cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L475 Setting the RTC to 24 hour mode

PHedl
Associate

I am using a STM32L475 and plan to also use an STM32L451 processor, I am having trouble setting the RTC so that its in 24 hour mode. According to the datasheet setting a 0 to bit 22 of RTC_TR should set it into 24 hour mode but this does not seem to work. I can set the time to 11:59:00 check the 24 hour indicator and it flips from 0 to 1 at 12:00 but it still displays in 12 hour mode. I also have set bit 6 of RTC_CR to 0 without any change. What Am i doing wrong or is there a sample code to configure the rtc that i am not seeing.

Thanks in advance

1 REPLY 1

> According to the datasheet setting a 0 to bit 22 of RTC_TR should set it into 24 hour mode

No, that's a misunderstanding of what was meant by the - not very clear - description.

It's just to say, that that bit in 24-hour mode is to stay 0.

In 12-hour mode, it indicates the current state of AM/PM (or can be set to that state).

> I also have set bit 6 of RTC_CR to 0 without any change.

That should have made the change, so you maybe did not do it properly - the RTC has to be unlocked and in INIT state. Read back the register in debugger to be sure this bit is clear.

You can find some sample code here - most of it deals with the LCD itself, but it should be easy to spot the place where the RTC is initialized (and as RTC_CR.FMT is not set, it stays at its reset value 0). You can change the time being set to something like 23:59:50, and then in debugger observe how it rolls over to 00:00:00 - then you know you've set the 24-hour mode properly.

JW