Closed rtek1000 closed 4 years ago
//Read the temperature value from the register and convert it into float (deg C) float Sodaq_DS3231::getTemperature() { float fTemperatureCelsius; uint8_t tUBYTE = readRegister(DS3231_TMP_UP_REG); //Two's complement form uint8_t tLRBYTE = readRegister(DS3231_TMP_LOW_REG); //Fractional part
if(tUBYTE & 0b10000000) //check if -ve number
{
tUBYTE ^= 0b11111111;
tUBYTE += 0x1;
fTemperatureCelsius = tUBYTE + ((tLRBYTE >> 6) * 0.25);
fTemperatureCelsius = fTemperatureCelsius * -1;
}
else
{
fTemperatureCelsius = tUBYTE + ((tLRBYTE >> 6) * 0.25);
}
return (fTemperatureCelsius);
}
https://github.com/SodaqMoja/Sodaq_DS3231/blob/master/src/Sodaq_DS3231.cpp
Please see: https://github.com/JChristensen/DS3232RTC
https://github.com/rodan/ds3231