Skip to main content
Visitor II
January 10, 2023
Question

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

  • January 10, 2023
  • 4 replies
  • 2007 views

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.

    4 replies

    Super User
    January 10, 2023

    > 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.8Author
    Visitor II
    January 11, 2023

    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.8Author
    Visitor II
    January 12, 2023

    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.

    Graduate II
    January 12, 2023

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

    JKing.8Author
    Visitor II
    January 13, 2023

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

    Super User
    January 14, 2023

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

    JW