From c085f2d292afd8790cd167f5333cab8e56fca988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Mon, 7 Dec 2020 19:07:56 +0100 Subject: [PATCH] sensor_ds18b20: fix set precision for single device --- lib/sensor_ds18b20.c | 10 ++++++++-- lib/sensor_ds18b20.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/sensor_ds18b20.c b/lib/sensor_ds18b20.c index 0ae2476..1ef6a11 100644 --- a/lib/sensor_ds18b20.c +++ b/lib/sensor_ds18b20.c @@ -109,8 +109,14 @@ float sensor_ds18b20_temperature(uint64_t code) } // send ROM command to select slave - if (!onewire_master_rom_match(code)) { // select specific slave - return NAN; // ROM command failed + if (0 == code) { // broadcast convert + if (!onewire_master_rom_skip()) { // select all slaves + return false; // ROM command failed + } + } else { + if (!onewire_master_rom_match(code)) { // select specific slave + return false; // ROM command failed + } } // read scratchpad to get temperature (on byte 0 and 1) diff --git a/lib/sensor_ds18b20.h b/lib/sensor_ds18b20.h index 28f2b66..20f1334 100644 --- a/lib/sensor_ds18b20.h +++ b/lib/sensor_ds18b20.h @@ -36,7 +36,7 @@ bool sensor_ds18b20_convert(uint64_t code); */ float sensor_ds18b20_temperature(uint64_t code); /** set conversion precision - * @param[in] code ROM code of sensor to start conversion on (0 for all, if only DS18B20 sensors are on the bus) + * @param[in] code ROM code of sensor to start conversion on (0 for single DS18B20 sensor are on the bus) * @param[in] precision precision in bits (9-12) * @return if operation succeeded */