×

Common RTC (Real-Time Clock) Issues with STM32F091RCT6

seekdd seekdd Posted in2025-04-28 05:08:41 Views11 Comments0

Take the sofaComment

Common RTC (Real-Time Clock ) Issues with STM32F091RCT6

Common RTC (Real-Time Clock) Issues with STM32F091RCT6 and Solutions

The STM32F091RCT6 microcontroller, part of the STM32 family, is widely used for embedded systems due to its versatile features, including the Real-Time Clock (RTC) module . However, there are common issues that users may face when working with the RTC. Here, we will explore these issues, their causes, and provide clear, step-by-step solutions to resolve them.

1. RTC Not Running After Power -Up

Cause: The RTC may not start functioning after powering up the system due to incorrect initialization or improper configuration of the RTC clock source.

Solution:

Step 1: Ensure that the RTC clock source is properly configured. The STM32F091RCT6 RTC can use different clock sources such as the LSE (Low-Speed External) or LSI (Low-Speed Internal) oscillator. You should configure the clock source correctly in the SystemClock_Config() function.

Step 2: If you are using the LSE, check whether the crystal oscillator is properly connected and functioning. If using the LSI, verify that the internal oscillator is enabled and stable.

Step 3: Initialize the RTC with the correct configuration. This typically involves enabling the RTC peripheral, setting the prescaler, and enabling the RTC interrupt if needed.

Example initialization code:

// Enable the LSE oscillator RCC->BDCR |= RCC_BDCR_LSEON; // Wait for LSE to be ready while(!(RCC->BDCR & RCC_BDCR_LSERDY)); // Configure the RTC to use LSE as the clock source RCC->APB1ENR |= RCC_APB1ENR_RTCEN; RTC->CRL &= ~RTC_CRL_RSF; RTC->CRL |= RTC_CRL_CNF; // Set prescaler, etc. RTC->PRER = 0x7F00F; // Example prescaler value RTC->CRL &= ~RTC_CRL_CNF; 2. RTC Losing Time

Cause: If the RTC is losing time, it could be due to several reasons such as:

Incorrect prescaler settings.

Insufficient power supply for the RTC (when the system goes into low-power modes).

A faulty or unconnected backup battery.

Solution:

Step 1: Verify the prescaler settings. The prescaler defines how fast the RTC increments, and it must be correctly set based on the clock source.

Step 2: Check the backup battery. Ensure the battery is installed and functional. If the STM32F091RCT6 is not connected to a backup battery, the RTC will lose time when power is removed.

Step 3: If your application goes into low-power mode (like Stop or Standby), make sure that the RTC can still run during these modes. You might need to enable the RTC Wakeup feature to allow the RTC to continue running during low-power states.

Example of checking the backup battery power:

if (!(PWR->CSR & PWR_CSR_BRE)) { // Backup battery not available or powered off } 3. RTC Alarm Not Triggering

Cause: The RTC alarm may not trigger due to:

Incorrect alarm configuration.

The alarm interrupt not being enabled.

A mismatch between the alarm time and the actual RTC time.

Solution:

Step 1: Verify the alarm configuration. Make sure the alarm is set to the correct time (in the correct format) and that it matches the RTC time.

Step 2: Ensure that the alarm interrupt is enabled in the interrupt vector table and NVIC. Additionally, check that the alarm mask is not set (i.e., no unwanted masking of the alarm).

Step 3: Ensure that the RTC time has been correctly set before configuring the alarm. If the RTC time is not set correctly, the alarm might never match the time.

Example of enabling the alarm interrupt:

// Enable the alarm interrupt NVIC_EnableIRQ(RTC_Alarm_IRQn); RTC->CRH |= RTC_CRH_ALRIE; // Enable the alarm interrupt in RTC 4. RTC Stopping During Low-Power Modes

Cause: If the RTC stops during low-power modes (like Stop or Standby mode), it is usually because the RTC is disabled or no backup power is available.

Solution:

Step 1: If you are using Stop mode, ensure that the RTC is still enabled to run during low-power modes. This can be done by setting the RTC to run in Stop mode using the PWR_CR_LPDS bit.

Step 2: If Standby mode is used, ensure that you have configured the RTC Wakeup to allow the RTC to run during this mode.

Step 3: Ensure the backup domain is powered by the battery or a capacitor when the main power supply is off.

Example configuration for running RTC during Stop mode:

// Enable RTC to continue running in Stop mode PWR->CR |= PWR_CR_LPDS; // Low power deep sleep 5. RTC Interrupt Not Working

Cause: If the RTC interrupt is not triggering, the issue could be due to:

Incorrect interrupt configuration.

The interrupt priority or vector table not being set correctly.

Missing flags or the interrupt not being properly cleared.

Solution:

Step 1: Ensure that the interrupt is enabled in both the RTC peripheral and the NVIC. You should also check the interrupt flags and ensure they are not masked.

Step 2: Check that the RTC interrupt handler is correctly implemented and that the interrupt is cleared in the handler (e.g., by clearing the interrupt flag).

Step 3: Set the interrupt priority to ensure the RTC interrupt is handled correctly.

Example of interrupt handler:

void RTC_Alarm_IRQHandler(void) { if (RTC->CRL & RTC_CRL_AL RF ) { RTC->CRL &= ~RTC_CRL_ALRF; // Clear alarm interrupt flag // Handle the alarm } }

Conclusion

When working with the RTC module in the STM32F091RCT6, common issues typically arise from configuration errors, improper initialization, power issues, or interrupt misconfigurations. By carefully following the steps outlined above, you can address and resolve these issues, ensuring your RTC functions correctly in your embedded system.

seekdd

Anonymous