modm API documentation
modm::lis3mdl< I2cMaster > Class Template Reference

#include <modm/driver/inertial/lis3mdl.hpp>

Inheritance diagram for modm::lis3mdl< I2cMaster >:
modm::Lis3TransportI2c< I2cMaster > modm::I2cDevice< I2cMaster >

Public Typedefs

typedef modm::Configuration< Control1_t, DataRate, Bit6|Bit5|Bit4|Bit3|Bit2|Bit1 > DataRate_t
 
typedef modm::Configuration< Control1_t, HighSpeedModes, Bit2|Bit1, 4 > HighSpeedModes_t
 
typedef modm::Configuration< Control2_t, Scale, Bit6|Bit5 > Scale_t
 
typedef modm::Configuration< Control3_t, OperationMode, Bit1|Bit0 > OperationMode_t
 
typedef modm::Configuration< Control4_t, HighSpeedModes, Bit2|Bit1, 2 > HighSpeedModesZ_t
 

Public Types

enum  Register : uint8_t {
  Register::WHO_AM_I = 0x0F, Register::CTRL1 = 0x20, Register::CTRL2 = 0x21, Register::CTRL3 = 0x22,
  Register::CTRL4 = 0x23, Register::CTRL5 = 0x24, Register::STATUS = 0x27, Register::OUT_X_L = 0x28,
  Register::OUT_X_H = 0x29, Register::OUT_Y_L = 0x2A, Register::OUT_Y_H = 0x2B, Register::OUT_Z_L = 0x2C,
  Register::OUT_Z_H = 0x2D, Register::OUT_TEMP_L = 0x2E, Register::OUT_TEMP_H = 0x2F, Register::INT_CFG = 0x30,
  Register::INT_SRC = 0x31, Register::INT_THS_L = 0x33, Register::INT_THS_H = 0x34
}
 
enum  Control1 : uint8_t {
  Control1::TEMP_EN = Bit7, Control1::OM1 = Bit6, Control1::OM0 = Bit5, Control1::DO2 = Bit4,
  Control1::DO1 = Bit3, Control1::DO0 = Bit2, Control1::FAST_ODR = Bit1, Control1::ST = Bit0
}
 Control register 1. More...
 
enum  DataRate : uint8_t {
  DataRate::Rate_0_625_Hz = 0x00, DataRate::Rate_1_25_Hz = 0x04, DataRate::Rate_2_5_Hz = 0x80, DataRate::Rate_5_Hz = 0xC0,
  DataRate::Rate_10_Hz = 0x10, DataRate::Rate_20_Hz = 0x14, DataRate::Rate_40_Hz = 0x18, DataRate::Rate_80_Hz = 0x1C,
  DataRate::Rate_115_Hz = 0x62, DataRate::Rate_300_Hz = 0x42, DataRate::Rate_569_Hz = 0x22, DataRate::Rate_1000_Hz = 0x02
}
 Output Data Rates for the Magnetometer sensor. More...
 
enum  HighSpeedModes : uint8_t { LowPower = 0x00, MediumPerformance = 0x01, HighPerformance = 0x02, UltraHighPerformance = 0x03 }
 Operation mode to be used with high speed data rates (>80 Hz)
 
enum  Control2 : uint8_t { Control2::FS1 = Bit6, Control2::FS0 = Bit5, Control2::REBOOT = Bit3, Control2::SOFT_RST = Bit2 }
 Control Register 2. More...
 
enum  Scale : uint8_t { Scale::Scale_4_gauss = 0x00, Scale::Scale_8_gauss = 0x40, Scale::Scale_12_gauss = 0x80, Scale::Scale_16_gauss = 0xC0 }
 Full scale of the magnetometer data output. More...
 
enum  Control3 : uint8_t { Control3::LP = Bit5, Control3::SIM = Bit2, Control3::MD_1 = Bit1, Control3::MD_0 = Bit0 }
 Control Register 3. More...
 
enum  OperationMode : uint8_t { OperationMode::Off = 0x02, OperationMode::Continous = 0x00, OperationMode::Single = 0x01 }
 
enum  Control4 : uint8_t { Control4::OMZ_1 = Bit3, Control4::OMZ_0 = Bit2, Control4::BLE = Bit1 }
 Control Register 4. More...
 
enum  Control5 : uint8_t { Control5::FAST_READ = Bit7, Control5::BDU = Bit6 }
 Control Register 5. More...
 
enum  Status : uint8_t {
  Status::ZYXOR = Bit7, Status::ZOR = Bit6, Status::YOR = Bit5, Status::XOR = Bit4,
  Status::ZYXDA = Bit3, Status::ZDA = Bit2, Status::YDA = Bit1, Status::XDA = Bit0
}
 STATUS is read-only. More...
 

Public Member Functions

 MODM_FLAGS8 (Control1)
 
 MODM_FLAGS8 (Control2)
 
 MODM_FLAGS8 (Control3)
 
 MODM_FLAGS8 (Control4)
 
 MODM_FLAGS8 (Control5)
 
 MODM_FLAGS8 (Status)
 
 Lis3mdl (uint8_t address=0x1C)
 Construct a driver object for the LIS3MDL chip. More...
 
bool configure (DataRate rate, Scale scale)
 Configures the sensor This method will setup the data rate and the scale with which the sensor will sample the data. More...
 
bool setMode (OperationMode mode)
 Sets the mode of the sensor. More...
 
Scale getScale ()
 Get the currently configured scale for the magnetometer. More...
 
bool readMagnetometerRaw (Vector3i &data)
 Reads out the raw magnetometer into a given vector object. More...
 
bool readMagnetometer (Vector3f &data)
 Reads out the scaled magnetometer data in gauss. More...
 
void attachConfigurationHandler (I2c::ConfigurationHandler handler)
 
bool ping ()
 
bool read (uint8_t *buffer, std::size_t size)
 Starts a write transaction and waits until finished.
 
void setAddress (uint8_t address)
 
bool write (const uint8_t *buffer, std::size_t size)
 Starts a write transaction and waits until finished.
 
bool writeRead (const uint8_t *writeBuffer, std::size_t writeSize, uint8_t *readBuffer, std::size_t readSize)
 Starts a write-read transaction and waits until finished.
 

Protected Member Functions

bool isTransactionRunning ()
 
bool read (uint8_t reg, uint8_t &value)
 read a 8bit value
 
bool read (uint8_t reg, uint8_t *buffer, uint8_t length)
 read multiple 8bit values from a start register
 
bool runTransaction ()
 Starts our own transaction and waits until finished.
 
bool startTransaction ()
 Starts the transaction with our own transaction object.
 
bool startTransaction (modm::I2cTransaction *transaction)
 Starts the transaction with a separate transaction object.
 
bool wasTransactionSuccessful ()
 
bool write (uint8_t reg, uint8_t value)
 write a 8bit value
 

Protected Attributes

I2cWriteReadTransaction transaction
 

Static Protected Attributes

static constexpr float convTable [4]
 

Detailed Description

template<class I2cMaster>
class modm::lis3mdl< I2cMaster >

Template Parameters
I2cMasterI2cMaster interface
Author
Benjamin Carrick

Member Enumeration Documentation

template<class I2cMaster >
enum modm::lis3mdl::Control1 : uint8_t
strong

Control register 1.

Enum ValuesDocumentation
TEMP_EN 

Temperature sensor enable.

OM1 

Operation mode bit 1.

OM0 

Operation mode bit 0.

DO2 

Data output rate bit 2.

DO1 

Data output rate bit 1.

DO0 

Data output rate bit 0.

FAST_ODR 

Fast data acquisition (for rates higher than 80Hz)

ST 

Self test enable.

template<class I2cMaster >
enum modm::lis3mdl::Control2 : uint8_t
strong

Control Register 2.

Enum ValuesDocumentation
FS1 

Full-Scale configuration bit 1.

FS0 

Full-Scale configuration bit 0.

REBOOT 

Reboot memory content.

SOFT_RST 

Soft reset.

template<class I2cMaster >
enum modm::lis3mdl::Control3 : uint8_t
strong

Control Register 3.

Enum ValuesDocumentation
LP 

Low Power Mode Enable.

SIM 

SPI Interface Mode (0 = 4 Wire(default), 1 = 3 Wire)

MD_1 

Sensor Operation Mode bit 1.

MD_0 

Sensor Operation Mode bit 0.

template<class I2cMaster >
enum modm::lis3mdl::Control4 : uint8_t
strong

Control Register 4.

Enum ValuesDocumentation
OMZ_1 

Operation Mode for z axis bit 1.

OMZ_0 

Operation Mode for z axis bit 1.

BLE 

Bit order of the data output (0 = little endian, 1 = big endian)

template<class I2cMaster >
enum modm::lis3mdl::Control5 : uint8_t
strong

Control Register 5.

Enum ValuesDocumentation
FAST_READ 

Fast read enable.

BDU 

Blocking read.

template<class I2cMaster >
enum modm::lis3mdl::DataRate : uint8_t
strong

Output Data Rates for the Magnetometer sensor.

Enum ValuesDocumentation
Rate_0_625_Hz 

0.625 Hz

Rate_1_25_Hz 

1.25 Hz

Rate_2_5_Hz 

2.5 Hz

Rate_5_Hz 

5 Hz

Rate_10_Hz 

10 Hz

Rate_20_Hz 

20 Hz

Rate_40_Hz 

40 Hz

Rate_80_Hz 

80 Hz

Rate_115_Hz 

115 Hz

Rate_300_Hz 

300 Hz

Rate_569_Hz 

560 Hz

Rate_1000_Hz 

1000 Hz

template<class I2cMaster >
enum modm::lis3mdl::OperationMode : uint8_t
strong
Enum ValuesDocumentation
Off 

Power down mode.

Continous 

Continous conversion mode.

Single 

Single shot mode.

template<class I2cMaster >
enum modm::lis3mdl::Register : uint8_t
strong
Enum ValuesDocumentation
WHO_AM_I 

Contains 0x3D.

CTRL1 

Control register 1: rw.

CTRL2 

Control register 2: rw.

CTRL3 

Control register 3: rw.

CTRL4 

Control register 4: rw.

CTRL5 

Control register 5: rw.

STATUS 

Status Data Register.

OUT_X_L 

Angular rates output x-axis register low.

OUT_X_H 

Angular rates output x-axis register high.

OUT_Y_L 

Angular rates output y-axis register low.

OUT_Y_H 

Angular rates output y-axis register high.

OUT_Z_L 

Angular rates output z-axis register low.

OUT_Z_H 

Angular rates output z-axis register high.

OUT_TEMP_L 

Temperature output register low.

OUT_TEMP_H 

Temperature output register high.

INT_CFG 

Interrupt Configuration Register.

INT_SRC 

Interrupt Source Register.

INT_THS_L 

Interrupt Threshold Value Low.

INT_THS_H 

Interrupt Threshold Value High.

template<class I2cMaster >
enum modm::lis3mdl::Scale : uint8_t
strong

Full scale of the magnetometer data output.

Enum ValuesDocumentation
Scale_4_gauss 

4 gauss

Scale_8_gauss 

8 gauss

Scale_12_gauss 

12 gauss

Scale_16_gauss 

16 gauss

template<class I2cMaster >
enum modm::lis3mdl::Status : uint8_t
strong

STATUS is read-only.

Enum ValuesDocumentation
ZYXOR 

Overrun in Z,Y and X axis.

ZOR 

Overrun in Z axis.

YOR 

Overrun in Y axis.

XOR 

Overrun in X axis.

ZYXDA 

New data available in Z,Y and X axis.

ZDA 

New data available in Z axis.

YDA 

New data available in Y axis.

XDA 

New data available in X axis.

Member Function Documentation

void modm::I2cDevice< I2cMaster, 10 , I2cWriteReadTransaction >::attachConfigurationHandler ( I2c::ConfigurationHandler  handler)
inheritedinline

Attaches a configuration handler, which is called before a transaction, whenever the configuration has to be changed.

template<class I2cMaster >
bool modm::lis3mdl< I2cMaster >::configure ( DataRate  rate,
Scale  scale 
)

Configures the sensor This method will setup the data rate and the scale with which the sensor will sample the data.

Parameters
rateThe sample rate for the sensor
scaleThe full scale of the output data
Returns
Whether the configuration was successful
template<class I2cMaster >
Scale modm::lis3mdl< I2cMaster >::getScale ( )

Get the currently configured scale for the magnetometer.

Returns
The currently configured data scale
bool modm::I2cDevice< I2cMaster, 10 , I2cWriteReadTransaction >::isTransactionRunning ( )
inheritedinlineprotected
Returns
true when transaction is busy.
template<class I2cMaster >
modm::lis3mdl< I2cMaster >::Lis3mdl ( uint8_t  address = 0x1C)

Construct a driver object for the LIS3MDL chip.

Parameters
addressThe I2C device address of the sensor
bool modm::I2cDevice< I2cMaster, 10 , I2cWriteReadTransaction >::ping ( )
inheritedinline
Return Values
truedevice responds to address
falseno device with address found
template<class I2cMaster >
bool modm::lis3mdl< I2cMaster >::readMagnetometer ( Vector3f data)

Reads out the scaled magnetometer data in gauss.

Parameters
dataA reference to a Vector3f object the data will be written to
Returns
Whether the sensor data have been read
template<class I2cMaster >
bool modm::lis3mdl< I2cMaster >::readMagnetometerRaw ( Vector3i data)

Reads out the raw magnetometer into a given vector object.

Parameters
dataA reference to a Vector3i object the data will be written to
Returns
Whether the sensor data have been read
void modm::I2cDevice< I2cMaster, 10 , I2cWriteReadTransaction >::setAddress ( uint8_t  address)
inheritedinline

Sets a new address of the slave device.

Parameters
addressthe slave address not yet shifted left (address < 128).
template<class I2cMaster >
bool modm::lis3mdl< I2cMaster >::setMode ( OperationMode  mode)

Sets the mode of the sensor.

Parameters
modeThe mode on which the magnetometer operates
Returns
Whether the mode has been set
bool modm::I2cDevice< I2cMaster, 10 , I2cWriteReadTransaction >::wasTransactionSuccessful ( )
inheritedinlineprotected
Returns
true when transaction did not return an error.

Member Data Documentation

template<class I2cMaster >
constexpr float modm::lis3mdl< I2cMaster >::convTable[4]
staticprotectedconstexpr
Initial value:
{
0.00012207f,
0.000244141f,
0.000366211f,
0.000488281f
}

The documentation for this class was generated from the following file: