Skip to main content
Associate
June 22, 2026
Solved

RTC hours keep counting after 24 hours

  • June 22, 2026
  • 6 replies
  • 94 views

Hello,

I am using a STM32G474 and the RTC is counting >24.
I have setup the RTC with the STM32CubeMX.

 

regards Mark,

Best answer by waclawek.jan

Most probably the usual case of inadvertently set AM/PM mode, and that usually happens through using uninitialized structs when setting time.

JW

6 replies

mƎALLEm
ST Technical Moderator
June 22, 2026

Hello ​@MdeJong and welcome to the ST community,

You need to provide more details: your code and your ioc file so others could help you efficiently.

Good luck.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Andrew Neil
Super User
June 22, 2026

Welcome to the forum

As ​@mƎALLEm said, you need to give more details - Please see How to write your question to maximize your chances to find a solution.

 

But first, check your initialisations - see:

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
waclawek.jan
waclawek.janBest answer
Super User
June 22, 2026

Most probably the usual case of inadvertently set AM/PM mode, and that usually happens through using uninitialized structs when setting time.

JW

MdeJongAuthor
Associate
June 25, 2026

Hello,

many thanks, that gave me the right direction to look for.

regards Mark,

ST Technical Moderator
June 22, 2026
In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om
MdeJongAuthor
Associate
June 25, 2026

Hello,

I have found the cause.

 

in the function HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc):

When the INITS bit in the ICSR register is set, then the CR register is not initialized.

 

This means that when the year is != 0 the register CR will not be set, also not the FMT bit, 

So you can not switch between 12 and 24 hours mode when the year is != 0.

 

Regards Mark,