Skip to main content
Visitor II
June 16, 2024
Solved

RTC LSE not working on power off with Vbat

  • June 16, 2024
  • 7 replies
  • 2613 views

I'm using the stm23F103C8 and I would use the RTC internal cloak/calendar. The program is working fine and I have used the LSE osc (32KHz..) as clock source. I have connected a 3V battery to the VBAT pin. My problem is that the switching off the main supply (3.3V) the LSE and RTC stops (vrified with scope).

Attached the main.c.

Can you help me??

    This topic has been closed for replies.
    Best answer by Techn

    Since the seconds register is 32 bits, it takes a long time to overflow, so if the rtc works in battery mode till the overflow condition, the calendar data will be accurate. If you go through the rtc.c file you will get to know how the

    backup domain is used to get it done smoothly.

    Please check the link to get an idea.. RTC_F103/Core/Src/rtc.c at master · lamik/RTC_F103 · GitHub

    I have done programming of RTC for this processor, I used STM32cubeMX  tool to set the parameters. 

    please refer to the HAL and LL documentation as follows
    35.2.3
    WARNING: Drivers Restrictions
    RTC version used on STM32F1 families is version V1. All the features supported by V2
    (other families) will be not supported on F1.
    As on V2, main RTC features are managed by HW. But on F1, date feature is completely
    managed by SW.
    Then, there are some restrictions compared to other families:
    Only format 24 hours supported in HAL (format 12 hours not supported)
    Date is saved in SRAM. Then, when MCU is in STOP or STANDBY mode, date will be
    lost. User should implement a way to save date before entering in low power mode
    (an example is provided with firmware package based on backup registers)
    Date is automatically updated each time a HAL_RTC_GetTime or HAL_RTC_GetDate
    is called.
    Alarm detection is limited to 1 day. It will expire only 1 time (no alarm repetition, need
    to program a new alarm)

    7 replies

    Super User
    June 17, 2024

    > My problem is that the switching off the main supply (3.3V) the LSE and RTC stops

    How do you know?

    > (vrified with scope).

    LSE is a low power oscillator and loading it by oscilloscope probe can very likely stop it.

    JW

    OldSTManAuthor
    Visitor II
    June 17, 2024

    Yes I know but anyway at power on the RTC is running but starts from 00:00:00.

    I programmed the device with the complete init of RTC. The RTC starts with the correct initialized time.

    After that I removed the time/date init from te RTC_init, reprogrammed the device, and the RTC is running with the programmed time and increment correctly.

    I see it from the UART. Now removing the main power, Vbat connected to 3V battery, and repowering the RTC is running but starts from 00:00:00.

    I normally use DS1307 or similar external RTC, now I would use the internal resource..

    Thanks in advance for any help

    Super User
    June 17, 2024

    > at power on the RTC is running but starts from 00:00:00

    If you'd have problem with LSE not oscillating, while the time would not advance, it also would not reset.

    So you either don't have properly connected VBAT or any of the VDD/VDDA/GND pins,  or you perform a backup-domain reset (see RCC_BDCR.BDRST - maybe some "library" which you are using performs this for you) upon startup.

    Or maybe you just incorrectly read out the RTC after reset, see Reading RTC registers subchapter of RTC chapter in RM.

    JW

    Graduate II
    June 18, 2024

    Is rtc set time is disabled? Does it set as per the values? After initially setting   you have to disable it. 

    OldSTManAuthor
    Visitor II
    June 18, 2024

    All VSS_x/VSSA are tied together.  RTC set routines are commented.

    I'll check for the backup-domain management. It's possible to have a simple example?

    OldSTManAuthor
    Visitor II
    March 27, 2025

    I was not able to have RTC correctly working using STM32F103. The time was increasing every 2 seconds. With Vbat connected the time is kept, but the calendar is lost.

    After a lot of trials i tried to use the STM32F401. With this one the RTC was working fine, the seconds increment every second as espected; with Vbat connected the time and calendar are working and nothing is lost removing the main supply.

    Also the backup registers are working fine with any particular software setup.

    Everything is working also with the STM32F411.

    At this point i have the suspect that the F103 has someting wrong in RTC.(?).

     

    Technical Moderator
    March 27, 2025

    Have you verified that it is a genuine STM32F103C8?

    There are plenty of threads on this topic here in the community, e.g. here, there or there.

    OldSTManAuthor
    Visitor II
    March 28, 2025

    Thanks for the calrifications. Anyway if the calendar has to be saved and is not updating during the power off, it is not very useful. Can you have a suggestion about the time that increments every 2 seconds. I played with the prescaler values but anythig change.

    Thanks.

    TechnAnswer
    Graduate II
    March 28, 2025

    Since the seconds register is 32 bits, it takes a long time to overflow, so if the rtc works in battery mode till the overflow condition, the calendar data will be accurate. If you go through the rtc.c file you will get to know how the

    backup domain is used to get it done smoothly.

    Please check the link to get an idea.. RTC_F103/Core/Src/rtc.c at master · lamik/RTC_F103 · GitHub

    I have done programming of RTC for this processor, I used STM32cubeMX  tool to set the parameters. 

    please refer to the HAL and LL documentation as follows
    35.2.3
    WARNING: Drivers Restrictions
    RTC version used on STM32F1 families is version V1. All the features supported by V2
    (other families) will be not supported on F1.
    As on V2, main RTC features are managed by HW. But on F1, date feature is completely
    managed by SW.
    Then, there are some restrictions compared to other families:
    Only format 24 hours supported in HAL (format 12 hours not supported)
    Date is saved in SRAM. Then, when MCU is in STOP or STANDBY mode, date will be
    lost. User should implement a way to save date before entering in low power mode
    (an example is provided with firmware package based on backup registers)
    Date is automatically updated each time a HAL_RTC_GetTime or HAL_RTC_GetDate
    is called.
    Alarm detection is limited to 1 day. It will expire only 1 time (no alarm repetition, need
    to program a new alarm)