ME507 Airheads Project v1.1.0
Flight Stabilization for Glider
Loading...
Searching...
No Matches
LIS3MDL Class Reference

Class to interface with the LIS3MDL magnetometer. More...

#include <IMU.h>

Public Member Functions

 LIS3MDL (TwoWire &i2c, uint8_t address=0x1E)
 Header for LIS3MDL object. More...
 
void config_reg1 (bool temp_en=0, OM OMXY=LPM, uint8_t DOR=5, bool FAST_ODR=0, bool ST=0)
 Header to configure register 1. More...
 
void config_reg2 (FS FULL_SCALE=GAUSS_4, bool REBOOT=0, bool SOFT_RST=0)
 Header to configure register 2. More...
 
void config_reg3 (bool LP=0, bool SIM=0, MD SYS_OP_MODE=CONTINUOUS_CONVERSION)
 Header to configure register 3. More...
 
void config_reg4 (OM OMZ=LPM, BLE Endian_Data_Selec=LSB)
 Header to configure register 4. More...
 
void config_reg5 (bool FAST_READ=0, bool BDU=1)
 Header to configure register 5. More...
 
void read_xyz_mag (int16_t &MAG_X, int16_t &MAG_Y, int16_t &MAG_Z)
 Header to read all magnetometer data at once. More...
 

Protected Types

enum  OM { LPM = 0b00 , MPM = 0b01 , HPM =0b10 , UHPM = 0b11 }
 
enum  FS { GAUSS_4 = 0b00 , GAUSS_8 = 0b01 , GAUSS_12 = 0b10 , GAUSS_16 = 0b11 }
 
enum  MD { CONTINUOUS_CONVERSION = 0b00 , SINGLE_CONVERSION = 0b01 , POWER_DOWN = 0b11 }
 
enum  BLE { LSB = 0b1 , MSB = 0b1 }
 

Protected Member Functions

void writeRegister (byte Register, byte RegData)
 Header function to write to registers. More...
 
uint8_t readRegister (byte Register)
 Header function to read from registers. More...
 

Protected Attributes

uint8_t _LIS3MDLAddress = 0x1E
 Initialize I2C.
 
const byte _CTRL_REG1 = 0x20
 "CTRL_REG1" address
 
const byte _CTRL_REG2 = 0x21
 "CTRL_REG2" address
 
const byte _CTRL_REG3 = 0x22
 "CTRL_REG3" address
 
const byte _CTRL_REG4 = 0x23
 "CTRL_REG4" address
 
const byte _CTRL_REG5 = 0x24
 "CTRL_REG5" address
 
const byte _STATUS_REG = 0x27
 "STATUS_REG" address
 
const byte _OUT_X_L = 0x28
 "OUT_X_L" address for X-axis data output LSB
 
const byte _OUT_X_H = 0x29
 "OUT_X_H" address for X-axis data output MSB
 
const byte _OUT_Y_L = 0x2A
 "OUT_Y_L" address for Y-axis data output LSB
 
const byte _OUT_Y_H = 0x2B
 "OUT_Y_H" address for Y-axis data output MSB
 
const byte _OUT_Z_L = 0x2C
 "OUT_Z_L" address for Z-axis data output LSB
 
const byte _OUT_Z_H = 0x2D
 "OUT_Z_H" address for Z-axis data output MSB
 
const byte _INT_CFG = 0x30
 "INT_CFG" address
 
const byte _INT_THS_L = 0x32
 "INT_THS_L" address LSB
 
const byte _INT_THS_H = 0x33
 "INT_THS_H" address MSB
 
TwoWire * p_i2c
 Initialize I2C.
 

Detailed Description

Class to interface with the LIS3MDL magnetometer.

Constructor & Destructor Documentation

◆ LIS3MDL()

LIS3MDL::LIS3MDL ( TwoWire &  i2c,
uint8_t  address = 0x1E 
)

Header for LIS3MDL object.

Constructor for LIS3MDL object, which operates with the magnetometer.

Parameters
i2cDefault two wire method, default set to Wire
addressAddress for i2c communication, default set to 0x1E

Member Function Documentation

◆ config_reg1()

void LIS3MDL::config_reg1 ( bool  temp_en = 0,
OM  OMXY = LPM,
uint8_t  DOR = 5,
bool  FAST_ODR = 0,
bool  ST = 0 
)

Header to configure register 1.

Function to configure Register 1.

Parameters
temp_enBool to enable temp sensor or not
OMXYSet operating mode of XY sensors
DORSet data output rate
FAST_ODRBool to enable fast output data rate
STBool to enable, disable ST

◆ config_reg2()

void LIS3MDL::config_reg2 ( FS  FULL_SCALE = GAUSS_4,
bool  REBOOT = 0,
bool  SOFT_RST = 0 
)

Header to configure register 2.

Function to configure Register 2.

Parameters
FULL_SCALESets the full scale value
REBOOTBool to reboot memory content
SOFT_RSTBool to configure registers and user register reset function

◆ config_reg3()

void LIS3MDL::config_reg3 ( bool  LP = 0,
bool  SIM = 0,
MD  SYS_OP_MODE = CONTINUOUS_CONVERSION 
)

Header to configure register 3.

Function to configure Register 3.

Parameters
LPSet Low-power mode configuration
SIMSet SPI serial interface mode configuration
SYS_OP_MODESet system operating mode selection

◆ config_reg4()

void LIS3MDL::config_reg4 ( OM  OMZ = LPM,
BLE  Endian_Data_Selec = LSB 
)

Header to configure register 4.

Function to configure Register 4.

Parameters
OMZZ-axis operative mode selection
Endian_Data_SelecBig/little endian data selection

◆ config_reg5()

void LIS3MDL::config_reg5 ( bool  FAST_READ = 0,
bool  BDU = 1 
)

Header to configure register 5.

Function to configure Register 5.

Parameters
FAST_READEnable or disable fast read
BDUSets block data update for magnetic data

◆ read_xyz_mag()

void LIS3MDL::read_xyz_mag ( int16_t &  MAG_X,
int16_t &  MAG_Y,
int16_t &  MAG_Z 
)

Header to read all magnetometer data at once.

Reads the data for X, Y, and Z magnetometer data.

Parameters
MAG_XReference parameter for X-reading for magnetometer.
MAG_YReference parameter for Y-reading for magnetometer.
MAG_ZReference parameter for Z-reading for magnetometer.

◆ readRegister()

uint8_t LIS3MDL::readRegister ( byte  Register)
protected

Header function to read from registers.

Reads from register.

Parameters
RegisterRegister to read from
Returns
Reading from register

◆ writeRegister()

void LIS3MDL::writeRegister ( byte  Register,
byte  RegData 
)
protected

Header function to write to registers.

Writes to register.

Parameters
RegisterRegister address to write to
RegDataData to write to address

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