×

STM32F103RET6 RTC Not Working Common Causes and Fixes

blog6 blog6 Posted in2025-04-22 01:54:51 Views4 Comments0

Take the sofaComment

STM32F103RET6 RTC Not Working Common Causes and Fixes

STM32F103 RET6 RTC Not Working: Common Causes and Fixes

When you're working with the STM32F103RET6 microcontroller and the RTC (Real-Time Clock ) is not functioning as expected, it can be frustrating. The RTC in STM32F103RET6 is essential for keeping track of time, even during Power -down events (if configured properly). Several reasons can cause the RTC not to work correctly. Let’s go through the common causes, what leads to these issues, and how to resolve them systematically.

1. Power Supply Issues

Cause: One of the most common issues is insufficient or missing power supply to the RTC. The STM32F103RET6 has a dedicated RTC_VDD pin that provides power to the RTC. If this is not properly powered, the RTC will fail to work.

Solution:

Check the RTC_VDD pin and ensure it is correctly connected to a stable power supply. Typically, this should be connected to a battery or a stable power source that doesn’t go off even when the main system is powered down.

Ensure the VBAT pin is connected to a backup battery if you want the RTC to continue working during power-off.

Tip: The VBAT pin powers the RTC and keeps it running in low-power states. If it is not connected to a battery or a power source, the RTC will stop working as soon as the main power is off.

2. Incorrect Initialization of the RTC

Cause: The RTC might not be initialized properly in the firmware. The STM32F103RET6 RTC needs to be configured in the correct mode before it can work. If the initialization code is wrong or incomplete, the RTC won't function.

Solution:

Verify that the RTC is initialized properly in your code. The basic initialization steps include enabling the RTC clock, setting the prescalers, and configuring the date and time.

Example initialization in the firmware:

// Enable the RTC clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP | RCC_APB1Periph_PWR, ENABLE); PWR_Backup Access Cmd(ENABLE); // Configure the RTC RTC_InitTypeDef RTC_InitStructure; RTC_InitStructure.RTC_AsynchPrediv = RTC_AsynchPrediv_Value; RTC_InitStructure.RTC_SynchPrediv = RTC_SynchPrediv_Value; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; RTC_Init(&RTC_InitStructure);

Make sure you're configuring both the asynchronous and synchronous prescalers based on the desired time precision.

3. LSE Oscillator Not Configured Correctly

Cause: The STM32F103RET6 RTC typically uses the Low-Speed External (LSE) crystal oscillator to keep track of time. If this oscillator is not properly configured or is faulty, the RTC will not work.

Solution:

Ensure that the LSE oscillator is properly connected to the STM32F103RET6. The LSE typically uses a 32.768 kHz crystal. Double-check the circuit and ensure it is correctly placed.

In your code, ensure that the LSE oscillator is enabled:

RCC_LSEConfig(RCC_LSE_ON); while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET); // Wait for LSE to stabilize RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); RCC_RTCCLKCmd(ENABLE);

Tip: If the LSE is not functioning, the RTC can still be powered by the LSI (Low-Speed Internal) oscillator, but it will not have as accurate timing.

4. RTC Backup Domain Reset

Cause: The backup domain (where the RTC settings and data are stored) may be inadvertently reset. This can happen if the backup domain reset is triggered by the IWDG (Independent Watchdog) or some other event.

Solution:

Make sure the backup domain is not being reset unintentionally. You can check whether the RTC and BKP registers are being reset by code or an external event.

If you need to prevent accidental resets, you can disable the backup domain reset:

RCC_BackupResetCmd(DISABLE);

Tip: Sometimes, using the independent watchdog (IWDG) can cause unexpected resets, so check the watchdog configuration as well.

5. RTC Configuration Clashes

Cause: Another possible issue is a configuration clash with other peripherals, particularly the RTC and System Tick Timer (SysTick), which might cause timekeeping issues.

Solution:

Verify that the SysTick timer is not conflicting with the RTC. The SysTick is typically used for time delays and interrupt handling, so make sure it’s not affecting the RTC’s functionality. To avoid this, configure the SysTick and RTC to use different timebases.

6. RTC Calendar/Time Setting Issues

Cause: If the RTC is not correctly setting the calendar or the time, it may appear that the RTC is not working, even though it is functioning correctly in terms of timekeeping.

Solution:

Ensure that the date and time are set correctly in the RTC. If the RTC is not initialized with the correct time, you might see a default or incorrect value.

To set the date and time:

RTC_TimeTypeDef RTC_TimeStructure; RTC_DateTypeDef RTC_DateStructure; RTC_TimeStructure.RTC_Hours = 0; RTC_TimeStructure.RTC_Minutes = 0; RTC_TimeStructure.RTC_Seconds = 0; RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure); RTC_DateStructure.RTC_Year = 2025; RTC_DateStructure.RTC_Month = RTC_Month_March; RTC_DateStructure.RTC_Date = 19; RTC_SetDate(RTC_Format_BIN, &RTC_DateStructure);

Conclusion

In summary, if your STM32F103RET6 RTC is not working, it is likely due to one of the following causes: power supply issues, incorrect initialization, improper oscillator setup, backup domain reset, configuration conflicts, or incorrect time/calendar settings. By systematically checking each of these potential causes and applying the solutions provided, you should be able to get your RTC functioning properly.

Troubleshooting Checklist:

Check RTC_VDD and VBAT for proper power supply. Initialize the RTC correctly in the firmware. Ensure LSE oscillator is configured and operational. Avoid accidental backup domain resets. Verify no conflicts with SysTick or other timers. Ensure the RTC time and date are properly set.

By following these steps, you can resolve most RTC-related issues on the STM32F103RET6 and ensure your timekeeping works flawlessly.

pcbnest.com

Anonymous