Skip to content

Commit 5856d19

Browse files
authored
Merge pull request #289 from Laxilef/fix_85c
Detect power on reset and insufficient power for DS18B20
2 parents 4da548a + ffc7de9 commit 5856d19

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

DallasTemperature.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,15 @@ int32_t DallasTemperature::calculateTemperature(const uint8_t* deviceAddress, ui
558558
| neg;
559559
}
560560

561+
// detect POR and insufficient power conditions
562+
if (deviceAddress[DSROM_FAMILY] == DS18B20MODEL) {
563+
if (scratchPad[0] == 0x50 && scratchPad[1] == 0x05 && scratchPad[6] == 0x0C) {
564+
return DEVICE_POWER_ON_RESET_RAW;
565+
} else if (scratchPad[0] == 0xFF && scratchPad[1] == 0x07) {
566+
return DEVICE_INSUFFICIENT_POWER_RAW;
567+
}
568+
}
569+
561570
/*
562571
DS1820 and DS18S20 have a 9-bit temperature register.
563572

DallasTemperature.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@
4646
#define DEVICE_FAULT_SHORTVDD_F -421.599976
4747
#define DEVICE_FAULT_SHORTVDD_RAW -32256
4848

49+
#define DEVICE_POWER_ON_RESET_C -251
50+
#define DEVICE_POWER_ON_RESET_F -419.799988
51+
#define DEVICE_POWER_ON_RESET_RAW -32128
52+
53+
#define DEVICE_INSUFFICIENT_POWER_C -250
54+
#define DEVICE_INSUFFICIENT_POWER_F -418.0
55+
#define DEVICE_INSUFFICIENT_POWER_RAW -32000
56+
4957
// Configuration Constants
5058
#define MAX_CONVERSION_TIMEOUT 750
5159
#define MAX_INITIALIZATION_RETRIES 3

keywords.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,9 @@ DEVICE_FAULT_SHORTGND_RAW LITERAL1
8585
DEVICE_FAULT_SHORTVDD_C LITERAL1
8686
DEVICE_FAULT_SHORTVDD_F LITERAL1
8787
DEVICE_FAULT_SHORTVDD_RAW LITERAL1
88+
DEVICE_POWER_ON_RESET_C LITERAL1
89+
DEVICE_POWER_ON_RESET_F LITERAL1
90+
DEVICE_POWER_ON_RESET_RAW LITERAL1
91+
DEVICE_INSUFFICIENT_POWER_C LITERAL1
92+
DEVICE_INSUFFICIENT_POWER_F LITERAL1
93+
DEVICE_INSUFFICIENT_POWER_RAW LITERAL1

test/unit_test_001.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ unittest(test_error_code) {
4747
assertEqual(DEVICE_FAULT_SHORTVDD_C, -252);
4848
assertEqualFloat(DEVICE_FAULT_SHORTVDD_F, -421.6, 0.1);
4949
assertEqual(DEVICE_FAULT_SHORTVDD_RAW, -32256);
50+
51+
assertEqual(DEVICE_POWER_ON_RESET_C, -251);
52+
assertEqualFloat(DEVICE_POWER_ON_RESET_F, -419.8, 0.1);
53+
assertEqual(DEVICE_POWER_ON_RESET_RAW, -32128);
54+
55+
assertEqual(DEVICE_INSUFFICIENT_POWER_C, -250);
56+
assertEqualFloat(DEVICE_INSUFFICIENT_POWER_F, -418.0, 0.1);
57+
assertEqual(DEVICE_INSUFFICIENT_POWER_RAW, -32000);
5058
}
5159

5260
// Test basic initialization and functionality of the DallasTemperature library

0 commit comments

Comments
 (0)