AnsweredAssumed Answered

Interrupt on RTC Alarm

Question asked by whiteford.nava on Sep 11, 2012
Latest reply on Sep 13, 2012 by whiteford.nava
Hi guys,

I'm trying to get the RTC alarm to cause an interrupt on an STM32F101 but I'm having issues. The RTC is running but the interrupt doesn't seem to be being triggered.

I'd be very grateful if anyone could help me with the code below. But if there is a simple code sample somewhere that would be very useful. The examples I've found so far, seem to match my code, but are also heavy integrated into larger frameworks.


This is the code I'm using to do the configuration:

typedef struct rtc_reg_map {
    __io uint32 CRH;            /**< Control register high */
    __io uint32 CRL;            /**< Control register low */
    __io uint32 PRLH;           /**< Prescaler load register high */
    __io uint32 PRLL;           /**< Prescaler load register low */
    __io uint32 DIVH;           /**< Prescaler divider register high */
    __io uint32 DIVL;           /**< Prescaler divider register low */
    __io uint32 CNTH;           /**< Counter register high */
    __io uint32 CNTL;           /**< Counter register low */
    __io uint32 ALRH;           /**< Alarm register high */
    __io uint32 ALRL;           /**< Alarm register low */
} rtc_reg_map;

/** RTC register map base pointer */
#define RTC_BASE                       ((struct rtc_reg_map*)0x40002800)

rtc_dev *RTC;
rtc_dev = RTC_BASE;

void rtoff_wait(rtc_dev *dev) {
  dev->regs->CRL &= (uint16)~RTC_CRL_RSF;
  while(!(dev->regs->CRL & RTC_CRL_RTOFF));
}

// configure the alarm
bkp_enable_writes();

rtoff_wait(dev);
for(;((RTC->CRL & RTC_CRL_CNF) == 0);) RTC->CRL |= RTC_CRL_CNF;

rtoff_wait(dev);
RTC->regs->ALRH = (uint16) 0;
rtoff_wait(dev);
RTC->regs->ALRL = (uint16) 10;

rtoff_wait(dev);
RTC->CRL &= ~RTC_CRL_CNF;
rtoff_wait(dev);

bkp_disable_writes();

// enable the interrupt
bkp_enable_writes();
rtoff_wait(dev);
RTC->CRH = 0x3;
rtoff_wait(dev);
bkp_disable_writes();


I then have an interrupt handler in the NVIC table. I've also tried enabling the interrupt in the NVIC ISER, but this doesn't seem to help. In fact when I enable the RTC interrupt the system hangs.

Outcomes