DS18B20 API Overview
This API contains the functions to configure and control a DS18B20 temperature sensor over a 1-Wire bus.
DS18B20 Macros
The DS18B20 temperature sensor has 6 specific commands that are defined as the following macros:
- DS18B20_TEMP_CONV: Performs a temperature conversion and copies it to scratchpad memory.
- DS18B20_SCRPD_CPY: Copies scratchpad memory values to device's EEPROM (only config, TH and TL registers).
- DS18B20_SCRPD_WR: Allows the master to write the 3 registers of the scratchpad memory.
- DS18B20_SCRPD_RD: Allows the master to read the contents of the scratchpad.
- DS18B20_EEPROM_RCL: Recalls the alarm trigger and configuration registers from the EEPROM to scratchpad memory.
- DS18B20_PWR_RD: Reads power supply (externally or parasite-powered).
Verifies that the family code stored in rom first byte belongs to the driver supported device. Data read is CRC8 checked before a success is reported.
- Parameters
-
[in] | rom | address where ROM of device is stored. |
- Return values
-
0 | on success. |
<0 | if there is any error. |
Configures resolution and alarm registers of a specific DS18B20.
- Parameters
-
[in] | rom | address where ROM of device is stored. NULL if only one device is connected to the 1-Wire bus. |
[in] | th | alarm High Register. |
[in] | tl | alarm Low Register. |
[in] | resolution | resolution to be configured (9, 10, 11 or 12 bits). |
- Return values
-
0 | on success. |
<0 | if there is any error. |
Restores data from permanent EEPROM (TH, TL and configuration registers) to scratchpad memory.
- Parameters
-
[in] | rom | address where ROM of device is stored. NULL if only one device is connected to the 1-Wire bus. |
- Return values
-
0 | on success. |
<0 | if there is any error. |
Checks wether the DS18B20 is parasite powered.
- Parameters
-
[in] | uint8_t | *rom address where ROM of device is stored. NULL if only one device is connected to the 1-Wire bus. |
- Return values
-
0 | if device is externally powered. |
1 | if device is parasite powered. |
<0 | if there is any error. |
Reads temperature registers from DS18B20. If device is parasite-powered a strong pull-up is necessary.
- Parameters
-
[in] | rom | address where ROM of device is stored. NULL if only one device is connected to the 1-Wire bus. |
[in] | temperature | buffer where read register will be stored. |
- Return values
-
0 | on success. |
<0 | if there is any error. |
Copies data from scratchpad memory (TH, TL and configuration registers) to permanent EEPROM. If device is parasite-powered a strong pull-up is necessary.
- Parameters
-
[in] | rom | address where ROM of device is stored. NULL if only one device is connected to the 1-Wire bus. |
- Return values
-
0 | on success. |
<0 | if there is any error. |
Reads the content of scratchpad memory (temperature, triggers and configuration registers) from DS18B20. Data read is CRC8 checked before a success is reported.
- Parameters
-
[in] | rom | address where ROM of device is stored. NULL if only one device is connected to the 1-Wire bus. |
[in] | scratchpad | address where content of memory will be stored. |
- Return values
-
0 | on success. |
<0 | if there is any error. |
Performs a conversion of the temperature read from DS18B20.
- Parameters
-
[in] | temp_regs | temperature registers (LSB and MSB). |
- Return values
-
signed | value of temperature multiplied by 100 (2 less significative digits are decimals). |
Verifies that the family code stored in rom first byte belongs to the driver supported device. Data read is CRC8 checked before a success is reported.
- Parameters
-
[in] | rom | address where ROM of device is stored. |
- Return values
-
0 | on success. |
<0 | if there is any error. |