A compilation of some hardware sensors and their shared programming interfaces.

Embed: (wiki syntax)

« Back to documentation index

MAG3110 Class Reference

This class allows for easy control of an MAG3110 magnetometer IC. More...

#include <MAG3110.h>

Inherits I2CSensor, and PeriodicSensor.

Public Types

enum  adc_smpl_rate_t
 

Enumeration of allowed ADC sampling data rates.

More...
enum  oversmpl_ratio_t
 

Enumeration of allowed oversampling ratios.

More...
enum  smpl_rate_t
 

Enumeration of possible output data rates.

More...

Public Member Functions

 MAG3110 (PinName sda, PinName scl, int i2c_addr)
void selfInit ()
 Self-initialization to some nice preset.
uint8_t whoAmI ()
 Implements the pure virtual method of the parent I2CSensor class.
bool isActive ()
void setActive (bool activate)
uint8_t getSystemMode ()
void getOutputSamplingParameters (smpl_rate_t *rate, oversmpl_ratio_t *ratio, adc_smpl_rate_t *adc_rate)
bool setOutputSamplingParameters (smpl_rate_t rate, oversmpl_ratio_t ratio, adc_smpl_rate_t *adc_rate)
uint8_t getDataRegisterStatus ()
int16_t getX (bool sampleNow)
int16_t getY (bool sampleNow)
int16_t getZ (bool sampleNow)
float getFloatX (bool sampleNow)
float getFloatY (bool sampleNow)
float getFloatZ (bool sampleNow)
int8_t getDieTemp ()
 Get the die temperature.
float getFloatDieTemp ()
PinName getSDAPin ()
PinName getSCLPin ()
uint8_t getDeviceI2CAddress ()
uint8_t getRegister (const uint8_t reg_addr)
 Read an 8-bit register.
uint16_t getRegister16b (const uint8_t reg_addr)
 Read a 16-bit register.
void setRegister (const uint8_t reg_addr, const uint8_t data)
 Set an 8-bit register.
void setRegister16b (const uint8_t reg_addr, const uint16_t data)
 Set a 16-bit register.
bool isDataReady ()
void enableBackgroundSampling (bool enable, float sample_period)
 Control the background sampling of the device via interrupts.
bool isBackgroundSamplingEnabled ()
float getSamplePeriod ()
float getMinSamplePeriod ()

Protected Member Functions

int __readReg (const uint8_t reg_addr, uint8_t *data, int len)
int __writeReg (const uint8_t *data, int total_len)

Detailed Description

This class allows for easy control of an MAG3110 magnetometer IC.

Definition at line 18 of file MAG3110.h.


Member Enumeration Documentation

Enumeration of allowed ADC sampling data rates.

The device does sample averages such that the output data rate ODR = ADC_RATE / OVERSMPL_RATIO in all cases except for when ADC_RATE is 80 Hz (min). In this case, there are multiple ODR for the same ADC_RATE, OVERSMPL_RATIO combination. Note that there are non-unique combinations for the same ODR.

Definition at line 27 of file MAG3110.h.

Enumeration of allowed oversampling ratios.

The device does sample averages such that the output data rate ODR = ADC_RATE / OVERSMPL_RATIO in all cases except for when ADC_RATE is 80 Hz (min). In this case, there are multiple ODR for the same ADC_RATE, OVERSMPL_RATIO combination. Note that there are non-unique combinations for the same ODR.

Definition at line 42 of file MAG3110.h.

Enumeration of possible output data rates.

The device does sample averages such that the output data rate ODR = ADC_RATE / OVERSMPL_RATIO in all cases except for when ADC_RATE is 80 Hz (min). In this case, there are multiple ODR for the same ADC_RATE, OVERSMPL_RATIO combination. Note that there are non-unique combinations for the same ODR.

Definition at line 56 of file MAG3110.h.


Constructor & Destructor Documentation

MAG3110 ( PinName  sda,
PinName  scl,
int  i2c_addr 
)
Parameters:
sdathe pin identifier for SDA I2C signal
sclthe pin identifier for SCL I2C signal
i2c_addrthe 8-bit I2C address for this device. Note that LSB is a don't care.

Definition at line 14 of file MAG3110.cpp.


Member Function Documentation

int __readReg ( const uint8_t  reg_addr,
uint8_t *  data,
int  len 
) [protected, inherited]
Parameters:
reg_addr8-bit register address inside the device
data8-bit data that will be read from the register. This pointer MUST be valid. This array MUST be at least as long as len.
lentotal number of bytes to read. len must be >= 1.
Returns:
0 on success, otherwise error code from I2C

Definition at line 57 of file I2CSensor.cpp.

int __writeReg ( const uint8_t *  data,
int  total_len 
) [protected, inherited]
Parameters:
data8-bit data that will be written to the register. This pointer MUST be valid. This array MUST be at least as long as total_len. data[0] should be set to the 8-bit register address. The data payload should start at index 1.
total_lentotal length of the data array, which is the length of the payload + 1 for the register address. total_len must be >= 2.
Returns:
0 on success, otherwise error code from I2C

Definition at line 72 of file I2CSensor.cpp.

void enableBackgroundSampling ( bool  enable,
float  sample_period 
) [inherited]

Control the background sampling of the device via interrupts.

If disabled, the device can still be sampled using the getter methods directly.

Parameters:
enableif true, enables background sampling with the given sample period.
sample_periodsampling period in seconds. Must be at least 0.005 sec unless enable is false, in which case it is don't care.

Definition at line 36 of file PeriodicSensor.cpp.

uint8_t getDataRegisterStatus (  )
Returns:
the value in the data register

Definition at line 43 of file MAG3110.cpp.

uint8_t getDeviceI2CAddress (  ) [inherited]
Returns:
Device I2C address (LSB always 0 in this case, it is don't care)

Definition at line 28 of file I2CSensor.cpp.

int8_t getDieTemp (  )

Get the die temperature.

Note that the actual sensor range is only -40C to 125C, so not all outputs are valid.

Returns:
8-bit die temperature data

Definition at line 417 of file MAG3110.cpp.

float getFloatDieTemp (  )
Returns:
the die temperature in deg Celsius. Note that the actual sensor range is only -40C to 125C, so not all possible outputs may be valid.

Definition at line 421 of file MAG3110.cpp.

float getFloatX ( bool  sampleNow )
Parameters:
sampleNowif true, queries the device for the sample and returns it. if false, gets the last queried value. The latter is preferred if this object is set up to sample using interrupts. Returns the latest X data reading as a float in uT

Definition at line 405 of file MAG3110.cpp.

float getFloatY ( bool  sampleNow )
Parameters:
sampleNowif true, queries the device for the sample and returns it. if false, gets the last queried value. The latter is preferred if this object is set up to sample using interrupts. Returns the latest Y data reading as a float in uT

Definition at line 409 of file MAG3110.cpp.

float getFloatZ ( bool  sampleNow )
Parameters:
sampleNowif true, queries the device for the sample and returns it. if false, gets the last queried value. The latter is preferred if this object is set up to sample using interrupts. Returns the latest Z data reading as a float in uT

Definition at line 413 of file MAG3110.cpp.

float getMinSamplePeriod (  ) [inherited]
Returns:
the minimum sample period in seconds

Definition at line 57 of file PeriodicSensor.cpp.

void getOutputSamplingParameters ( smpl_rate_t rate,
oversmpl_ratio_t ratio,
adc_smpl_rate_t adc_rate 
)
Parameters:
rateoptional pointer, if provided, will be set to the output sampling rate
ratiooptional pointer, if provided, will be set to the oversampling ratio
adc_rateoptional pointer, if provided, will be set to the ADC rate

Definition at line 67 of file MAG3110.cpp.

uint8_t getRegister ( const uint8_t  reg_addr ) [inherited]

Read an 8-bit register.

Parameters:
reg_addrthe register in the device
Returns:
The raw value from the register specified by reg_addr.

Definition at line 30 of file I2CSensor.cpp.

uint16_t getRegister16b ( const uint8_t  reg_addr ) [inherited]

Read a 16-bit register.

Parameters:
reg_addrthe register in the device
Returns:
The raw value from the register specified by reg_addr.

Definition at line 36 of file I2CSensor.cpp.

float getSamplePeriod (  ) [inherited]
Returns:
the sample period in seconds, if background sampling is enabled. Else, non-positive return.

Definition at line 53 of file PeriodicSensor.cpp.

PinName getSCLPin (  ) [inherited]
Returns:
I2C SCL pin ID

Definition at line 26 of file I2CSensor.cpp.

PinName getSDAPin (  ) [inherited]
Returns:
I2C SDA pin ID

Definition at line 24 of file I2CSensor.cpp.

uint8_t getSystemMode (  )
Returns:
the 8-bit system mode status

Definition at line 47 of file MAG3110.cpp.

int16_t getX ( bool  sampleNow )
Parameters:
sampleNowif true, queries the device for the sample and returns it. if false, gets the last queried value. The latter is preferred if this object is set up to sample using interrupts.
Returns:
a 16-bit value representing the latest data sample for the X dimension, centered at 0.

Definition at line 357 of file MAG3110.cpp.

int16_t getY ( bool  sampleNow )
Parameters:
sampleNowif true, queries the device for the sample and returns it. if false, gets the last queried value. The latter is preferred if this object is set up to sample using interrupts.
Returns:
a 16-bit value representing the latest data sample for the Y dimension, centered at 0.

Definition at line 373 of file MAG3110.cpp.

int16_t getZ ( bool  sampleNow )
Parameters:
sampleNowif true, queries the device for the sample and returns it. if false, gets the last queried value. The latter is preferred if this object is set up to sample using interrupts.
Returns:
a 16-bit value representing the latest data sample for the Z dimension, centered at 0.

Definition at line 389 of file MAG3110.cpp.

bool isActive (  )
Returns:
true if the device is active

Definition at line 51 of file MAG3110.cpp.

bool isBackgroundSamplingEnabled (  ) [inherited]
Returns:
true if background sampling is enabled.

Definition at line 49 of file PeriodicSensor.cpp.

bool isDataReady (  ) [inherited]
Returns:
true if there is new data ready to be retrieved.

Definition at line 32 of file PeriodicSensor.cpp.

void selfInit (  )

Self-initialization to some nice preset.

You must ensure the device is first deactivated using setActive().

Definition at line 29 of file MAG3110.cpp.

void setActive ( bool  activate )
Parameters:
activateif true, enables the device, else disables it

Definition at line 55 of file MAG3110.cpp.

bool setOutputSamplingParameters ( smpl_rate_t  rate,
oversmpl_ratio_t  ratio,
adc_smpl_rate_t adc_rate 
)
Parameters:
ratethe enumerated value corresponding to the output data sample rate to use
ratiothe number of ADC samples per output sample (averaged)
adc_rateoptional pointer, set to the resulting adc_rate used for the combination of rate and ratio
Returns:
true if the operation succeeded and the first two parameters were correct

Definition at line 77 of file MAG3110.cpp.

void setRegister ( const uint8_t  reg_addr,
const uint8_t  data 
) [inherited]

Set an 8-bit register.

Parameters:
reg_addrthe register in the device
datathe byte to write to the register

Definition at line 43 of file I2CSensor.cpp.

void setRegister16b ( const uint8_t  reg_addr,
const uint16_t  data 
) [inherited]

Set a 16-bit register.

Parameters:
reg_addrthe register in the device
datathe byte to write to the register

Definition at line 48 of file I2CSensor.cpp.

uint8_t whoAmI (  )

Implements the pure virtual method of the parent I2CSensor class.

Returns:
the 8-bit device identifier.

Definition at line 39 of file MAG3110.cpp.