Loading...
Searching...
No Matches

Driver for the LM75 and TMP1075 temperature sensors. More...

Detailed Description

Driver for the LM75 and TMP1075 temperature sensors.

Author
Vitor Batista vitor.nosp@m..bat.nosp@m.ista@.nosp@m.ml-p.nosp@m.a.com

Definition in file lm75.h.

#include <errno.h>
#include <stdbool.h>
#include "periph/gpio.h"
#include "periph/i2c.h"
+ Include dependency graph for lm75.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  lm75_properties
 Temperature reading properties/resolutions struct of the LM75 sensors. More...
 
struct  lm75_params
 Parameters required for initialization. More...
 
struct  lm75
 LM75 device descriptor. More...
 

Typedefs

typedef struct lm75_properties lm75_properties_t
 Temperature reading properties/resolutions struct of the LM75 sensors.
 
typedef struct lm75_params lm75_params_t
 Parameters required for initialization.
 
typedef struct lm75 lm75_t
 LM75 device descriptor.
 

Functions

int lm75_init (lm75_t *dev, const lm75_params_t *params)
 Initialization of the LM75 sensor.
 
int lm75_get_temperature_raw (const lm75_t *dev, int32_t *temperature)
 Temperature values of LM75 sensor.
 
int lm75_get_temperature (const lm75_t *dev, int32_t *temperature)
 Temperature values of LM75 sensor.
 
int lm75_set_temp_limits (const lm75_t *dev, int32_t temp_hyst, int32_t temp_os, gpio_cb_t cb, void *arg)
 Sets the values for Overtemperature Shutdown (OS) and Hysteresis Temperature (HYST).
 
int lm75_get_os_temp (const lm75_t *dev, int32_t *temperature)
 Overtemperature Shutdown (OS) value of the LM75 sensor.
 
int lm75_get_hyst_temp (const lm75_t *dev, int32_t *temperature)
 Hysteresis Temperature (HYST) value of the LM75 sensor.
 
int lm75_get_os_pin (const lm75_t *dev, bool *os_pin_state)
 Read the current state of the OS pin to see if it's active.
 
int lm75_poweroff (const lm75_t *dev)
 Activate the LM75 sensor shutdown mode.
 
int lm75_poweron (const lm75_t *dev)
 Deactivate the LM75 sensor shutdown mode.
 
int tmp1075_one_shot (const lm75_t *dev)
 Activates one shot conversion mode.
 
int lm75_low_power_mode (const lm75_t *dev, uint16_t interval)
 Activates low power mode operation.
 

Variables

lm75_properties_t lm75a_properties
 declaration present in lm75.c
 
lm75_properties_t tmp1075_properties
 declaration present in lm75.c
 

Backwards compatible LM75 return values

Deprecated
Use errno directly instead
#define LM75_SUCCESS   0
 Success.
 
#define LM75_ERROR_I2C   (-EIO)
 I2C communication error.
 
#define LM75_ERROR   (-EINVAL)
 Other error.
 

Macro Definition Documentation

◆ LM75_ERROR

#define LM75_ERROR   (-EINVAL)

Other error.

Definition at line 42 of file lm75.h.

◆ LM75_ERROR_I2C

#define LM75_ERROR_I2C   (-EIO)

I2C communication error.

Definition at line 41 of file lm75.h.

◆ LM75_SUCCESS

#define LM75_SUCCESS   0

Success.

Definition at line 40 of file lm75.h.

Function Documentation

◆ lm75_get_hyst_temp()

int lm75_get_hyst_temp ( const lm75_t * dev,
int32_t * temperature )

Hysteresis Temperature (HYST) value of the LM75 sensor.

Reads the sensor hysteresis temperature value from THYST_REG in ºC.

Parameters
[in]devdevice structure
[out]temperaturebuffer that the HYST temperature value will be written to
Return values
0success
<0Error from I2C, see i2c_read_reg

◆ lm75_get_os_pin()

int lm75_get_os_pin ( const lm75_t * dev,
bool * os_pin_state )

Read the current state of the OS pin to see if it's active.

Reads the configuration register to see the OS pin's polarity and then reads its state. Then outputs if the pin is active and whether it's in the low and active or high and active.

Parameters
[in]devdevice structure
[out]os_pin_statepointer to the state of the OS pin - 0 for inactive and 1 for active
Return values
0success
<0Error from I2C, see i2c_read_reg

◆ lm75_get_os_temp()

int lm75_get_os_temp ( const lm75_t * dev,
int32_t * temperature )

Overtemperature Shutdown (OS) value of the LM75 sensor.

Reads the sensor OS temperature value from TOS_REG in ºC.

Parameters
[in]devdevice structure
[out]temperaturebuffer that the OS temperature value will be written to
Return values
0success
<0Error from I2C, see i2c_read_reg

◆ lm75_get_temperature()

int lm75_get_temperature ( const lm75_t * dev,
int32_t * temperature )

Temperature values of LM75 sensor.

Gets the device's temperature register with the lm75_get_temperature_raw function and then returns the values in mºC, truncating values smaller than this, if available.

Parameters
[in]devdevice structure
[out]temperaturethat the temperature value will be written to in mºC
Return values
0success
<0Error from I2C, see i2c_read_reg

◆ lm75_get_temperature_raw()

int lm75_get_temperature_raw ( const lm75_t * dev,
int32_t * temperature )

Temperature values of LM75 sensor.

Reads the sensor temperature values from TEMP_REG. The value is given with the full precision the device is capable of. If divided by the device's temp_mult property, the result will be the temperature in ºC and the remainder of that division will be the decimal part of the temperature, at the maximum resolution the device is capable of.

Parameters
[in]devdevice structure
[out]temperaturebuffer that the temperature value will be written to
Return values
0success
<0Error from I2C, see i2c_read_reg

◆ lm75_init()

int lm75_init ( lm75_t * dev,
const lm75_params_t * params )

Initialization of the LM75 sensor.

Initializes the sensor according to the specified input parameters.

Parameters
[out]devdevice structure to initialize
[in]paramsinitialization parameters
Return values
0success
-EINVALNot an LM75 or TMP1075 sensor (value in ID register does not match)
<0Error from I2C, see i2c_read_reg

◆ lm75_low_power_mode()

int lm75_low_power_mode ( const lm75_t * dev,
uint16_t interval )

Activates low power mode operation.

This function makes the device measure temperatures in a strictly discrete way at a user definable rate, as opposed to performing continuous measurements at the device's conversion rate.

It allows the device to stay in shutdown mode for the most part, therefore consuming less power. In the TMP1075 and other devices which have the one shot feature this is done automatically. In the LM75A sensor and other sensors which lack the one shot mode feature this is done manually by switching the device to and from shutdown mode and staying awake at least long enough to perform one measurement.

Parameters
[in]devdevice structure
[in]intervaltime interval in ms between measurements
Return values
0success
<0Error from I2C, see i2c_read_reg

◆ lm75_poweroff()

int lm75_poweroff ( const lm75_t * dev)

Activate the LM75 sensor shutdown mode.

Parameters
[in]devdevice structure to set into shutdown mode
Return values
0success
<0Error from I2C, see i2c_read_reg

◆ lm75_poweron()

int lm75_poweron ( const lm75_t * dev)

Deactivate the LM75 sensor shutdown mode.

Parameters
[in]devdevice structure to wake up from shutdown mode
Return values
0success
<0Error from I2C, see i2c_read_reg

◆ lm75_set_temp_limits()

int lm75_set_temp_limits ( const lm75_t * dev,
int32_t temp_hyst,
int32_t temp_os,
gpio_cb_t cb,
void * arg )

Sets the values for Overtemperature Shutdown (OS) and Hysteresis Temperature (HYST).

OS gives the temperature's upper bound and HYST the lower bound. The values are rounded to the lowest value that the device supports.

Parameters
[in]devdevice structure
[in]temp_hystdesired HYST temperature in mºC
[in]temp_osdesired OS temperature in mºC
[in]cbcallback that is called from interrupt context
[in]argoptional arguments for the gpio_init_int function
Return values
0success
-EINVALInvalid hysteresis or invalid GPIO config
<0Error from I2C, see i2c_read_reg

◆ tmp1075_one_shot()

int tmp1075_one_shot ( const lm75_t * dev)

Activates one shot conversion mode.

Wakes from shutdown mode, does a single temperature conversion and writes in into the temperature register and then goes back into shutdown.

Parameters
[in]devdevice structure
Return values
0success
-ENOTSUPfeature not supported by hardware variant used
<0Error from I2C, see i2c_read_reg