cancel
Showing results for 
Search instead for 
Did you mean: 

Why the interrupt is not triggered for RTC wakeup interrupt?

SSaiy.1
Associate III

Hi,

I am new to STM32 controller and I am using STM32L412RBT6. I was doing baremetal programming for RTC wakeup interrupt. But interrupt is not calling. Below mentioning my code.

/* Enable Clock for Power interface.*/

RCC->APB1ENR1 |= (1U<<28);

/*Disable backup domain write protection*/

PWR->CR1 |= (1U<<8);

/*Enable LSE Clock source and wait until LSERDY bit to set*/

RCC->BDCR |= (1U<<0);

while ((RCC->BDCR & (1U<<1)) == 0);

/*Select LSE as RTC Clock*/

RCC->BDCR |= (1U<<8);

RCC->BDCR &= ~(1U<<9);

/*Enable RTC Clock*/

RCC->BDCR |= (1U<<15);

 /* Disable the write protection for RTC registers */

RTC->WPR = 0xCA;

RTC->WPR = 0x53;

/* Check if the Initialization mode is set */

if((RTC->ICSR & (1U<<6))==0)

{

/* Set the Initialization mode */

RTC->ICSR |= (1U<<7);

/* Wait till RTC is in INIT state*/

while((RTC->ICSR & (1U<<6))==0);

}

/* Clear RTC_CR FMT, OSEL, POL and TAMPOE Bits */

RTC->CR &= ~(1U<<6);     //FMT

RTC->CR &= ~(1U<<20); //POL

RTC->CR &= ~(1U<<21); //OSEL

RTC->CR &= ~(1U<<22); //OSEL

RTC->CR &= ~(1U<<26); //TAMPOE

/* Set RTC_CR register */

RTC->CR &= ~(1U<<6);     //FMT bit set as Zero,Hour Format Selected as 24

RTC->CR &= ~(1U<<20); //POL bit set as Zero, Output polarity selected as high.

RTC->CR &= ~(1U<<21); //OSEL[22:21] set as zero, output selection disabled.

RTC->CR &= ~(1U<<22);

/* Configure the RTC PRER */

RTC->PRER |= 0xFF; // Synchronus value set as 255

RTC->PRER |= (0x7F<<16);   // Asynchronus value set as 127.

/* Exit Initialization mode */

RTC->ICSR &= ~(1U<<7); // Clear INIT bit.

/*Set Output type as open drain pullup*/

RTC->CR |= (1U<<30);

/*Disable the Wakeup Timer*/

RTC->CR &= ~(1U<<10);

/*In case of interrupt mode is used, the interrupt source must disabled*/

RTC->CR &= ~(1U<<14);

/* Wait till RTC WUTWF flag is set and if Time out is reached exit */

while ((RTC->ICSR & (1U<<2)) == 0);

/* Clear WUTE in RTC_CR to disable the wakeup timer */

RTC->CR &= ~(1U<<10);

/* Clear flag Wake-Up */

RTC->SCR |= (1U<<2);

/* Poll WUTWF until it is set in RTC_ICSR to make sure the access to wakeup autoreload

   counter and to WUCKSEL[2:0] bits is allowed. */

while((RTC->ICSR & (1U<<2))==0);

/* Configure the Wakeup Timer counter and auto clear value */

RTC->WUTR |= (RTC_WAKEUP_TIME_IN_SECONDS-1);

RTC->WUTR |= (WakeUpAutoClr<<16);

  /* Configure the clock source */

RTC->CR &= ~(1U<<0);

RTC->CR &= ~(1U<<1);

RTC->CR |= (1U<<2);

/* RTC WakeUpTimer EXTI Configuration: Interrupt configuration */

EXTI->IMR1 |= (1U<<20);

EXTI->RTSR1 |= (1U<<20);

/* Configure the Interrupt in the RTC_CR register */

RTC->CR |= (1U<<14);

/* Enable the Wakeup Timer */

RTC->CR |= (1U<<10);

/* Enable the write protection for RTC registers */

RTC->WPR = 0xFF;

NVIC_EnableIRQ(RTC_WKUP_IRQn);

void RTC_WKUP_IRQHandler(void)

{

EXTI->PR1 |= (1U<<20);

if((RTC->MISR & (1U<<2))!=0)

{

RTC->SCR |= (1U<<2);

count++ ;

}

}

1 REPLY 1
SSaiy.1
Associate III

Hi Guys,

If anyone got the idea whats gone wrong, please share your suggestion. Since not much baremetal examples available for this I got stuck with this.

Thanks.