Skip to content

Commit 12b8904

Browse files
committed
fix milesburton#143 divide by zero
1 parent ed7826b commit 12b8904

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

DallasTemperature.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ int16_t DallasTemperature::calculateTemperature(const uint8_t* deviceAddress,
535535
See - http://myarduinotoy.blogspot.co.uk/2013/02/12bit-result-from-ds18s20.html
536536
*/
537537

538-
if (deviceAddress[0] == DS18S20MODEL) {
538+
if ((deviceAddress[0] == DS18S20MODEL) && (scratchPad[COUNT_PER_C] != 0)) {
539539
fpTemperature = ((fpTemperature & 0xfff0) << 3) - 32
540540
+ (((scratchPad[COUNT_PER_C] - scratchPad[COUNT_REMAIN]) << 7)
541541
/ scratchPad[COUNT_PER_C]);

0 commit comments

Comments
 (0)