File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -134,11 +134,12 @@ float RTC_RV3032::getTemperature() {
134134 uint8_t buffer[2 ] = {RV3032_TEMPERATURE, 0 };
135135 i2c_dev->write_then_read (buffer, 1 , buffer, 2 );
136136 // Whereas the DS3232 is MSB-first, the RV3032 is LSB-first.
137- // Also the fractional part is 4 bits instead of 2. Otherwise it's basically the same.
138- // First we convert the full 12 bits into a signed integer, then multiply by 0.0625 to get
139- // a signed float of the number of degrees.
140- int16_t signedVal = ((int8_t )buffer[1 ] << 4 ) + (buffer[0 ] >> 4 );
141- return signedVal * 0.0625 ;
137+ // The fractional part is 4 bits instead of 2, but that doesn't matter for this method.
138+ // What does matter is the remaining 4 bits are used for flags, so unlike the DS* they
139+ // are not guaranteed to be zero, and must be explicitly ignored.
140+ // Otherwise it's broadly the same, so we use a similar method to https://github.com/adafruit/RTClib/pull/303
141+ int16_t temp = uint16_t (buffer[1 ]) << 8 | (buffer[0 ] & 0xf0 );
142+ return temp * (1 / 256.0 );
142143}
143144
144145/* *************************************************************************/
You can’t perform that action at this time.
0 commit comments