@@ -36,6 +36,10 @@ extern "C" {
36
36
37
37
#define NO_ALARM_HANDLER ((AlarmHandler *)0 )
38
38
39
+ // DSROM FIELDS
40
+ #define DSROM_FAMILY 0
41
+ #define DSROM_CRC 7
42
+
39
43
DallasTemperature::DallasTemperature () {
40
44
_wire = nullptr ;
41
45
devices = 0 ;
@@ -554,6 +558,37 @@ int32_t DallasTemperature::calculateTemperature(const uint8_t* deviceAddress, ui
554
558
| neg;
555
559
}
556
560
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
+
557
592
return fpTemperature;
558
593
}
559
594
0 commit comments