DS18x20 temperature sensor
- group LWOW_DEVICE_DS18x20
Device driver for DS18x20 temperature sensor.
Note
Functions with
_raw
suffix do no implement locking mechanism when used with operating system.Defines
-
LWOW_DS18X20_ALARM_DISABLE
Disable alarm temperature
-
LWOW_DS18X20_ALARM_NOCHANGE
Do not modify current alarm settings
-
LWOW_DS18X20_TEMP_MIN
Minimum temperature
-
LWOW_DS18X20_TEMP_MAX
Maximal temperature
-
LWOW_DS18X20_CMD_ALARM_SEARCH
Alarm Search Command
-
LWOW_DS18X20_CMD_CONVERT_T
Convert T Command
Functions
-
uint8_t lwow_ds18x20_start_raw(lwow_t *const owobj, const lwow_rom_t *const rom_id)
Start temperature conversion on specific (or all) devices.
- Parameters
ow – [in] 1-Wire handle
rom_id – [in] 1-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
-
uint8_t lwow_ds18x20_start(lwow_t *const owobj, const lwow_rom_t *const rom_id)
Start temperature conversion on specific (or all) devices.
Note
This function is thread-safe
- Parameters
ow – [in] 1-Wire handle
rom_id – [in] 1-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
-
uint8_t lwow_ds18x20_read_raw(lwow_t *const owobj, const lwow_rom_t *const rom_id, float *const temp_out)
Read temperature previously started with lwow_ds18x20_start.
- Parameters
ow – [in] 1-Wire handle
rom_id – [in] 1-Wire device address to read data from
temp_out – [out] Pointer to output float variable to save temperature
- Returns
1
on success,0
otherwise
-
uint8_t lwow_ds18x20_read(lwow_t *const owobj, const lwow_rom_t *const rom_id, float *const temp_out)
Read temperature previously started with lwow_ds18x20_start.
Note
This function is thread-safe
- Parameters
ow – [in] 1-Wire handle
rom_id – [in] 1-Wire device address to read data from
temp_out – [out] Pointer to output float variable to save temperature
- Returns
1
on success,0
otherwise
-
uint8_t lwow_ds18x20_set_resolution_raw(lwow_t *const owobj, const lwow_rom_t *const rom_id, const uint8_t bits)
Set resolution for
DS18B20
sensor.Note
DS18S20
has fixed9-bit
resolution- Parameters
ow – [in] 1-Wire handle
rom_id – [in] 1-Wire device address to set resolution
bits – [in] Number of resolution bits. Possible values are
9 - 12
- Returns
1
on success,0
otherwise
-
uint8_t lwow_ds18x20_set_resolution(lwow_t *const owobj, const lwow_rom_t *const rom_id, const uint8_t bits)
Set resolution for
DS18B20
sensor.Note
DS18S20
has fixed9-bit
resolutionNote
This function is thread-safe
- Parameters
ow – [in] 1-Wire handle
rom_id – [in] 1-Wire device address to set resolution
bits – [in] Number of resolution bits. Possible values are
9 - 12
- Returns
1
on success,0
otherwise
-
uint8_t lwow_ds18x20_get_resolution_raw(lwow_t *const owobj, const lwow_rom_t *const rom_id)
Get resolution for
DS18B20
device.- Parameters
ow – [in] 1-Wire handle
rom_id – [in] 1-Wire device address to get resolution from
- Returns
Resolution in units of bits (
9 - 12
) on success,0
otherwise
-
uint8_t lwow_ds18x20_get_resolution(lwow_t *const owobj, const lwow_rom_t *const rom_id)
Get resolution for
DS18B20
device.Note
This function is thread-safe
- Parameters
ow – [in] 1-Wire handle
rom_id – [in] 1-Wire device address to get resolution from
- Returns
Resolution in units of bits (
9 - 12
) on success,0
otherwise
-
uint8_t lwow_ds18x20_set_alarm_temp_raw(lwow_t *const owobj, const lwow_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 lwow_ds18x20_set_alarm_temp(&ow, dev_id, 10, 30); //Set alarm temperature; low = disable, high = no change lwow_ds18x20_set_alarm_temp(&ow, dev_id, LWOW_DS18X20_ALARM_DISABLE, LWOW_DS18X20_ALARM_NOCHANGE); //Set alarm temperature; low = no change, high = disable lwow_ds18x20_set_alarm_temp(&ow, dev_id, LWOW_DS18X20_ALARM_NOCHANGE, LWOW_DS18X20_ALARM_DISABLE); //Set alarm temperature; low = 10°C, high = 30°C lwow_ds18x20_set_alarm_temp(&ow, dev_id, 10, 30);
Note
temp_h
andtemp_l
are high and low temperature alarms and can accept different values:-55 % 125
, valid temperature rangeLWOW_DS18X20_ALARM_DISABLE to disable temperature alarm (either high or low)
LWOW_DS18X20_ALARM_NOCHANGE to keep current alarm temperature (either high or low)
- Parameters
ow – [in] 1-Wire handle
rom_id – [in] 1-Wire device address
temp_l – [in] Alarm low temperature
temp_h – [in] Alarm high temperature
- Returns
1
on success,0
otherwise
-
uint8_t lwow_ds18x20_set_alarm_temp(lwow_t *const owobj, const lwow_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 lwow_ds18x20_set_alarm_temp(&ow, dev_id, 10, 30); //Set alarm temperature; low = disable, high = no change lwow_ds18x20_set_alarm_temp(&ow, dev_id, LWOW_DS18X20_ALARM_DISABLE, LWOW_DS18X20_ALARM_NOCHANGE); //Set alarm temperature; low = no change, high = disable lwow_ds18x20_set_alarm_temp(&ow, dev_id, LWOW_DS18X20_ALARM_NOCHANGE, LWOW_DS18X20_ALARM_DISABLE); //Set alarm temperature; low = 10°C, high = 30°C lwow_ds18x20_set_alarm_temp(&ow, dev_id, 10, 30);
Note
temp_h
andtemp_l
are high and low temperature alarms and can accept different values:-55 % 125
, valid temperature rangeLWOW_DS18X20_ALARM_DISABLE to disable temperature alarm (either high or low)
LWOW_DS18X20_ALARM_NOCHANGE to keep current alarm temperature (either high or low)
Note
This function is thread-safe
- Parameters
ow – [in] 1-Wire handle
rom_id – [in] 1-Wire device address
temp_l – [in] Alarm low temperature
temp_h – [in] Alarm high temperature
- Returns
1
on success,0
otherwise
-
uint8_t lwow_ds18x20_get_alarm_temp_raw(lwow_t *const owobj, const lwow_rom_t *const rom_id, int8_t *temp_l, int8_t *temp_h)
Get the low and high temperature triggers for the alarm configuration.
- Parameters
ow – [in] 1-Wire handle
rom_id – [in] 1-Wire device address
temp_l – [out] Pointer to output variable to write low temperature alarm trigger
temp_h – [out] Pointer to output variable to write high temperature alarm trigger
- Returns
1
on success,0
otherwise
-
uint8_t lwow_ds18x20_get_alarm_temp(lwow_t *const owobj, const lwow_rom_t *const rom_id, int8_t *temp_l, int8_t *temp_h)
Get the low and high temperature triggers for the alarm configuration.
Note
This function is thread-safe
- Parameters
ow – [in] 1-Wire handle
rom_id – [in] 1-Wire device address
temp_l – [out] Pointer to output variable to write low temperature alarm trigger
temp_h – [out] Pointer to output variable to write high temperature alarm trigger
- Returns
1
on success,0
otherwise
-
lwowr_t lwow_ds18x20_search_alarm_raw(lwow_t *const owobj, lwow_rom_t *const rom_id)
Search for
DS18x20
devices with alarm flag.Note
To reset search, use lwow_search_reset function
-
lwowr_t lwow_ds18x20_search_alarm(lwow_t *const owobj, lwow_rom_t *const rom_id)
Search for
DS18x20
devices with alarm flag.Note
To reset search, use lwow_search_reset function
Note
This function is thread-safe
-
uint8_t lwow_ds18x20_is_b(lwow_t *const owobj, const lwow_rom_t *const rom_id)
Check if ROM address matches
DS18B20
device.Note
This function is reentrant
- Parameters
ow – [in] 1-Wire handle
rom_id – [in] 1-Wire device address to test against
DS18B20
- Returns
1
on success,0
otherwise
-
uint8_t lwow_ds18x20_is_s(lwow_t *const owobj, const lwow_rom_t *const rom_id)
Check if ROM address matches
DS18S20
device.Note
This function is reentrant
- Parameters
ow – [in] 1-Wire handle
rom_id – [in] 1-Wire device address to test against
DS18S20
- Returns
1
on success,0
otherwise
-
uint16_t lwow_ds18x20_get_temp_conversion_time(uint8_t resolution, uint8_t is_b)
Get temperature conversion time in units of milliseconds for a specific resolution.
- Parameters
resolution – Resolution in bits
is_b – [in] Set to
1
for DS18B20,0
otherwise
- Returns
uint16_t
-
LWOW_DS18X20_ALARM_DISABLE