cancel
Showing results for 
Search instead for 
Did you mean: 

How does it come the RTC shows a time like 33:27 left alone over night?

friedrich.janus
Associate II

STM32F446 RTC

I seem to have a problem with this part of the MCU.

I am using the HAL to retrieve date and time.

Yesterday evening I set the time (about 22h something).

Time was displayed correctly.

Today in the morning I have a time of 33h27 retreived by HAL_RTC_GetTime.

Looking into the RTC registers that is exactly the value that comes from the RTC.

And it keeps counting like this.

Time is correct if you would subtract 24hrs.

Calender was not updated (no day rollover).

Any idea how that would happen that the RTC registers will not wrap around the 24hrs mark?

And Yes, I do a HAL_RTC_GetDate after reading the time =)

rgds

2 REPLIES 2

Normally I would say that this is result of setting RTC_CR.FMT=1 for 12-hour format, but I see that you have RTC_CR.FMT = 0.

OTOH, the content of RTC_CR is highly unusual and I am not familiar with the combination of coarse-calibration (which is an obsolete feature) and reference clock detection enable; and the manual warns against this combination in the reference clock detection subchapter. Is this an intended value? Have you filled in all init-struct fields when setting up the RTC?

JW

friedrich.janus
Associate II

Hello to all.

To answer waclawek first:

No. it is NOT intendend and all structure members were filled in correctly.

The system was set and then left alone with no further update coming from extern. So I can be sure that nothing set this value.

BUT:

There was one little loophole when setting time and date:

IF the date was already correct I did check the time and set it then. And guess what: There the additional HAL_RTC_GetDate was missing when gettingb the time. According to the testing performed the very day I assume that I ran into this SW path and provoked this.

Summary:

If you ever encounter such a behaviour that the day does not wrap around or your time is beyond 24h check you usage of HAL_RTC_GetTime and HAL_RTC_GetDate.

And I strongly recommend to update the HAL with a HAL_RTC_Get_Time_Date to avoid future accidental errors.

Problem considered solved.