Driver for the LM75 and TMP1075 temperature sensors.
More...
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"
Go to the source code of this file.
|
|
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.
|
| |
|
| 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.
|
| |
◆ LM75_ERROR
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
Success.
Definition at line 40 of file lm75.h.
◆ 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] | dev | device structure |
| [out] | temperature | buffer that the HYST temperature value will be written to |
- Return values
-
◆ 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] | dev | device structure |
| [out] | os_pin_state | pointer to the state of the OS pin - 0 for inactive and 1 for active |
- Return values
-
◆ 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] | dev | device structure |
| [out] | temperature | buffer that the OS temperature value will be written to |
- Return values
-
◆ 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] | dev | device structure |
| [out] | temperature | that the temperature value will be written to in mºC |
- Return values
-
◆ 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] | dev | device structure |
| [out] | temperature | buffer that the temperature value will be written to |
- Return values
-
◆ lm75_init()
Initialization of the LM75 sensor.
Initializes the sensor according to the specified input parameters.
- Parameters
-
| [out] | dev | device structure to initialize |
| [in] | params | initialization parameters |
- Return values
-
| 0 | success |
| -EINVAL | Not an LM75 or TMP1075 sensor (value in ID register does not match) |
| <0 | Error 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] | dev | device structure |
| [in] | interval | time interval in ms between measurements |
- Return values
-
◆ lm75_poweroff()
| int lm75_poweroff |
( |
const lm75_t * | dev | ) |
|
Activate the LM75 sensor shutdown mode.
- Parameters
-
| [in] | dev | device structure to set into shutdown mode |
- Return values
-
◆ lm75_poweron()
| int lm75_poweron |
( |
const lm75_t * | dev | ) |
|
Deactivate the LM75 sensor shutdown mode.
- Parameters
-
| [in] | dev | device structure to wake up from shutdown mode |
- Return values
-
◆ 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] | dev | device structure |
| [in] | temp_hyst | desired HYST temperature in mºC |
| [in] | temp_os | desired OS temperature in mºC |
| [in] | cb | callback that is called from interrupt context |
| [in] | arg | optional arguments for the gpio_init_int function |
- Return values
-
| 0 | success |
| -EINVAL | Invalid hysteresis or invalid GPIO config |
| <0 | Error 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
-
- Return values
-
| 0 | success |
| -ENOTSUP | feature not supported by hardware variant used |
| <0 | Error from I2C, see i2c_read_reg |