cancel
Showing results for 
Search instead for 
Did you mean: 

RTC hours keep counting after 24 hours

Ppeyr.1
Associate II

Hi,

I use RTC on a STM32L073. Every 12hours, I receive a date and time to set to the RTC. (Sometime, like 1% of the time) After writen the new RTC value, the RTC doesn't overflow after 23h59min59sec and keep counting without incrementing day. I can have: 02/08/22 and 29h49min52sec. The incrementation timing is correct, it's just the overflow.

For information, when I set a new RTC value, I use in that order:

HAL_RTC_DeInit

HAL_RTC_SetTime

HAL_RTC_SetDate

HAL_RTC_Init

The handler doesn't change.

Someone has an idea ? What can do this ?

edit after questions:

the handler for init is:

    handler.Instance = RTC;
    handler.Init.HourFormat = RTC_HOURFORMAT_24;
    handler.Init.AsynchPrediv = 124;
    handler.Init.SynchPrediv = (38000 / 295) - 1U;
    handler.Init.OutPut = RTC_OUTPUT_DISABLE;
    handler.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
    handler.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

I tried both BCD and binary, There is the same issue

5 REPLIES 5

Using BCD rather than binary mode perhaps?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Ppeyr.1
Associate II

I tried both, BCD or binary, both has the same issue

> After writen the new RTC value, the RTC doesn't overflow after 23h59min59sec and keep counting without incrementing day.

That's because you've set hours above 12 and (inadvertently) the 12h (AM/PM) mode. You've set it because you've used a struct which did not have all fields initialized.

JW

Ppeyr.1
Associate II

The handler is initialized with 24hours mode. I never erase it, It's a global var and I never go to standby mode, so the handler doesn't change during the run.

    handler.Instance = RTC;
    handler.Init.HourFormat = RTC_HOURFORMAT_24;
    handler.Init.AsynchPrediv = 124;
    handler.Init.SynchPrediv = (38000 / 295) - 1U;
    handler.Init.OutPut = RTC_OUTPUT_DISABLE;
    handler.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
    handler.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

Is it a better way to change the RTC value "on the fly", instead of DeInit/Init each time ?

Are you sure that struct is global, static and - most importantly - is automatically zeroed upon startup?

And the RTC_TimeTypeDef type struct you use to update the time, is it global static, or local, and has all its elements initialized?

If this is not the reason, observe the content of the RTC_TR.PM bit using debugger, or output it by some suitable way.

> Is it a better way to change the RTC value "on the fly", instead of DeInit/Init each time ?

Probably. I don't know what Deinit/Init does exactly, and I also don't care, I don't use Cube. Generally, unless your application is OK with what could be clicked in CubeMX, it is better not to use Cube at all and read the RM.

JW