Skip to content

RTC_DS3231.cpp getTemperature() doesn't provide for negative temps #287

@Fishbone69

Description

@Fishbone69

I believe as written, the DS3231 method for getting the temperature does not look at the MSB of the high byte to determine if the temperature is positive or negative. I would recommend something like this for the update:

float RTC_DS3231::getTemperature() {
uint8_t buffer[2] = {DS3231_TEMPERATUREREG, 0};
float temperatureDegC;
i2c_dev->write_then_read(buffer, 1, buffer, 2);
temperatureDegC = (float)buffer[0] + (float)(buffer[1] >> 6) * 0.25f;
if (buffer[0] & 0x80) {
temperatureDegC *= -1.0f;
}
return temperatureDegC;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions