3-phase PV router
Loading...
Searching...
No Matches
ds18b20.h File Reference

The checks of a DS18B20 reading: CRC, conversion to hundredths of °C, range, power-on value. More...

#include <stdint.h>
Include dependency graph for ds18b20.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  DS18B20::PowerOnFilter
 The readings of one sensor, the power-on value skipped. More...
 

Namespaces

namespace  DS18B20
 

Typedefs

using DS18B20::ScratchPad = uint8_t[9]
 The scratchpad: temperature LSB and MSB, TH, TL, configuration, 3 reserved bytes, CRC.
 

Functions

constexpr uint8_t DS18B20::crc8 (const uint8_t *data, uint8_t len)
 The Dallas/Maxim CRC-8 (x^8 + x^5 + x^4 + 1), as OneWire::crc8.
 
constexpr int16_t DS18B20::decode (const ScratchPad &buf)
 The reading of a scratchpad, its CRC checked.
 
constexpr bool isValidTemperature (int16_t temperature_x100)
 Whether a temperature reading is valid, and so worth sending.
 
constexpr int16_t DS18B20::skipPowerOnValue (int16_t reading, int16_t previous)
 The reading to keep, the power-on value skipped.
 
constexpr int16_t DS18B20::toHundredths (uint8_t lsb, uint8_t msb)
 The temperature of the register, in hundredths of °C.
 

Variables

constexpr uint8_t CONVERT_TEMPERATURE { 0x44 }
 
constexpr int16_t DEVICE_DISCONNECTED_RAW { -7040 }
 
constexpr int16_t OUTOFRANGE_TEMPERATURE { 30200 }
 
constexpr int16_t DS18B20::POWER_ON_JUMP { 500 }
 
constexpr int16_t DS18B20::POWER_ON_VALUE { 8500 }
 
constexpr uint8_t READ_SCRATCHPAD { 0xBE }
 
constexpr int16_t TEMP_RANGE_HIGH { 12500 }
 
constexpr int16_t TEMP_RANGE_LOW { -5500 }
 
constexpr uint8_t WRITE_SCRATCH { 0x4E }
 

Detailed Description

The checks of a DS18B20 reading: CRC, conversion to hundredths of °C, range, power-on value.

Author
Frédéric Metrich (frede.nosp@m.ric..nosp@m.metri.nosp@m.ch@l.nosp@m.ive.f.nosp@m.r)
Version
0.1
Date
2026-11-21

The bus I/O stays in utils_temp.h. Here, what is done with the 9 bytes of the scratchpad once read, and with the reading once converted:

  • the CRC of the scratchpad (Dallas/Maxim CRC-8, the one of the OneWire library),
  • the temperature, x16 in the sensor, x100 here,
  • the range of the sensor (-55 to +125 °C),
  • the power-on value (85.00 °C), skipped after a jump,
  • which values are not a temperature, and so are not sent.

No Arduino dependency: the native tests run it (test/native/test_ds18b20).

Definition in file ds18b20.h.

Function Documentation

◆ isValidTemperature()

bool isValidTemperature ( int16_t temperature_x100)
constexpr

Whether a temperature reading is valid, and so worth sending.

Parameters
temperature_x100The reading, in hundredths of °C.

Definition at line 146 of file ds18b20.h.

Here is the caller graph for this function:

Variable Documentation

◆ CONVERT_TEMPERATURE

uint8_t CONVERT_TEMPERATURE { 0x44 }
inlineconstexpr

Definition at line 30 of file ds18b20.h.

◆ DEVICE_DISCONNECTED_RAW

int16_t DEVICE_DISCONNECTED_RAW { -7040 }
inlineconstexpr

no answer, or a CRC error

Definition at line 38 of file ds18b20.h.

◆ OUTOFRANGE_TEMPERATURE

int16_t OUTOFRANGE_TEMPERATURE { 30200 }
inlineconstexpr

this value (302C) is sent if the sensor reports below -55C or above +125C

Definition at line 34 of file ds18b20.h.

◆ READ_SCRATCHPAD

uint8_t READ_SCRATCHPAD { 0xBE }
inlineconstexpr

Definition at line 31 of file ds18b20.h.

◆ TEMP_RANGE_HIGH

int16_t TEMP_RANGE_HIGH { 12500 }
inlineconstexpr

Definition at line 36 of file ds18b20.h.

◆ TEMP_RANGE_LOW

int16_t TEMP_RANGE_LOW { -5500 }
inlineconstexpr

Definition at line 35 of file ds18b20.h.

◆ WRITE_SCRATCH

uint8_t WRITE_SCRATCH { 0x4E }
inlineconstexpr

Definition at line 32 of file ds18b20.h.