cancel
Showing results for 
Search instead for 
Did you mean: 

RTC Losing time after power restart

KBhon.1
Associate III

Hello all,

I am working on RTC of STM32F401RC. I have connected a new CR2032 battery to VBAT.

My problem is that when I restart the power I lose time. I have disabled the calendar generation and setting time manually so there is no possibility of time reset due to SW. Apart from that, I also tried to set the backup register and read it after power restart, the backup register also resets to 0.

To make sure I also tried on other MCU STM32F407, and it still has the same issue. The RTC circuit for both F401 and F407 boards is the same and are populated on my custom designed boards.

In order to make sure the battery is not the issue, I used a new different battery, and also tried powering VBAT using 3.3V derived from different board and still the time gets reset.

Here is the schematic of my RTC circuit.

KBhon1_0-1697944232160.png

 

Main Code:

KBhon1_2-1697944416432.png

 

Here is my RTC init function:


static void MX_RTC_Init(void)
{

/* USER CODE BEGIN RTC_Init 0 */

/* USER CODE END RTC_Init 0 */

RTC_TimeTypeDef sTime = {0};
RTC_DateTypeDef sDate = {0};

/* USER CODE BEGIN RTC_Init 1 */

/* USER CODE END RTC_Init 1 */

/** Initialize RTC Only
*/
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}

/* USER CODE BEGIN Check_RTC_BKUP */

/* USER CODE END Check_RTC_BKUP */

/* USER CODE BEGIN RTC_Init 2 */

/* USER CODE END RTC_Init 2 */

}

 

 

Please help me with this. I am kind of stuck and must solve this problem.

 

15 REPLIES 15

VDDA/VREF+ is connected exactly how?

JW

KBhon.1
Associate III

@waclawek.jan Thanks for the reply.

 

VDDA/VREF+ are connected together and are powered by using a separate LDO power supply. This is done to keep analog and digital voltages separate. Also, I would like to mention that VSSA/VREF- are connected together and are shorted to digital Gnd using a choke. This is done to keep analog and digital Gnds on separate sides (but still connected using choke).

Here is how the supplies are:

The please note in the image below VSSA/VREF- are on separate GND node and the choke L3 is used to connect both the digital and analog Gnds.

KBhon1_0-1697977093867.png

 

TDK
Guru

> I also tried to set the backup register and read it after power restart, the backup register also resets to 0.

Suggests this isn't purely an RTC issue, but a hardware issue.

I would suggest connecting VDDA/VDD directly per the datasheet recommendation as well as VSSA/VSS. You could also try out your code on known good hardware such as a nucleo board.

Note that VDD and VDDA must be within 300 mV of each other during power-up. Do you ensure that?

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

@TDK Thanks for the insight.

However we have followed ST app note AN2834 to design analog circuitry. On page 42, 43 it clearly suggests to keep analog and digital supplies separate and to connect analog and digital Gnds at one single point as we did using choke.

Here is the link for app note (Page 42,43)

https://www.st.com/resource/en/application_note/an2834-how-to-optimize-the-adc-accuracy-in-the-stm32-mcus-stmicroelectronics.pdf

 

Here I have attached its screenshots

KBhon1_0-1697982312022.png

KBhon1_1-1697982353610.png

 

I can remove choke on GND line and short them directly, however in our another test board there is no such choke but still it gives the same RTC problem. I really do not want to merge VDDA and VDD, since keeping them separately has impacted hugely on our analog reading section.

I understand. For the purposes of debugging, if powering them from a single rail fixes the problem, you now know what the issue is.

Other series of chips are more forgiving on separating VDD/VDDA, but mind the ±300mV requirement during startup/shutdown on the F4. Going to be hard or impossible to guarantee that with truly independent supplies.

TDK_1-1697983804210.png

 

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

Thanks for the response.
I find this really very strange to recommend analog and digital supplies together in datasheet and then mention in the app note to keep them separate. If we had to keep them together then why even provide separate pins for them.

Obviously using separate supplies have worked great on analog readings. But, I have designed 3 separate boards with this approach to get better analog readings and on all 3 boards the RTC backup functionality is very unreliable.

I will try your suggestion and see if it solves the issues and update here.
If it does solve then either I will have to get a external RTC module or try to figure out something in the same design.

I understand it is very unlikely to keep the 300mV difference at the startup with separate supplies. Any suggestions on what else can be the option to somehow use RTC feature with separate supplies?

Thanks!

first: try connecting vdd+vdda ; if this solves the problem, you could

1. try bridging vdd-vdda with 2 antiparallel schottky diodes

2. bridge vdd-vdda with a (low impedance) P-mosfet, gate with pulldown on a cpu-pin; after startup, switch pin hi ; mosfet off then. 

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

@KBhon.1 wrote:

I find this really very strange to recommend analog and digital supplies together in datasheet and then mention in the app note to keep them separate. If we had to keep them together then why even provide separate pins for them.


Keep in mind the app note is for all STM32's, and there's quite a few. They all have different requirements.

VDDA/VDD have separate pins because they can be easily decoupled with a ferrite bead to improve accuracy. Separating VSSA/VSS also allows for the star-network ground setup.


I understand it is very unlikely to keep the 300mV difference at the startup with separate supplies. Any suggestions on what else can be the option to somehow use RTC feature with separate supplies?


Perhaps put Schottky diodes between VDD -> VDDA and VDDA -> VDD and use regulators that don't mind being backpowered.

Good luck!

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

@TDK @AScha.3 

Thanks both of you for your valuable insights.

 

@AScha.3 

To confirm I get you correctly, Is this how you want me to test your 2nd option?

KBhon1_0-1697986603946.png

In this, I am considering

1. VDD and VDDA are still getting power from separate sources.

2. Keep mosfet pulled down at first and then give high to disconnect both the supplies.