Skip to content

Commit c2dc48e

Browse files
authored
ds18b20 detection for uninitialized power-on state (BSP-788) (#733)
* ds18b20 detection for uninitialized power-on state * formatting * bump version of ds18b20
1 parent 061f8d6 commit c2dc48e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

components/ds18b20/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "0.2.0"
1+
version: "0.3.0"
22
description: DS18B20 device driver
33
url: https://github.com/espressif/esp-bsp/tree/master/components/ds18b20
44
dependencies:

components/ds18b20/src/ds18b20.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ esp_err_t ds18b20_get_temperature(ds18b20_device_handle_t ds18b20, float *ret_te
181181
ESP_RETURN_ON_FALSE(onewire_crc8(0, (uint8_t *)&scratchpad, 8) == scratchpad.crc_value, ESP_ERR_INVALID_CRC, TAG,
182182
"scratchpad crc error");
183183

184+
// detect uninitialized power-on state
185+
// https://github.com/cpetrich/counterfeit_DS18B20#solution-to-the-85-c-problem
186+
if (scratchpad._reserved2 == 0x0c && scratchpad.temp_msb == 0x05 && scratchpad.temp_lsb == 0x50) {
187+
ESP_LOGW(TAG, "read power-on value (85.0)");
188+
return ESP_ERR_INVALID_STATE;
189+
}
190+
184191
const uint8_t lsb_mask[4] = {0x07, 0x03, 0x01, 0x00}; // mask bits not used in low resolution
185192
uint8_t lsb_masked = scratchpad.temp_lsb & (~lsb_mask[scratchpad.configuration >> 5]);
186193
// Combine the MSB and masked LSB into a signed 16-bit integer

0 commit comments

Comments
 (0)