2018-04-27 06:47 AM
The RTC continues to count after 23:59:59, just changes the day at 39:59:59, what's the problem?
I use HAL Library.
RTC Output:
2018-04-06 weak5, 23:59:57
2018-04-06 weak5, 23:59:582018-04-06 weak5, 23:59:592018-04-06 weak5, 24:00:002018-04-06 weak5, 24:00:012018-04-06 weak5, 24:00:022018-04-06 weak5, 24:00:032018-04-06 weak5, 24:00:042018-04-28 05:27 AM
Thanks to everyone, the solution is to change the location of this line in RTC Init
if (HAL_RTCEx_BKUPRead (& hrtc, RTC_BKP_DR0)! = 0x32F2) {
maybe some bug um STMCubeMX32
see function
/* RTC init function */
static void MX_RTC_Init(void){RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;/**Initialize RTC Only
*/ 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.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; if (HAL_RTC_Init(&hrtc) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Initialize RTC and set the Time and Date */ if(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR0) != 0x32F2){ sTime.Hours = 0x0; sTime.Minutes = 0x0; sTime.Seconds = 0x0; sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; sTime.StoreOperation = RTC_STOREOPERATION_RESET; if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); }sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_JANUARY; sDate.Date = 0x1; sDate.Year = 0x0;if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
{ _Error_Handler(__FILE__, __LINE__); }HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR0,0x32F2);
}}
2018-04-28 11:54 AM
'
maybe some bug um STMCubeMX32'
understatement of the century,
that's the irony of a buggy library: it hurts the most people it is designed to help. If you were to simply write out your own code, you would have figured this out in a couple hours, not days.
2018-04-29 01:39 AM
the solution is to change the location of this line in RTC Init
if (HAL_RTCEx_BKUPRead (& hrtc, RTC_BKP_DR0)! = 0x32F2) {
Certainly not.
As long as the clock is running, i.e. battery is connected to VBAT, the RTC retains its settings and there's no need to reinitialize it upon reset. Contrary, by reinitialization you may disturb the clock (see numerous
https://community.st.com/0D50X00009XkgBWSAZ
in this very forum on subseconds being reset, thus losing up to 1 second upon each reset).I am not going to comment on the quality of examples nor Cube. Read the RTC chapter in RM and write your own code.
JW
2018-04-29 01:57 AM
Hi, Thank you for the advice.