Skip to main content
FDigi
Associate III
November 5, 2019
Question

Hi, I'm using the MCU STM32l476, and I have a problem with RTC. The RTC works only if the board is turned on. When the board is turned off or it's sent a command to the MCU go to shutdown mode, the RTC is reset to zero values.

  • November 5, 2019
  • 12 replies
  • 2071 views

According to the datasheet, there is shutdown mode with and without RTC, so I believe it's a problem of configuration. Can be some parameter of configuration that is missing? How to configure the shutdown mode with RTC?

Thanks!

This topic has been closed for replies.

12 replies

Piranha
Principal III
November 5, 2019

Which oscillator are you using for RTC? In shutdown mode RTC can work only with LSE, not LSI.

FDigi
FDigiAuthor
Associate III
November 5, 2019

I'm using the LSE oscilator.

waclawek.jan
Super User
November 5, 2019

And what happens with RTC if you reset the board either by pulling the NRST pin down, or in software, i.e. without turning the power off?

JW

Piranha
Principal III
November 5, 2019

Also an idea.. Maybe you are reading RTC incorrectly? RTC has a special procedure for reading and setting date/time values. Looking with a debugger will not show these registers correctly.

FDigi
FDigiAuthor
Associate III
November 6, 2019

For reading I'm using the functions HAL_RTC_GetDate() and HAL_RTC_GetTime(). For setting HAL_RTC_SetDate() and HAL_RTC_SetTime()

waclawek.jan
Super User
November 5, 2019

> Looking with a debugger will not show these registers correctly.

The lock/unlock mechanism with BYPASS=0 may surely be confusing, but should not result in reading 0.

OTOH, reading after startup may indeed return 0, if the synchronization mechanism indicated by RSF bit is not observed. Nevertheless, the proper procedure to read time/date is described clearly in the Reading the calendar subchapter of RTC chapter of RM.

JW

Jack Peacock_2
Associate II
November 6, 2019

Do you have a backup power supply connected to the VBAT pin? One that remains on when you turn off power to the board?

FDigi
FDigiAuthor
Associate III
November 6, 2019

Yes, I have a backup supply connected to VBAT pin.

waclawek.jan
Super User
November 6, 2019

And what happens with RTC if you reset the board either by pulling the NRST pin down, or in software, i.e. without turning the power off?

JW

FDigi
FDigiAuthor
Associate III
November 7, 2019

In this case the RTC is reset to zero too.

waclawek.jan
Super User
November 8, 2019

That means you do something wrong in software then.

I don't use Cube so can't help with that. Maybe I'd set a breakpoint immediately after the reset label, before any "initialization" code is called in the startup, and check in debugger if the RTC is still up and running. Then, step through any of the "clock initialization" or whatever Cube imposes on you to see if there is any backup domain reset or anything similar occuring there.

JW

FDigi
FDigiAuthor
Associate III
November 7, 2019

Are the functions HAL_RTC_SetDate() and HAL_RTC_SetTime() enough to configure the RTC for working in shutdown mode?

Looking into these functions, they do the same steps for initializing and configuring the RTC as doing it step by step, so I think it's missing some parameter of configuration or I have a hardware problem.