Skip to main content
JKing.8
Associate II
Jan 10, 2023 5:06 PM UTC
Question

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

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

This topic has been closed for replies.

6 replies

waclawek.jan
Super User
Jan 10, 2023 10:04 PM UTC

> 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

JKing.8
JKing.8Author
Associate II
Jan 11, 2023 2:53 PM UTC

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
JKing.8Author
Associate II
Jan 12, 2023 6:44 PM UTC

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
Principal III
Jan 12, 2023 8:45 PM UTC

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

JKing.8
JKing.8Author
Associate II
Jan 13, 2023 2:27 PM UTC

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

waclawek.jan
Super User
Jan 14, 2023 9:10 AM UTC

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

JW