Skip to content

Commit 5e44324

Browse files
committed
Use the getTemperature conversion method from adafruit#303 instead
1 parent 120f369 commit 5e44324

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/RTC_DS3232.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,9 @@ void RTC_DS3232::writeSqwPinMode(Ds3232SqwPinMode mode) {
114114
float RTC_DS3232::getTemperature() {
115115
uint8_t buffer[2] = {DS3232_TEMPERATUREREG, 0};
116116
i2c_dev->write_then_read(buffer, 1, buffer, 2);
117-
// First we convert the full 10 bits into a signed integer, then multiply by 0.25 to get
118-
// a signed float of the number of degrees.
119-
int16_t signedVal = ((int8_t)buffer[0] << 2) + (buffer[1] >> 6);
120-
return signedVal * 0.25;
117+
// Fix for negative temperatures https://github.com/adafruit/RTClib/pull/303
118+
int16_t temp = uint16_t(buffer[0]) << 8 | buffer[1];
119+
return temp * (1 / 256.0);
121120
}
122121

123122
/**************************************************************************/

0 commit comments

Comments
 (0)