From 58b80f6b584de526fee28ce75977d09e88408300 Mon Sep 17 00:00:00 2001 From: Kiveisha Yevgeniy Date: Mon, 4 Aug 2014 12:00:58 +0300 Subject: [PATCH] maxds3231m :: fix to getTemperature method Signed-off-by: Kiveisha Yevgeniy --- src/maxds3231m/maxds3231m.cxx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/maxds3231m/maxds3231m.cxx b/src/maxds3231m/maxds3231m.cxx index b10be55..40af866 100644 --- a/src/maxds3231m/maxds3231m.cxx +++ b/src/maxds3231m/maxds3231m.cxx @@ -86,13 +86,18 @@ MAXDS3231M::getDate (Time3231 &time) { uint16_t MAXDS3231M::getTemperature () { - uint8_t buffer[2]; - uint16_t tempRaw = 0; + uint8_t buffer[2]; + uint8_t msb = 0; + uint8_t lsb = 0; i2cReadReg_N (TEMPERATURE_ADDR, 2, buffer); - tempRaw = (((int16_t)buffer[0]) << 8) | buffer[1]; + msb = buffer[0]; + lsb = buffer[1] >> 6; - return tempRaw; + if ((msb & 0x80) != 0) + msb |= ~((1 << 8) - 1); // if negative get two's complement + + return 0.25 * lsb + msb; } /* -- 2.7.4