cancel
Showing results for 
Search instead for 
Did you mean: 

"PROPER" way to read RTC time?

StephanMair
Senior

Hi, I'm using STM32L431xx series mcus and I want to perform a read on the RTC time.

Normally I would do that with a simple read operation on registers, specifically, the RTC_TR and RTC_DR register, but I am afraid that's not how things were supposed to be done.

So my questionS are:

  1. Is there any HAL lib function that I can use? If so I clearly should use them
  2. If I want to read directly from registers, which (shadow/cache) register should I read from?

Thanks in advance.

2 REPLIES 2

> I am afraid that's not how things were supposed to be done.

That's how things are supposed to be done. Reading those registers, in that order. Read the RTC chapter in RM and the Errata to your chip.

JW

TDK
Guru

You can use HAL_RTC_GetTime/HAL_RTC_GetDate.

They just read the registers, though, plus some conversion into a potentially "user-friendly" data structure.

https://github.com/STMicroelectronics/STM32CubeL4/blob/master/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rtc.c#L895

If you feel a post has answered your question, please click "Accept as Solution".