From 3086bb2d52609c7fa1fc513ca9cd0ad7de93a365 Mon Sep 17 00:00:00 2001 From: 94xhn <87560781+94xhn@users.noreply.github.com> Date: Tue, 14 Jul 2026 14:31:32 +0800 Subject: [PATCH] fix: preserve DS18S20 broadcast wait Global resolution also selects the broadcast conversion delay. Keep the requested resolution separate while programming configurable devices so fixed-resolution DS18S20 sensors retain their 750 ms wait. Constraint: DS18S20 is 9-bit but requires up to 750 ms to convert Rejected: Return 9 from getResolution | breaks established conversion timing Confidence: high Scope-risk: narrow Directive: Keep broadcast bitResolution at the slowest device on the bus Tested: WSL GCC 13 ASan/UBSan host bus harness; AVR GCC 7.3 atmega328p -Werror compile Not-tested: Physical mixed DS18S20 and DS18B20 bus --- DallasTemperature.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/DallasTemperature.cpp b/DallasTemperature.cpp index 29b7bc5..25882b2 100644 --- a/DallasTemperature.cpp +++ b/DallasTemperature.cpp @@ -318,12 +318,15 @@ float DallasTemperature::getTempFByIndex(uint8_t index) { } void DallasTemperature::setResolution(uint8_t newResolution) { - bitResolution = constrain(newResolution, 9, 12); + newResolution = constrain(newResolution, 9, 12); + bitResolution = newResolution; DeviceAddress deviceAddress; _wire->reset_search(); for (uint8_t i = 0; i < devices; i++) { if (_wire->search(deviceAddress) && validAddress(deviceAddress)) { - setResolution(deviceAddress, bitResolution, true); + setResolution(deviceAddress, newResolution, true); + // DS18S20 is fixed at 9-bit but needs the 12-bit conversion delay. + if (deviceAddress[0] == DS18S20MODEL) bitResolution = 12; } } } @@ -815,4 +818,4 @@ int16_t DallasTemperature::getUserDataByIndex(uint8_t deviceIndex) { DeviceAddress deviceAddress; getAddress(deviceAddress, deviceIndex); return getUserData((uint8_t*)deviceAddress); -} \ No newline at end of file +}