3.2.3. ds18b20 — One-wire temperature sensor

DS18B20 is a one-wire temperature sensor.

../../../_images/ds18b20.png

Source code: src/drivers/sensors/ds18b20.h, src/drivers/sensors/ds18b20.c

Test code: tst/drivers/hardware/sensors/ds18b20/main.c


Defines

DS18B20_FAMILY_CODE

Functions

int ds18b20_module_init(void)

Initialize the DS18B20 driver module. This function must be called before calling any other function in this module.

The module will only be initialized once even if this function is called multiple times.

Return
zero(0) or negative error code.

int ds18b20_init(struct ds18b20_driver_t *self_p, struct owi_driver_t *owi_p)

Initialize given driver object. The driver object will communicate with all DS18B20 sensors on given OWI bus.

Return
zero(0) or negative error code.
Parameters
  • self_p: Driver object to be initialized.
  • owi_p: One-Wire (OWI) driver.

int ds18b20_convert(struct ds18b20_driver_t *self_p)

Start a temperature convertion on all sensors. The converted temperature can later be read with ds18b20_read*().

Return
zero(0) or negative error code.
Parameters
  • self_p: Initialized driver object.

int ds18b20_read(struct ds18b20_driver_t *self_p, const uint8_t *id_p, float *temperature_p)

Read the most recently converted temperature from given sensor.

Return
zero(0) or negative error code.
Parameters
  • self_p: Initialized driver object.
  • id_p: Sensor identity.
  • temperature_p: Measured temperature.

int ds18b20_read_fixed_point(struct ds18b20_driver_t *self_p, const uint8_t *id_p, int *temperature_p)

Read the most recently converted temperature from given sensor as a fixed point number.

Return
zero(0) or negative error code.
Parameters
  • self_p: Initialized driver object.
  • id_p: Sensor identity.
  • temperature_p: Measured temperature in Q4 fixed point format, or unit 0.0625 degrees Celsius (the raw value read from the sensor).

char *ds18b20_read_string(struct ds18b20_driver_t *self_p, const uint8_t *id_p, char *temperature_p)

Read the most recently converted temperature from given sensor as a string.

Return
temperature_p on success, NULL otherwise.
Parameters
  • self_p: Initialized driver object.
  • id_p: Sensor identity.
  • temperature_p: Measured temperature as a string.

int ds18b20_get_temperature(struct ds18b20_driver_t *self_p, const uint8_t *id_p, int *temperature_p)

Read the most recently converted temperature from given sensor. Call ds18b20_convert() to read the temperature from the sensor and update the cached value.

Return
zero(0) or negative error code.
Parameters
  • self_p: Initialized driver object.
  • id_p: Sensor identity.
  • temperature_p: Measured temperature in 0.0625 degrees Celsius (the raw value read from the sensor).

char *ds18b20_get_temperature_str(struct ds18b20_driver_t *self_p, const uint8_t *id_p, char *temperature_p)

Get temperature for given sensor identity formatted as a string.

Return
temperature_p on success, NULL otherwise.
Parameters
  • self_p: Initialized driver object.
  • id_p: Sensor identity.
  • temperature_p: Measured formatted temperature.

struct ds18b20_driver_t

Public Members

struct owi_driver_t *owi_p
struct ds18b20_driver_t *next_p