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

Embed: (wiki syntax)

« Back to documentation index

MAX17043 Class Reference

This class allows for easy control over a MAX17043 LiPo fuel gauge IC. More...

#include <MAX17043.h>

Inherits I2CSensor, and PeriodicSensor.

Public Member Functions

 MAX17043 (PinName sda, PinName scl, int i2c_addr)
void selfInit ()
 Initializes the device to some preferred state.
void reset ()
 Performs a software reset of the device.
uint16_t getVersion ()
uint16_t getVCell (bool sampleNow)
float getFloatVCell (bool sampleNow)
uint16_t getSOC (bool sampleNow)
float getFloatSOC (bool sampleNow)
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 over a MAX17043 LiPo fuel gauge IC.

Definition at line 17 of file MAX17043.h.


Constructor & Destructor Documentation

MAX17043 ( 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 MAX17043.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 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.

float getFloatSOC ( 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 battery state of charge in %, as a floating point #

Definition at line 74 of file MAX17043.cpp.

float getFloatVCell ( 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 battery voltage as floating point

Definition at line 56 of file MAX17043.cpp.

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

Definition at line 57 of file PeriodicSensor.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.

uint16_t getSOC ( 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 battery state of charge as computed by the ModelGauge algorithm. High byte: units of %. Low byte: units of 1/256%.

Definition at line 60 of file MAX17043.cpp.

uint16_t getVCell ( 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 battery voltage raw ADC value

Definition at line 42 of file MAX17043.cpp.

uint16_t getVersion (  )
Returns:
the IC version code

Definition at line 37 of file MAX17043.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 reset (  )

Performs a software reset of the device.

Definition at line 29 of file MAX17043.cpp.

void selfInit (  )

Initializes the device to some preferred state.

Definition at line 24 of file MAX17043.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.