2024-06-16 8:47 AM
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??
Solved! Go to Solution.
2025-03-28 3:35 AM
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)
2024-06-17 4:41 AM
> 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
2024-06-17 5:44 AM
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
2024-06-17 6:41 AM - edited 2024-06-17 6:42 AM
> 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
2024-06-18 12:40 AM
Is rtc set time is disabled? Does it set as per the values? After initially setting you have to disable it.
2024-06-18 5:32 AM
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?
2025-03-27 8:57 AM
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.(?).
2025-03-27 11:14 AM
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.
2025-03-27 3:36 PM
There is no calendar registers for f103. Only one count register. Please refer to the rtc api in HAL. You have to manage it. The calendar values needs to be backed up in battery backed up register. On power up or reset, it has to be restored.
2025-03-28 2:27 AM
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.