cancel
Showing results for 
Search instead for 
Did you mean: 

How to have the RTC continue to count while powered by VBAT

JKing.8
Associate III

I am using an STM32H753I-EVAL2 and the STM32CubeIDE. I am able to set up the RTC and print out its counting time. I do it on a FreeRTOS thread. I have JP11 configured such that VBAT is connected to the battery.

I set my RTC_TimeTypeDef globally:

RTC_TimeTypeDef sTime = {0};

My task made with FreeRTOS to always get the time and print it:

void StartDefaultTask(void *argument) {
  for(;;) {
	HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN);
	uint16_t milliSec = 1000 - (sTime.SubSeconds * 1000) / sTime.SecondFraction;
	printf("-> Time Value: %.2d:%.2d:%.2d:%.3d\r\n", sTime.Hours, sTime.Minutes, sTime.Seconds, milliSec);
  }
}

When I have JP11 configured such that VBAT is connected to +3.3 V, and I unplug the primary power source and replug it back in, the time resets to 00:00:00:000. Yet when VBAT is connected to the coin battery, the time resumes from the time when it was unplugged.

I want it to continue counting while the battery powers it. What do I need to change?

Thank you,

Jared

6 REPLIES 6

> When I have JP11 configured such that VBAT is connected to +3.3 V, and I unplug the primary power > source and replug it back in, the time resets to 00:00:00:000.

Isn't that the expected behaviour?

> Yet when VBAT is connected to the coin battery, the time resumes from the time when it was unplugged.

Measure voltage of the battery.

JW

Thank you for the response.

> Yes, that is expected behavior. I should have said that, I was trying to add more context.

> The battery is reading 2.77V. It is a 3V battery. Do you reckon that is the issue?

JKing.8
Associate III

After a deep dive into some documentation, I found that I needed the RTC Clock Mux to be set to LSE instead of the default LSI. This has led to its own issues (LSE is never set to ready in SystemClock_Config), but I believe it could help anyone who has a similar issue in the future.

Piranha
Chief II

Typically there is no need to wait for LSE ready in system startup.

Right I agree. Leads me to believe there is a deeper issue with LSE but I am not sure where to look for it.

Do you have a crystal at the LSE pins, and solder bridges/jumpers set accordingly?

JW