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-27 08:47 AM
Looks like you have Binary Coded Decimal, when you want Bin.
there's bin2bcd and bcd2bin in the HAL RTC code file. I forget if its in .h or .c, but they are there.
2018-04-27 10:10 AM
Let's think through it logically.
It is definitely not a hardware problem: the same hardware has been used by countless others in countless applications flawlessly.
It is definitely not a software problem either you you seem to trust your code so much that you didn't even think posting it could help others help you. I'm 100 percent with you on that.
So here it is: we have a bug that is not hardware nor software related. Where else could the bug be hiding? In our minds?
2018-04-27 10:44 AM
At this moment I have no idea, you're right follow the code below.
/* Infinite loop */
while (1){
HAL_RTC_GetTime(&hrtc, &stimestructureget, FORMAT_BCD); if(stimestructureget.Seconds!=lastSecond) {HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_9);
HAL_RTC_GetDate(&hrtc, &sdatestructureget, FORMAT_BCD); leng=sprintf(printbuf,'20%02x-%02x-%02x weak%x, %02x:%02x:%02x\n\r',sdatestructureget.Year, sdatestructureget.Month, sdatestructureget.Date,sdatestructureget.WeekDay, stimestructureget.Hours, stimestructureget.Minutes, stimestructureget.Seconds); HAL_UART_Transmit(&huart1,printbuf,leng,10000); lastSecond=stimestructureget.Seconds; }}
/* RTC init function */
static void MX_RTC_Init(void){RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;/**Initialize RTC Only /
hrtc.Instance = RTC; if(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR0) != 0x32F2){ 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
*/ 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-27 10:56 AM
Hi,
I have already switched between Binary and BCD, but I always get the same bug.
Notice that I only have the problem in the Hour, and the day does not change either.
I used this code in the past in STM32F407 and it worked fine.
2018-04-27 12:50 PM
Which STM32 exactly are you using?
Some STM32 only have RTC 'timer handle' that only counter 'the time', it doesn't count days (GetDate is emulated by software).2018-04-27 12:59 PM
Hi,
STM32F405RGT6 I think he has a calendar ... Am I right?
2018-04-27 01:44 PM
Read out the RTC registers and check/post them.
I see that in your init code there's RTC_HOURFORMAT_24 mentioned, but the symptoms are similar to the AM/PM (12-hour) cycle.
JW
2018-04-27 08:42 PM
You are right. I can't see nothing wrong.
2018-04-28 05:16 AM
Hi, You gave me a good idea, I changed the initialization to hrtc.Init.HourFormat = RTC_HOURFORMAT_12;
And in this configuration works :o .... but I preferred the format 24h, I will do some more tests and put here the results.