Skip to content

Commit 4839194

Browse files
committedJan 21, 2025
fix: Restored DS18S20 support
1 parent 3cfcb26 commit 4839194

4 files changed

+38
-3
lines changed
 

‎DallasTemperature.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ extern "C" {
3636

3737
#define NO_ALARM_HANDLER ((AlarmHandler *)0)
3838

39+
// DSROM FIELDS
40+
#define DSROM_FAMILY 0
41+
#define DSROM_CRC 7
42+
3943
DallasTemperature::DallasTemperature() {
4044
_wire = nullptr;
4145
devices = 0;
@@ -554,6 +558,37 @@ int32_t DallasTemperature::calculateTemperature(const uint8_t* deviceAddress, ui
554558
| neg;
555559
}
556560

561+
/*
562+
DS1820 and DS18S20 have a 9-bit temperature register.
563+
564+
Resolutions greater than 9-bit can be calculated using the data from
565+
the temperature, and COUNT REMAIN and COUNT PER °C registers in the
566+
scratchpad. The resolution of the calculation depends on the model.
567+
568+
While the COUNT PER °C register is hard-wired to 16 (10h) in a
569+
DS18S20, it changes with temperature in DS1820.
570+
571+
After reading the scratchpad, the TEMP_READ value is obtained by
572+
truncating the 0.5°C bit (bit 0) from the temperature data. The
573+
extended resolution temperature can then be calculated using the
574+
following equation:
575+
576+
COUNT_PER_C - COUNT_REMAIN
577+
TEMPERATURE = TEMP_READ - 0.25 + --------------------------
578+
COUNT_PER_C
579+
580+
Hagai Shatz simplified this to integer arithmetic for a 12 bits
581+
value for a DS18S20, and James Cameron added legacy DS1820 support.
582+
583+
See - http://myarduinotoy.blogspot.co.uk/2013/02/12bit-result-from-ds18s20.html
584+
*/
585+
586+
if ((deviceAddress[DSROM_FAMILY] == DS18S20MODEL) && (scratchPad[COUNT_PER_C] != 0)) {
587+
fpTemperature = (((fpTemperature & 0xfff0) << 3) - 32
588+
+ (((scratchPad[COUNT_PER_C] - scratchPad[COUNT_REMAIN]) << 7)
589+
/ scratchPad[COUNT_PER_C])) | neg;
590+
}
591+
557592
return fpTemperature;
558593
}
559594

‎DallasTemperature.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef DallasTemperature_h
22
#define DallasTemperature_h
33

4-
#define DALLASTEMPLIBVERSION "4.0.1"
4+
#define DALLASTEMPLIBVERSION "4.0.2"
55

66
// Configuration
77
#ifndef REQUIRESNEW

‎library.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
{
3333
"paulstoffregen/OneWire": "^2.3.5"
3434
},
35-
"version": "4.0.1",
35+
"version": "4.0.2",
3636
"frameworks": "arduino",
3737
"platforms": "*"
3838
}

‎library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=DallasTemperature
2-
version=4.0.1
2+
version=4.0.2
33
author=Miles Burton <mail@milesburton.com>, Tim Newsome <nuisance@casualhacker.net>, Guil Barros <gfbarros@bappos.com>, Rob Tillaart <rob.tillaart@gmail.com>
44
maintainer=Miles Burton <mail@milesburton.com>
55
sentence=Arduino library for Dallas/Maxim temperature ICs

0 commit comments

Comments
 (0)
Please sign in to comment.