TempSensor

Detailed Description

Driver for DS75 I2C temperature sensor.

Data Structures

struct TEMPSENS_Temp_TypeDef

Macros

#define TEMPSENS_DK_ADDR 0x90

Enumerations

enum TEMPSENS_Register_TypeDef {
tempsensRegTemp = 0,
tempsensRegConfig = 1,
tempsensRegHysteresis = 2,
tempsensRegShutdown = 3
}

Functions

void TEMPSENS_Celsius2Fahrenheit ( TEMPSENS_Temp_TypeDef *temp)
Convert temperature from Celsius to Fahrenheit.
int TEMPSENS_RegisterGet (I2C_TypeDef *i2c, uint8_t addr, TEMPSENS_Register_TypeDef reg, uint16_t *val)
Read sensor register content.
int TEMPSENS_RegisterSet (I2C_TypeDef *i2c, uint8_t addr, TEMPSENS_Register_TypeDef reg, uint16_t val)
Write to sensor register.
int TEMPSENS_TemperatureGet (I2C_TypeDef *i2c, uint8_t addr, TEMPSENS_Temp_TypeDef *temp)
Fetch current temperature from temperature sensor (in Celsius).

Macro Definition Documentation

#define TEMPSENS_DK_ADDR   0x90

I2C device address for temperature sensor on EFM32GG/LG/WG DK

Definition at line 55 of file tempsens.h .

Enumeration Type Documentation

Available registers in DS75 sensor device

Enumerator
tempsensRegTemp

Temperature register (read-only)

tempsensRegConfig

Configuration register

tempsensRegHysteresis

Hysteresis register

tempsensRegShutdown

Overtemperature shutdown register

Definition at line 62 of file tempsens.h .

Function Documentation

void TEMPSENS_Celsius2Fahrenheit ( TEMPSENS_Temp_TypeDef * temp )

Convert temperature from Celsius to Fahrenheit.

Parameters
[in,out] temp Reference to structure to holding temperature in Celsius to convert. Upon return, it has been changed to Fahrenheit.

Definition at line 58 of file tempsens.c .

References TEMPSENS_Temp_TypeDef::f , and TEMPSENS_Temp_TypeDef::i .

int TEMPSENS_RegisterGet ( I2C_TypeDef * i2c,
uint8_t addr,
TEMPSENS_Register_TypeDef reg,
uint16_t * val
)

Read sensor register content.

If reading the temperature register, when a measurement is completed inside the sensor device, the new measurement may not be stored. For this reason, the temperature should not be polled with a higher frequency than the measurement conversion time for a given resolution configuration. Please refer to sensor device datasheet.

Parameters
[in] i2c Pointer to I2C peripheral register block.
[in] addr I2C address for temperature sensor, in 8 bit format, where LSB is reserved for R/W bit.
[in] reg Register to read.
[out] val Reference to place register read.
Returns
Returns 0 if register read, <0 if unable to read register.

Definition at line 99 of file tempsens.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 , I2C_TransferSeq_TypeDef::len , and tempsensRegConfig .

Referenced by TEMPSENS_TemperatureGet() .

int TEMPSENS_RegisterSet ( I2C_TypeDef * i2c,
uint8_t addr,
TEMPSENS_Register_TypeDef reg,
uint16_t val
)

Write to sensor register.

Parameters
[in] i2c Pointer to I2C peripheral register block.
[in] addr I2C address for temperature sensor, in 8 bit format, where LSB is reserved for R/W bit.
[in] reg Register to write (temperature register cannot be written).
[in] val Value used when writing to register.
Returns
Returns 0 if register written, <0 if unable to write to register.

Definition at line 156 of file tempsens.c .

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

int TEMPSENS_TemperatureGet ( I2C_TypeDef * i2c,
uint8_t addr,
TEMPSENS_Temp_TypeDef * temp
)

Fetch current temperature from temperature sensor (in Celsius).

If reading the temperature, when a measurement is completed inside the sensor device, the new measurement may not be stored. For this reason, the temperature should not be polled with a higher frequency than the measurement conversion time for a given resolution configuration. Please refer to sensor device datasheet.

Note
The sensor on the the DK, STDS75, does not seem to have any check on max temperature limit, ie when exceeding specified max 125 C limit, it will keep increasing 9 bit counter to max representable 9 bit value of 127.5 C and then flip over to negative numbers. There is no limit check in this implementation on such issues.
Parameters
[in] i2c Pointer to I2C peripheral register block.
[in] addr I2C address for temperature sensor, in 8 bit format, where LSB is reserved for R/W bit.
[out] temp Reference to structure to place temperature (in Celsius).
Returns
Returns 0 if temperature read, <0 if unable to read temperature.

Definition at line 223 of file tempsens.c .

References TEMPSENS_Temp_TypeDef::f , TEMPSENS_Temp_TypeDef::i , TEMPSENS_RegisterGet() , and tempsensRegTemp .