2025-06-22 10:08 AM
Hello Community!
I have an issue with reading / writing the RTC in an H723 MCU.
The issue is:
I can set the Clock to a date, but when I read out the RTC, then the year is 10 years in the future.
e.g. I set the time to now (2025 / 06 / 22 19:mm:ss) and I read out the RTC after that, i get the corret day of month, month, hour, minute and second but the yearis 2035 (or better: 35 instead of 25, because the year in the Date Typedef is an u8 integer). This is my code:
RTC_DateTypeDef d;
RTC_TimeTypeDef t;
d.Year = (uint8_t)(hDateTime->dt.year - 2000);
d.Month = hDateTime->dt.month;
d.Date = hDateTime->dt.day;
t.Hours = hDateTime->tm.hour;
t.Minutes = hDateTime->tm.min;
t.Seconds = hDateTime->tm.sec;
if(hDateTime->tm.dst) {
t.DayLightSaving = RTC_DAYLIGHTSAVING_ADD1H;
} else {
t.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
}
uint8_t retval = 0;
if(HAL_OK != (HAL_RTC_SetTime(&hrtc, &t, RTC_FORMAT_BIN))) retval |= 2;
if(HAL_OK != (HAL_RTC_SetDate(&hrtc, &d, RTC_FORMAT_BIN))) retval |= 1;
if(HAL_OK != (HAL_RTC_GetDate(&hrtc, &d, RTC_FORMAT_BIN))) retval |= 4;
if(HAL_OK != (HAL_RTC_GetTime(&hrtc, &t, RTC_FORMAT_BIN))) retval |= 8;
Has anyone an idea, what's going wrong here? IMHO this is pretty straight forward and I don't know where the 10 years come from. I send the year information to this function as e.g. 2025, I subtract 2000 to make an u8 from it and push that into the RTC. Why does it add 10 years?
Thanks and cheers!