DS18 temperature sensor driver

Driver interface for the DS18 temperature sensors.

This driver provides [S]ensor [A]ctuator [U]ber [L]ayer capabilities. Currently the driver has the following limitations:

  • Does not allow addressing devices, only supports a single device on the bus.

  • The 1-Wire bus handling is hardcoded to the driver.

  • Does not allow configuration of sampling width.

    Note

    Due to timing issues present on some boards this drivers features two ways of reading information from the sensor. The optimized uses accurate delays to handle this, while the second way polls the line for changes. If you know that your board can handle ~3us resolution with the xtimer module, then the optimized way is recommended. To used the optimized way add the ds18_optimized module. Also this driver test application has a whitelist of the boards this driver has been tested on and known to work.

DS18_OK
1
(0)
DS18_ERROR
1
(-1)
int ds18_init(ds18_t * dev, const ds18_params_t * params)

Initialize a ds18 device.

Parameters

dev:device descriptor
params:ds18 initialization struct

Return values

  • 0 on success
  • -1 on error
int ds18_trigger(ds18_t * dev)

Triggers a temperature conversion.

Note

This also triggers a conversion on all devices connected to the bus

Parameters

dev:device descriptor

Return values

  • 0 on success
  • -1 on error
int ds18_read(ds18_t * dev, int16_t * temperature)

Reads the scratchpad for the last conversion.

Parameters

dev:device descriptor
temperature:buffer to write the temperature in centi-degrees

Return values

  • 0 on success
  • -1 on error
int ds18_get_temperature(ds18_t * dev, int16_t * temperature)

convenience fuction for triggering a conversion and reading the value

Note

This function will block for the convertion time. The current implementation of the driver uses 12-bit resolution, so this time is 750 ms.

Parameters

dev:device descriptor
temperature:buffer to write the temperature in centi-degrees

Return values

  • 0 on success
  • -1 on error
struct ds18_t

Device descriptor for a ds18 device.

gpio.h::gpio_t pin

Pin the sensor is connected to.

cc2538/include/periph_cpu.h::gpio_mode_t out_mode

Pin output mode.

cc2538/include/periph_cpu.h::gpio_mode_t in_mode

Pin input mode.

struct ds18_params_t

Device initialization parameters.

gpio.h::gpio_t pin

Pin the sensor is connected to.

cc2538/include/periph_cpu.h::gpio_mode_t out_mode

Pin output mode.