2019-07-24 05:20 AM
Hi,
What could be possibly wrong to make the RTC hour keep count up above 23 hour. With some boards it works correctly, going to 00 from 23. but some other keep count up 24, 25...
How is that possible? There is any configuration to do that?
2019-07-24 05:44 AM
Did you have a look at RTC->TR. Are there really values above 23 HT and HU?
2019-07-24 06:48 AM
Hi Uwe and thank you for answer,
I need to say yes once I am using the HAL library to read the RTC, and it get the TR value from the RTC instance.
HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format)
{
uint32_t tmpreg;
/* Check the parameters */
assert_param(IS_RTC_FORMAT(Format));
/* Get subseconds structure field from the corresponding register*/
sTime->SubSeconds = (uint32_t)(hrtc->Instance->SSR);
/* Get SecondFraction structure field from the corresponding register field*/
sTime->SecondFraction = (uint32_t)(hrtc->Instance->PRER & RTC_PRER_PREDIV_S);
/* Get the TR register */
tmpreg = (uint32_t)(hrtc->Instance->TR & RTC_TR_RESERVED_MASK);
/* Fill the structure fields with the read parameters */
sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> RTC_TR_HU_Pos);
sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >> RTC_TR_MNU_Pos);
sTime->Seconds = (uint8_t)( tmpreg & (RTC_TR_ST | RTC_TR_SU));
sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> RTC_TR_PM_Pos);
/* Check the input parameters format */
if(Format == RTC_FORMAT_BIN)
{
/* Convert the time structure parameters to Binary format */
sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours);
sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes);
sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds);
}
return HAL_OK;
}
Obs.: Removing the battery and soldering it again, made the bug desapear for now. But honestly, this is not a solution if it happen again with a costumer.
2019-07-24 08:20 AM
"But honestly, this is not a solution if it happen again with a customer."
Perhap you could recognize it is occurring and reset the RTC. Surely a way to do that without removing the battery. Consider a link or switch so you don't need to physically desolder stuff.
Sense the failure state, so next time you can root-cause the issue with an FAE. Perhaps file a support ticket now so you can get feedback or answers from their FAQ.
2019-07-24 11:03 AM
This happens e.g. if you set the 12-hour format and set the hour beyond 12 hours.
On this forum this was reported to happen when using "libraries" and the init struct does not have all fields filled in properly.
When it happens, read out and check the RTC registers' content.
JW
2022-07-15 02:29 AM
I have the same problem.
flow work for me.
RTC_TimeTypeDef sTime;
sTime.TimeFormat =RTC_FORMAT_BIN;
sTime.Hours = Hours;
sTime.Minutes = Min;
sTime.Seconds = Sec;
sTime.DayLightSaving = 0; <----
sTime.StoreOperation = 0; <-----
HAL_RTC_SetTime(hrtc, &sTime, RTC_FORMAT_BIN); //儲存設定值
2022-07-15 03:01 AM
Make sure you set *all* fields of sTime.
JW
2022-07-15 04:55 AM
+1 **THIS**
Failure to properly initialize auto/local variables, which live on the stack with random content, is the cause of a million latent failures. ST code is rife with them, as is the use of globals.
RTC_TimeTypeDef sTime = {0}; // Ensures at least you're starting with a clean and consistent sheet
It also helps the compiler/optimizer as it hints at intent.