Detailed Description

Silicon Labs Si72xx Magnetic Hall Effect Sensor I2C driver.

Macros

#define SI7200_ADDR_0 (0x30 << 1)
#define SI7200_ADDR_1 (0x31 << 1)
#define SI7200_ADDR_2 (0x32 << 1)
#define SI7200_ADDR_3 (0x33 << 1)
#define SI72XX_A0 0xCA
#define SI72XX_A1 0xCB
#define SI72XX_A2 0xCC
#define SI72XX_A3 0xCE
#define SI72XX_A4 0xCF
#define SI72XX_A5 0xD0
#define SI72XX_ARAUTOINC 0xC5
#define SI72XX_CTRL1 0xC6
#define SI72XX_CTRL2 0xC7
#define SI72XX_CTRL3 0xC9
#define SI72XX_CTRL4 0xCD
#define SI72XX_DSPSIGL 0xC2
#define SI72XX_DSPSIGM 0xC1
#define SI72XX_DSPSIGSEL 0xC3
#define SI72XX_ERROR_BUSY 0xfe
#define SI72XX_ERROR_NODATA 0xfd
#define SI72XX_HREVID 0xC0
#define SI72XX_OTP_200MT_ADDR 0x27
#define SI72XX_OTP_20MT_ADDR 0x21
#define SI72XX_OTP_ADDR 0xE1
#define SI72XX_OTP_CTRL 0xE3
#define SI72XX_OTP_DATA 0xE2
#define SI72XX_POWER_CTRL 0xC4
#define SI72XX_SLTIME 0xC8
#define SI72XX_TM_FG 0xE4

Enumerations

enum Si72xxFieldScale_t {
SI7210_20MT ,
SI7210_200MT
}
enum Si72xxSleepMode_t {
SI72XX_SLEEP_MODE ,
SI72XX_SLTIMEENA_MODE
}

Functions

int32_t Si72xx_ConvertDataCodesToMagneticField ( Si72xxFieldScale_t fieldScale, int16_t dataCode)
Convert Si7210 I2C Data Readings to Magnetic Field in microTeslas.
uint32_t Si72xx_EnterLatchMode (I2C_TypeDef *i2c, uint8_t addr)
Wake-up Si72xx, and configures output for Latch mode. Switch point = 0mT w/ 0.2mT hysteresis.
uint32_t Si72xx_EnterSleepMode (I2C_TypeDef *i2c, uint8_t addr, Si72xxSleepMode_t sleepMode)
Wake-up Si72xx, and set sleep-mode option. If Si72xx is in a sleep-mode, it requires a wake-up command first. Useful for placing Si72xx in SLTIMEENA mode from SLEEP mode, or vice-versa.
uint32_t Si72xx_FromIdle_GoToSleep (I2C_TypeDef *i2c, uint8_t addr)
Puts Si72xx into Sleep mode (lowest power).. Command can only be issued if Si72xx is idle mode.
uint32_t Si72xx_FromIdle_GoToSltimeena (I2C_TypeDef *i2c, uint8_t addr)
Puts Si72xx into Sleep-Timer-Enable mode. Si72xx periodically wakes-up, samples the magnetic field, updates the output, and goes back to sleep-timer-enabled mode. Command can only be issued if Si72xx is idle mode.
uint32_t Si72xx_IdentifyAndSleep (I2C_TypeDef *i2c, uint8_t addr, uint8_t *partId, uint8_t *partRev)
uint32_t Si72xx_Read_MagField_Data (I2C_TypeDef *i2c, uint8_t addr, int16_t *magData)
Read out Si72xx Magnetic Field Conversion Data Command can only be issued if Si72xx is idle mode.
static uint32_t Si72xx_Read_OTP (I2C_TypeDef *i2c, uint8_t addr, uint8_t otpAddr, uint8_t *otpData)
Read Si72xx OTP Data Command can only be issued if Si72xx is idle mode.
uint32_t Si72xx_Read_Register (I2C_TypeDef *i2c, uint8_t addr, uint8_t reg, uint8_t *data)
Reads register from the Si72xx sensor. Command can only be issued if Si72xx is idle mode.
uint32_t Si72xx_ReadCorrectedTempAndSleep (I2C_TypeDef *i2c, uint8_t addr, int16_t offsetData, int16_t gainData, int32_t *correctedTemp)
Wakes up SI72xx, performs a temperature conversion, and places sensor back to sleep. Temperature calculation is performed using compensation data.
uint32_t Si72xx_ReadMagFieldDataAndSleep (I2C_TypeDef *i2c, uint8_t addr, Si72xxFieldScale_t mTScale, Si72xxSleepMode_t sleepMode, int16_t *magFieldData)
Wake-up SI72xx, performs a magnetic-field conversion with FIR, and places Si72xx back to sleep-mode.
uint32_t Si72xx_ReadTempCorrectionDataAndSleep (I2C_TypeDef *i2c, uint8_t addr, int16_t *offsetValue, int16_t *gainValue)
Wakes up SI72xx, performs temperature conversion and places Si72xx into SI72XX_SLEEP sleep-mode.
uint32_t Si72xx_ReadTemperatureAndSleep (I2C_TypeDef *i2c, uint8_t addr, int32_t *rawTemp)
Wakes up SI72xx, performs temperature conversion and places Si72xx into SI72XX_SLEEP sleep-mode.
uint32_t Si72xx_ReadVariantAndSleep (I2C_TypeDef *i2c, uint8_t addr, uint8_t *basePn, uint8_t *pnVariant)
static uint32_t Si72xx_Set_mT_Range (I2C_TypeDef *i2c, uint8_t addr, Si72xxFieldScale_t mTScale)
Set magnetic-field output range, 20mT or 200mT full-scale Command can only be issued if Si72xx is idle mode.
uint32_t Si72xx_WakeUpAndIdle (I2C_TypeDef *i2c, uint8_t addr)
Wake-up Si72xx and places sensor in idle-mode.
uint32_t Si72xx_Write_Register (I2C_TypeDef *i2c, uint8_t addr, uint8_t reg, uint8_t data)
Writes register in the Si72xx sensor. Command can only be issued if Si72xx is idle mode.

Macro Definition Documentation

#define SI7200_ADDR_0   (0x30 << 1)

I2C device address for Si72xx

Definition at line 53 of file si72xx.h .

#define SI72XX_HREVID   0xC0

I2C registers for Si72xx

Definition at line 59 of file si72xx.h .

Enumeration Type Documentation

Si72xx magnetic field full-scales

Definition at line 91 of file si72xx.h .

Si72xx sleep modes

Definition at line 97 of file si72xx.h .

Function Documentation

int32_t Si72xx_ConvertDataCodesToMagneticField ( Si72xxFieldScale_t fieldScale,
int16_t dataCode
)

Convert Si7210 I2C Data Readings to Magnetic Field in microTeslas.

Parameters
[in] fieldScale 20mT or 200mT full-scale magnetic field range
[in] dataCodes signed 15bit value read from hall sensor after magnetic field conversion
Returns
microTeslas

Definition at line 456 of file si72xx.c .

uint32_t Si72xx_EnterLatchMode ( I2C_TypeDef * i2c,
uint8_t addr
)

Wake-up Si72xx, and configures output for Latch mode. Switch point = 0mT w/ 0.2mT hysteresis.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor

Definition at line 508 of file si72xx.c .

References Si72xx_Read_Register() , Si72xx_WakeUpAndIdle() , and Si72xx_Write_Register() .

uint32_t Si72xx_EnterSleepMode ( I2C_TypeDef * i2c,
uint8_t addr,
Si72xxSleepMode_t sleepMode
)

Wake-up Si72xx, and set sleep-mode option. If Si72xx is in a sleep-mode, it requires a wake-up command first. Useful for placing Si72xx in SLTIMEENA mode from SLEEP mode, or vice-versa.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor
[in] sleepMode SI72XX_SLEEP: Puts Si72xx into sleep mode. Lowest power & doesn't update SI72XX_SLTIMEENA: Si72xx into sltimeena mode. Updates output periodically

Definition at line 485 of file si72xx.c .

References Si72xx_FromIdle_GoToSleep() , Si72xx_FromIdle_GoToSltimeena() , and Si72xx_WakeUpAndIdle() .

uint32_t Si72xx_FromIdle_GoToSleep ( I2C_TypeDef * i2c,
uint8_t addr
)

Puts Si72xx into Sleep mode (lowest power).. Command can only be issued if Si72xx is idle mode.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor.

Definition at line 238 of file si72xx.c .

References Si72xx_Read_Register() , and Si72xx_Write_Register() .

Referenced by Si72xx_EnterSleepMode() , Si72xx_ReadCorrectedTempAndSleep() , Si72xx_ReadMagFieldDataAndSleep() , Si72xx_ReadTempCorrectionDataAndSleep() , and Si72xx_ReadTemperatureAndSleep() .

uint32_t Si72xx_FromIdle_GoToSltimeena ( I2C_TypeDef * i2c,
uint8_t addr
)

Puts Si72xx into Sleep-Timer-Enable mode. Si72xx periodically wakes-up, samples the magnetic field, updates the output, and goes back to sleep-timer-enabled mode. Command can only be issued if Si72xx is idle mode.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor.

Definition at line 263 of file si72xx.c .

References Si72xx_Read_Register() , and Si72xx_Write_Register() .

Referenced by Si72xx_EnterSleepMode() , and Si72xx_ReadMagFieldDataAndSleep() .

uint32_t Si72xx_Read_MagField_Data ( I2C_TypeDef * i2c,
uint8_t addr,
int16_t * magData
)

Read out Si72xx Magnetic Field Conversion Data Command can only be issued if Si72xx is idle mode.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor
[out] magData Mag-field conversion reading, signed 16-bit integer

Definition at line 204 of file si72xx.c .

References Si72xx_Read_Register() .

Referenced by Si72xx_ReadMagFieldDataAndSleep() .

static uint32_t Si72xx_Read_OTP ( I2C_TypeDef * i2c,
uint8_t addr,
uint8_t otpAddr,
uint8_t * otpData
)
static

Read Si72xx OTP Data Command can only be issued if Si72xx is idle mode.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor
[in] otpAddr The OTB Byte address of the coefficients
[out] data OTP data read out

Definition at line 325 of file si72xx.c .

References Si72xx_Read_Register() , and Si72xx_Write_Register() .

Referenced by Si72xx_ReadTempCorrectionDataAndSleep() , and Si72xx_Set_mT_Range() .

uint32_t Si72xx_Read_Register ( I2C_TypeDef * i2c,
uint8_t addr,
uint8_t reg,
uint8_t * data
)

Reads register from the Si72xx sensor. Command can only be issued if Si72xx is idle mode.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor.
[out] data The data read from the sensor.
[in] reg The register address to read from in the sensor.
Returns
Returns number of bytes read on success. Otherwise returns error codes based on the I2CSPM.

Definition at line 123 of file si72xx.c .

References I2C_TransferSeq_TypeDef::addr , I2C_TransferSeq_TypeDef::buf , I2C_TransferSeq_TypeDef::data , I2C_TransferSeq_TypeDef::flags , I2C_FLAG_WRITE_READ , I2CSPM_Transfer() , i2cTransferDone , and I2C_TransferSeq_TypeDef::len .

Referenced by Si72xx_EnterLatchMode() , Si72xx_FromIdle_GoToSleep() , Si72xx_FromIdle_GoToSltimeena() , Si72xx_Read_MagField_Data() , Si72xx_Read_OTP() , Si72xx_ReadCorrectedTempAndSleep() , Si72xx_ReadMagFieldDataAndSleep() , Si72xx_ReadTempCorrectionDataAndSleep() , and Si72xx_ReadTemperatureAndSleep() .

uint32_t Si72xx_ReadCorrectedTempAndSleep ( I2C_TypeDef * i2c,
uint8_t addr,
int16_t offsetData,
int16_t gainData,
int32_t * correctedTemp
)

Wakes up SI72xx, performs a temperature conversion, and places sensor back to sleep. Temperature calculation is performed using compensation data.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor
[out] temp Temperature measurement in millidegree Celsius
[in] offsetData Offset correction data
[in] gainData Gain correction data

Definition at line 672 of file si72xx.c .

References Si72xx_FromIdle_GoToSleep() , Si72xx_Read_Register() , Si72xx_WakeUpAndIdle() , and Si72xx_Write_Register() .

uint32_t Si72xx_ReadMagFieldDataAndSleep ( I2C_TypeDef * i2c,
uint8_t addr,
Si72xxFieldScale_t mTScale,
Si72xxSleepMode_t sleepMode,
int16_t * magFieldData
)

Wake-up SI72xx, performs a magnetic-field conversion with FIR, and places Si72xx back to sleep-mode.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor
[in] mTScale mTScale= Si7210_20MT: 20mT full-scale magnetic-field range mTScale= Si7210_200MT: 200mT full-scale magnetic-field range
[in] sleepMode SI72XX_SLEEP: Sleep mode. Lowest power & doesn't update output SI72XX_SLTIMEENA: Sleep-Timer-Enabled mode. Updates output periodically
[out] magFieldData Magnetic-field conversion reading, signed 16-bit integer

Definition at line 402 of file si72xx.c .

References Si72xx_FromIdle_GoToSleep() , Si72xx_FromIdle_GoToSltimeena() , Si72xx_Read_MagField_Data() , Si72xx_Read_Register() , Si72xx_Set_mT_Range() , Si72xx_WakeUpAndIdle() , and Si72xx_Write_Register() .

uint32_t Si72xx_ReadTempCorrectionDataAndSleep ( I2C_TypeDef * i2c,
uint8_t addr,
int16_t * offsetValue,
int16_t * gainValue
)

Wakes up SI72xx, performs temperature conversion and places Si72xx into SI72XX_SLEEP sleep-mode.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor
[out] offsetValue Temperature offset correction
[out] gainValue Temperature gain correction

Definition at line 624 of file si72xx.c .

References Si72xx_FromIdle_GoToSleep() , Si72xx_Read_OTP() , Si72xx_Read_Register() , Si72xx_WakeUpAndIdle() , and Si72xx_Write_Register() .

uint32_t Si72xx_ReadTemperatureAndSleep ( I2C_TypeDef * i2c,
uint8_t addr,
int32_t * rawTemp
)

Wakes up SI72xx, performs temperature conversion and places Si72xx into SI72XX_SLEEP sleep-mode.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor
[out] temp Temperature measurement in millidegree Celsius

Definition at line 554 of file si72xx.c .

References Si72xx_FromIdle_GoToSleep() , Si72xx_Read_Register() , Si72xx_WakeUpAndIdle() , and Si72xx_Write_Register() .

static uint32_t Si72xx_Set_mT_Range ( I2C_TypeDef * i2c,
uint8_t addr,
Si72xxFieldScale_t mTScale
)
static

Set magnetic-field output range, 20mT or 200mT full-scale Command can only be issued if Si72xx is idle mode.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor
[in] mTScale 20mT or 200mT

Definition at line 357 of file si72xx.c .

References Si72xx_Read_OTP() , and Si72xx_Write_Register() .

Referenced by Si72xx_ReadMagFieldDataAndSleep() .

uint32_t Si72xx_WakeUpAndIdle ( I2C_TypeDef * i2c,
uint8_t addr
)

Wake-up Si72xx and places sensor in idle-mode.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor.
Returns
Returns zero on success. Otherwise returns error codes based on the I2CCSPM

Definition at line 290 of file si72xx.c .

References I2C_TransferSeq_TypeDef::addr , I2C_TransferSeq_TypeDef::buf , I2C_TransferSeq_TypeDef::data , I2C_TransferSeq_TypeDef::flags , I2C_FLAG_WRITE , I2CSPM_Transfer() , i2cTransferDone , and I2C_TransferSeq_TypeDef::len .

Referenced by Si72xx_EnterLatchMode() , Si72xx_EnterSleepMode() , Si72xx_ReadCorrectedTempAndSleep() , Si72xx_ReadMagFieldDataAndSleep() , Si72xx_ReadTempCorrectionDataAndSleep() , and Si72xx_ReadTemperatureAndSleep() .

uint32_t Si72xx_Write_Register ( I2C_TypeDef * i2c,
uint8_t addr,
uint8_t reg,
uint8_t data
)

Writes register in the Si72xx sensor. Command can only be issued if Si72xx is idle mode.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor.
[in] data The data to write to the sensor.
[in] reg The register address to write to in the sensor.
Returns
Returns zero on success. Otherwise returns error codes based on the I2CCSPM

Definition at line 166 of file si72xx.c .

References I2C_TransferSeq_TypeDef::addr , I2C_TransferSeq_TypeDef::buf , I2C_TransferSeq_TypeDef::data , I2C_TransferSeq_TypeDef::flags , I2C_FLAG_WRITE , I2CSPM_Transfer() , i2cTransferDone , and I2C_TransferSeq_TypeDef::len .

Referenced by Si72xx_EnterLatchMode() , Si72xx_FromIdle_GoToSleep() , Si72xx_FromIdle_GoToSltimeena() , Si72xx_Read_OTP() , Si72xx_ReadCorrectedTempAndSleep() , Si72xx_ReadMagFieldDataAndSleep() , Si72xx_ReadTempCorrectionDataAndSleep() , Si72xx_ReadTemperatureAndSleep() , and Si72xx_Set_mT_Range() .