STM32U5 RTC min and sec count to more than 59
Hi
I am trying to get the RTC to work on the STM32U5 Nucleo board.
But when I read out the time I sometimes get a second and minute value that is more than 59. Any ideas as to how that happens?
I have checked that it is not because I write a higher value to the register.
I use LSI to run the RTC.
My init code
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
if (HAL_RTC_Init(&hrtc) != HAL_OK) {
Error_Handler();
}
struct tm ts;
ts = *localtime(&NewUTCtime);
RTC_TimeTypeDef newTime = { 0 };
RTC_DateTypeDef newDate = { 0 };
newTime.Hours = ts.tm_hour;
newTime.Minutes = ts.tm_min;
newTime.Seconds = ts.tm_sec;
newTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
newTime.StoreOperation = RTC_STOREOPERATION_RESET;
if (HAL_RTC_SetTime(&hrtc, &newTime, RTC_FORMAT_BCD) != HAL_OK) {
Error_Handler();
}
newDate.WeekDay = ts.tm_wday + 1; // 1-7
newDate.Month = ts.tm_mon + 1; // 1-12
newDate.Date = ts.tm_mday; // 1-31
newDate.Year = ts.tm_year - 100; // <99
if (HAL_RTC_SetDate(&hrtc, &newDate, RTC_FORMAT_BCD) != HAL_OK) {
Error_Handler();
}

