embedded runtime_error ai_generated true

RTC: alarm interrupt not triggering at configured time

ID: embedded/rtc-alarm-interrupt-not-triggering

Also available as: JSON · Markdown · 中文
85%Fix Rate
85%Confidence
1Evidence
2024-02-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
STM32Cube_FW_H7 V1.11.0 active — — —
FreeRTOS V10.4.1 active — — —

Root Cause

RTC alarm interrupt failed to fire due to incorrect mask configuration or pending interrupt flag not cleared.

generic

中文

RTC 闹钟中断因掩码配置错误或未清除挂起中断标志而未触发。

Official Documentation

https://www.st.com/resource/en/reference_manual/dm00314099.pdf

Workarounds

  1. 90% success Check and clear RTC_ISR_ALRAF flag in RTC_ISR register before setting alarm, then enable alarm interrupt in RTC_CR: `RTC->CR |= RTC_CR_ALRAIE;`
    Check and clear RTC_ISR_ALRAF flag in RTC_ISR register before setting alarm, then enable alarm interrupt in RTC_CR: `RTC->CR |= RTC_CR_ALRAIE;`
  2. 85% success Ensure RTC alarm mask bits (ALRAE, ALRABIN) in RTC_CR are set correctly for desired alarm mode.
    Ensure RTC alarm mask bits (ALRAE, ALRABIN) in RTC_CR are set correctly for desired alarm mode.
  3. 95% success Use HAL_RTC_AlarmIRQHandler() which automatically clears pending flags and re-enables interrupt.
    Use HAL_RTC_AlarmIRQHandler() which automatically clears pending flags and re-enables interrupt.

中文步骤

  1. 在设置闹钟前检查并清除 RTC_ISR 中的 RTC_ISR_ALRAF 标志,然后在 RTC_CR 中使能闹钟中断:`RTC->CR |= RTC_CR_ALRAIE;`
  2. 确保 RTC_CR 中的闹钟掩码位(ALRAE、ALRABIN)正确配置为所需闹钟模式。
  3. 使用 HAL_RTC_AlarmIRQHandler() 函数,它会自动清除挂起标志并重新使能中断。

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Increasing RTC clock prescaler changes alarm timing but does not fix interrupt configuration.

  2. 80% fail

    Reinitializing RTC peripheral resets all registers, losing alarm settings.

  3. 70% fail

    Adding delay loops after alarm set does not address missing interrupt enable.