OneWire UART  Version v0.2
Interface 1-Wire devices over UART protocol
DS18x20 temperature sensor

Device driver for DS18x20 temperature sensor. More...

Macros

#define OW_DS18X20_ALARM_DISABLE   ((int8_t)-128)
 
#define OW_DS18X20_ALARM_NOCHANGE   ((int8_t)-127)
 
#define OW_DS18X20_TEMP_MIN   ((int8_t)-55)
 
#define OW_DS18X20_TEMP_MAX   ((int8_t)125)
 

Functions

uint8_t ow_ds18x20_start_raw (ow_t *ow, const ow_rom_t *rom_id)
 Start temperature conversion on specific (or all) devices. More...
 
uint8_t ow_ds18x20_start (ow_t *ow, const ow_rom_t *rom_id)
 Start temperature conversion on specific (or all) devices. More...
 
uint8_t ow_ds18x20_read_raw (ow_t *ow, const ow_rom_t *rom_id, float *t)
 Read temperature previously started with ow_ds18x20_start. More...
 
uint8_t ow_ds18x20_read (ow_t *ow, const ow_rom_t *rom_id, float *t)
 Read temperature previously started with ow_ds18x20_start. More...
 
uint8_t ow_ds18x20_set_resolution_raw (ow_t *ow, const ow_rom_t *rom_id, uint8_t bits)
 Set resolution for DS18B20 sensor. More...
 
uint8_t ow_ds18x20_set_resolution (ow_t *ow, const ow_rom_t *rom_id, uint8_t bits)
 Set resolution for DS18B20 sensor. More...
 
uint8_t ow_ds18x20_get_resolution_raw (ow_t *ow, const ow_rom_t *rom_id)
 Get resolution for DS18B20 device. More...
 
uint8_t ow_ds18x20_get_resolution (ow_t *ow, const ow_rom_t *rom_id)
 Get resolution for DS18B20 device. More...
 
uint8_t ow_ds18x20_set_alarm_temp_raw (ow_t *ow, const ow_rom_t *rom_id, int8_t temp_l, int8_t temp_h)
 Set/clear temperature alarm high/low levels in units of degree Celcius. More...
 
uint8_t ow_ds18x20_set_alarm_temp (ow_t *ow, const ow_rom_t *rom_id, int8_t temp_l, int8_t temp_h)
 Set/clear temperature alarm high/low levels in units of degree Celcius. More...
 
owr_t ow_ds18x20_search_alarm_raw (ow_t *ow, ow_rom_t *rom_id)
 Search for DS18x20 devices with alarm flag. More...
 
owr_t ow_ds18x20_search_alarm (ow_t *ow, ow_rom_t *rom_id)
 Search for DS18x20 devices with alarm flag. More...
 
uint8_t ow_ds18x20_is_b_raw (ow_t *ow, const ow_rom_t *rom_id)
 Check if ROM address matches DS18B20 device. More...
 
uint8_t ow_ds18x20_is_b (ow_t *ow, const ow_rom_t *rom_id)
 Check if ROM address matches DS18B20 device. More...
 
uint8_t ow_ds18x20_is_s_raw (ow_t *ow, const ow_rom_t *rom_id)
 Check if ROM address matches DS18S20 device. More...
 
uint8_t ow_ds18x20_is_s (ow_t *ow, const ow_rom_t *rom_id)
 Check if ROM address matches DS18S20 device. More...
 

Detailed Description

Device driver for DS18x20 temperature sensor.

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

Macro Definition Documentation

◆ OW_DS18X20_ALARM_DISABLE

#define OW_DS18X20_ALARM_DISABLE   ((int8_t)-128)

Disable alarm temperature

◆ OW_DS18X20_ALARM_NOCHANGE

#define OW_DS18X20_ALARM_NOCHANGE   ((int8_t)-127)

Do not modify current alarm settings

◆ OW_DS18X20_TEMP_MAX

#define OW_DS18X20_TEMP_MAX   ((int8_t)125)

Maximal temperature

◆ OW_DS18X20_TEMP_MIN

#define OW_DS18X20_TEMP_MIN   ((int8_t)-55)

Minimum temperature

Function Documentation

◆ ow_ds18x20_get_resolution()

uint8_t ow_ds18x20_get_resolution ( ow_t ow,
const ow_rom_t rom_id 
)

Get resolution for DS18B20 device.

Parameters
[in]ow1-Wire handle
[in]rom_id1-Wire device address to get resolution from
Returns
Resolution in units of bits (9 - 12) on success, 0 otherwise
Note
This function is thread-safe

◆ ow_ds18x20_get_resolution_raw()

uint8_t ow_ds18x20_get_resolution_raw ( ow_t ow,
const ow_rom_t rom_id 
)

Get resolution for DS18B20 device.

Parameters
[in]ow1-Wire handle
[in]rom_id1-Wire device address to get resolution from
Returns
Resolution in units of bits (9 - 12) on success, 0 otherwise

◆ ow_ds18x20_is_b()

uint8_t ow_ds18x20_is_b ( ow_t ow,
const ow_rom_t rom_id 
)

Check if ROM address matches DS18B20 device.

Parameters
[in]ow1-Wire handle
[in]rom_id1-Wire device address to test against DS18B20
Returns
1 on success, 0 otherwise
Note
This function is thread-safe

◆ ow_ds18x20_is_b_raw()

uint8_t ow_ds18x20_is_b_raw ( ow_t ow,
const ow_rom_t rom_id 
)

Check if ROM address matches DS18B20 device.

Parameters
[in]ow1-Wire handle
[in]rom_id1-Wire device address to test against DS18B20
Returns
1 on success, 0 otherwise

◆ ow_ds18x20_is_s()

uint8_t ow_ds18x20_is_s ( ow_t ow,
const ow_rom_t rom_id 
)

Check if ROM address matches DS18S20 device.

Parameters
[in]ow1-Wire handle
[in]rom_id1-Wire device address to test against DS18S20
Returns
1 on success, 0 otherwise
Note
This function is thread-safe

◆ ow_ds18x20_is_s_raw()

uint8_t ow_ds18x20_is_s_raw ( ow_t ow,
const ow_rom_t rom_id 
)

Check if ROM address matches DS18S20 device.

Parameters
[in]ow1-Wire handle
[in]rom_id1-Wire device address to test against DS18S20
Returns
1 on success, 0 otherwise

◆ ow_ds18x20_read()

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

Read temperature previously started with ow_ds18x20_start.

Parameters
[in]ow1-Wire handle
[in]rom_id1-Wire device address to read data from
[out]tPointer to output float variable to save temperature
Returns
1 on success, 0 otherwise
Note
This function is thread-safe

◆ ow_ds18x20_read_raw()

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

Read temperature previously started with ow_ds18x20_start.

Parameters
[in]ow1-Wire handle
[in]rom_id1-Wire device address to read data from
[out]tPointer to output float variable to save temperature
Returns
1 on success, 0 otherwise

◆ ow_ds18x20_search_alarm()

owr_t ow_ds18x20_search_alarm ( ow_t ow,
ow_rom_t rom_id 
)

Search for DS18x20 devices with alarm flag.

Note
To reset search, use ow_search_reset function
Parameters
[in]ow1-Wire handle
[out]rom_idPointer to 8-byte long variable to save ROM
Returns
owOK on success, member of owr_t otherwise
Note
This function is thread-safe

◆ ow_ds18x20_search_alarm_raw()

owr_t ow_ds18x20_search_alarm_raw ( ow_t ow,
ow_rom_t rom_id 
)

Search for DS18x20 devices with alarm flag.

Note
To reset search, use ow_search_reset function
Parameters
[in]ow1-Wire handle
[out]rom_idPointer to 8-byte long variable to save ROM
Returns
owOK on success, member of owr_t otherwise

◆ ow_ds18x20_set_alarm_temp()

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

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

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

Example usage would look something similar to:

//Set alarm temperature; low = 10C, high = 30C
ow_ds18x20_set_alarm_temp(&ow, dev_id, 10, 30);
//Set alarm temperature; low = disable, high = no change
//Set alarm temperature; low = no change, high = disable
//Set alarm temperature; low = 10C, high = 30C
ow_ds18x20_set_alarm_temp(&ow, dev_id, 10, 30);
Parameters
[in]ow1-Wire handle
[in]rom_id1-Wire device address
[in]temp_lAlarm low temperature
[in]temp_hAlarm high temperature
Returns
1 on success, 0 otherwise
Note
This function is thread-safe

◆ ow_ds18x20_set_alarm_temp_raw()

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

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

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

Example usage would look something similar to:

//Set alarm temperature; low = 10C, high = 30C
ow_ds18x20_set_alarm_temp(&ow, dev_id, 10, 30);
//Set alarm temperature; low = disable, high = no change
//Set alarm temperature; low = no change, high = disable
//Set alarm temperature; low = 10C, high = 30C
ow_ds18x20_set_alarm_temp(&ow, dev_id, 10, 30);
Parameters
[in]ow1-Wire handle
[in]rom_id1-Wire device address
[in]temp_lAlarm low temperature
[in]temp_hAlarm high temperature
Returns
1 on success, 0 otherwise

◆ ow_ds18x20_set_resolution()

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

Set resolution for DS18B20 sensor.

Note
DS18S20 has fixed 9-bit resolution
Parameters
[in]ow1-Wire handle
[in]rom_id1-Wire device address to set resolution
[in]bitsNumber of resolution bits. Possible values are 9 - 12
Returns
1 on success, 0 otherwise
Note
This function is thread-safe

◆ ow_ds18x20_set_resolution_raw()

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

Set resolution for DS18B20 sensor.

Note
DS18S20 has fixed 9-bit resolution
Parameters
[in]ow1-Wire handle
[in]rom_id1-Wire device address to set resolution
[in]bitsNumber of resolution bits. Possible values are 9 - 12
Returns
1 on success, 0 otherwise

◆ ow_ds18x20_start()

uint8_t ow_ds18x20_start ( ow_t ow,
const ow_rom_t rom_id 
)

Start temperature conversion on specific (or all) devices.

Parameters
[in]ow1-Wire handle
[in]rom_id1-Wire device address to start measurement for. Set to NULL to start measurement on all devices at the same time
Returns
1 on success, 0 otherwise
Note
This function is thread-safe

◆ ow_ds18x20_start_raw()

uint8_t ow_ds18x20_start_raw ( ow_t ow,
const ow_rom_t rom_id 
)

Start temperature conversion on specific (or all) devices.

Parameters
[in]ow1-Wire handle
[in]rom_id1-Wire device address to start measurement for. Set to NULL to start measurement on all devices at the same time
Returns
1 on success, 0 otherwise