DS18x20 temperature sensor

group OW_DEVICE_DS18x20

Device driver for DS18x20 temperature sensor.

Note

Functions with _raw suffix do no implement locking mechanism when using with operating system.

Defines

OW_DS18X20_ALARM_DISABLE

Disable alarm temperature

OW_DS18X20_ALARM_NOCHANGE

Do not modify current alarm settings

OW_DS18X20_TEMP_MIN

Minimum temperature

OW_DS18X20_TEMP_MAX

Maximal temperature

Functions

uint8_t ow_ds18x20_start_raw(ow_t *const ow, const ow_rom_t *const rom_id)

Start temperature conversion on specific (or all) devices.

Return

1 on success, 0 otherwise

Parameters
  • [in] ow: 1-Wire handle

  • [in] rom_id: 1-Wire device address to start measurement for. Set to NULL to start measurement on all devices at the same time

uint8_t ow_ds18x20_start(ow_t *const ow, const ow_rom_t *const rom_id)

Start temperature conversion on specific (or all) devices.

Return

1 on success, 0 otherwise

Note

This function is thread-safe

Parameters
  • [in] ow: 1-Wire handle

  • [in] rom_id: 1-Wire device address to start measurement for. Set to NULL to start measurement on all devices at the same time

uint8_t ow_ds18x20_read_raw(ow_t *const ow, const ow_rom_t *const rom_id, float *const t)

Read temperature previously started with ow_ds18x20_start.

Return

1 on success, 0 otherwise

Parameters
  • [in] ow: 1-Wire handle

  • [in] rom_id: 1-Wire device address to read data from

  • [out] t: Pointer to output float variable to save temperature

uint8_t ow_ds18x20_read(ow_t *const ow, const ow_rom_t *const rom_id, float *const t)

Read temperature previously started with ow_ds18x20_start.

Return

1 on success, 0 otherwise

Note

This function is thread-safe

Parameters
  • [in] ow: 1-Wire handle

  • [in] rom_id: 1-Wire device address to read data from

  • [out] t: Pointer to output float variable to save temperature

uint8_t ow_ds18x20_set_resolution_raw(ow_t *const ow, const ow_rom_t *const rom_id, const uint8_t bits)

Set resolution for DS18B20 sensor.

Note

DS18S20 has fixed 9-bit resolution

Return

1 on success, 0 otherwise

Parameters
  • [in] ow: 1-Wire handle

  • [in] rom_id: 1-Wire device address to set resolution

  • [in] bits: Number of resolution bits. Possible values are 9 - 12

uint8_t ow_ds18x20_set_resolution(ow_t *const ow, const ow_rom_t *const rom_id, const uint8_t bits)

Set resolution for DS18B20 sensor.

Note

DS18S20 has fixed 9-bit resolution

Return

1 on success, 0 otherwise

Note

This function is thread-safe

Parameters
  • [in] ow: 1-Wire handle

  • [in] rom_id: 1-Wire device address to set resolution

  • [in] bits: Number of resolution bits. Possible values are 9 - 12

uint8_t ow_ds18x20_get_resolution_raw(ow_t *const ow, const ow_rom_t *const rom_id)

Get resolution for DS18B20 device.

Return

Resolution in units of bits (9 - 12) on success, 0 otherwise

Parameters
  • [in] ow: 1-Wire handle

  • [in] rom_id: 1-Wire device address to get resolution from

uint8_t ow_ds18x20_get_resolution(ow_t *const ow, const ow_rom_t *const rom_id)

Get resolution for DS18B20 device.

Return

Resolution in units of bits (9 - 12) on success, 0 otherwise

Note

This function is thread-safe

Parameters
  • [in] ow: 1-Wire handle

  • [in] rom_id: 1-Wire device address to get resolution from

uint8_t ow_ds18x20_set_alarm_temp_raw(ow_t *const ow, const ow_rom_t *const rom_id, int8_t temp_l, int8_t temp_h)

Set/clear temperature alarm high/low levels in units of degree Celcius.

Example usage would look something similar to:

//Set alarm temperature; low = 10°C, high = 30°C
ow_ds18x20_set_alarm_temp(&ow, dev_id, 10, 30);
//Set alarm temperature; low = disable, high = no change
ow_ds18x20_set_alarm_temp(&ow, dev_id, OW_DS18X20_ALARM_DISABLE, OW_DS18X20_ALARM_NOCHANGE);
//Set alarm temperature; low = no change, high = disable
ow_ds18x20_set_alarm_temp(&ow, dev_id, OW_DS18X20_ALARM_NOCHANGE, OW_DS18X20_ALARM_DISABLE);
//Set alarm temperature; low = 10°C, high = 30°C
ow_ds18x20_set_alarm_temp(&ow, dev_id, 10, 30);
Note

temp_h and temp_l are high and low temperature alarms and can accept different values:

Return

1 on success, 0 otherwise

Parameters
  • [in] ow: 1-Wire handle

  • [in] rom_id: 1-Wire device address

  • [in] temp_l: Alarm low temperature

  • [in] temp_h: Alarm high temperature

uint8_t ow_ds18x20_set_alarm_temp(ow_t *const ow, const ow_rom_t *const rom_id, int8_t temp_l, int8_t temp_h)

Set/clear temperature alarm high/low levels in units of degree Celcius.

Example usage would look something similar to:

//Set alarm temperature; low = 10°C, high = 30°C
ow_ds18x20_set_alarm_temp(&ow, dev_id, 10, 30);
//Set alarm temperature; low = disable, high = no change
ow_ds18x20_set_alarm_temp(&ow, dev_id, OW_DS18X20_ALARM_DISABLE, OW_DS18X20_ALARM_NOCHANGE);
//Set alarm temperature; low = no change, high = disable
ow_ds18x20_set_alarm_temp(&ow, dev_id, OW_DS18X20_ALARM_NOCHANGE, OW_DS18X20_ALARM_DISABLE);
//Set alarm temperature; low = 10°C, high = 30°C
ow_ds18x20_set_alarm_temp(&ow, dev_id, 10, 30);
Note

temp_h and temp_l are high and low temperature alarms and can accept different values:

Return

1 on success, 0 otherwise

Note

This function is thread-safe

Parameters
  • [in] ow: 1-Wire handle

  • [in] rom_id: 1-Wire device address

  • [in] temp_l: Alarm low temperature

  • [in] temp_h: Alarm high temperature

owr_t ow_ds18x20_search_alarm_raw(ow_t *const ow, ow_rom_t *const rom_id)

Search for DS18x20 devices with alarm flag.

Note

To reset search, use ow_search_reset function

Return

owOK on success, member of owr_t otherwise

Parameters
  • [in] ow: 1-Wire handle

  • [out] rom_id: Pointer to 8-byte long variable to save ROM

owr_t ow_ds18x20_search_alarm(ow_t *const ow, ow_rom_t *const rom_id)

Search for DS18x20 devices with alarm flag.

Note

To reset search, use ow_search_reset function

Return

owOK on success, member of owr_t otherwise

Note

This function is thread-safe

Parameters
  • [in] ow: 1-Wire handle

  • [out] rom_id: Pointer to 8-byte long variable to save ROM

uint8_t ow_ds18x20_is_b(ow_t *const ow, const ow_rom_t *const rom_id)

Check if ROM address matches DS18B20 device.

Return

1 on success, 0 otherwise

Note

This function is reentrant

Parameters
  • [in] ow: 1-Wire handle

  • [in] rom_id: 1-Wire device address to test against DS18B20

uint8_t ow_ds18x20_is_s(ow_t *const ow, const ow_rom_t *const rom_id)

Check if ROM address matches DS18S20 device.

Return

1 on success, 0 otherwise

Note

This function is reentrant

Parameters
  • [in] ow: 1-Wire handle

  • [in] rom_id: 1-Wire device address to test against DS18S20