DS18x20 temperature sensor¶
-
group
LWOW_DEVICE_DS18x20
Device driver for DS18x20 temperature sensor.
- Note
Functions with
_raw
suffix do no implement locking mechanism when using 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
Functions
-
uint8_t
lwow_ds18x20_start_raw
(lwow_t *const ow, const lwow_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 toNULL
to start measurement on all devices at the same time
-
uint8_t
lwow_ds18x20_start
(lwow_t *const ow, const lwow_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 toNULL
to start measurement on all devices at the same time
-
uint8_t
lwow_ds18x20_read_raw
(lwow_t *const ow, const lwow_rom_t *const rom_id, float *const t)¶ Read temperature previously started with lwow_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
lwow_ds18x20_read
(lwow_t *const ow, const lwow_rom_t *const rom_id, float *const t)¶ Read temperature previously started with lwow_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
lwow_ds18x20_set_resolution_raw
(lwow_t *const ow, const lwow_rom_t *const rom_id, const uint8_t bits)¶ Set resolution for
DS18B20
sensor.- Note
DS18S20
has fixed9-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 are9 - 12
-
uint8_t
lwow_ds18x20_set_resolution
(lwow_t *const ow, const lwow_rom_t *const rom_id, const uint8_t bits)¶ Set resolution for
DS18B20
sensor.- Note
DS18S20
has fixed9-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 are9 - 12
-
uint8_t
lwow_ds18x20_get_resolution_raw
(lwow_t *const ow, const lwow_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
lwow_ds18x20_get_resolution
(lwow_t *const ow, const lwow_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
lwow_ds18x20_set_alarm_temp_raw
(lwow_t *const ow, 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)
- 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
lwow_ds18x20_set_alarm_temp
(lwow_t *const ow, 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)
- 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
-
lwowr_t
lwow_ds18x20_search_alarm_raw
(lwow_t *const ow, lwow_rom_t *const rom_id)¶ Search for
DS18x20
devices with alarm flag.- Note
To reset search, use lwow_search_reset function
- Return
- Parameters
[in] ow
: 1-Wire handle[out] rom_id
: Pointer to 8-byte long variable to save ROM
-
lwowr_t
lwow_ds18x20_search_alarm
(lwow_t *const ow, lwow_rom_t *const rom_id)¶ Search for
DS18x20
devices with alarm flag.- Note
To reset search, use lwow_search_reset function
- Return
- 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
lwow_ds18x20_is_b
(lwow_t *const ow, const lwow_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 againstDS18B20
-
uint8_t
lwow_ds18x20_is_s
(lwow_t *const ow, const lwow_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 againstDS18S20