cancel
Showing results for 
Search instead for 
Did you mean: 

RTC WakeUp Timer interrupt STM32L100

chiptron
Associate II
Posted on April 15, 2015 at 20:34

Hi, I have a problem with interrupt of WakeUp Timer.

Never set flag for WakeUp interrupt. WakeUp timer is on EXTI EXTI of interrupt is set for rising edge and and line Can you help me? Thanks a lot :) P.S.: and blinking of LED without interrupt is working.

#include <
stddef.h
>
#include <
stdio.h
>
#include ''stm32l1xx.h''
#include ''stm32l1xx_conf.h''
int main (void){
int i;
//----LED----//
RCC->AHBENR |= RCC_AHBENR_GPIOCEN; //Povoleni clocku pro port C
RCC->AHBRSTR |= RCC_AHBRSTR_GPIOCRST; //reset GPIOC
RCC->AHBRSTR &= ~RCC_AHBRSTR_GPIOCRST;
GPIOC->MODER |= GPIO_MODER_MODER9_0 | GPIO_MODER_MODER8_0; 
GPIOC->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR9 | GPIO_OSPEEDER_OSPEEDR8;
GPIOC->ODR &= ~GPIO_ODR_ODR_9 | GPIO_ODR_ODR_8;
//---EXTI-for WakeUp timer-20--// 
EXTI->IMR |= EXTI_IMR_MR20; //Line 20 - WakeUp timer
EXTI->EMR &= ~EXTI_EMR_MR20;
EXTI->RTSR |= EXTI_RTSR_TR20; //Rising edge
EXTI->FTSR &= ~EXTI_FTSR_TR20;
NVIC->ISER[0] |= (1 << (RTC_WKUP_IRQn & 0x1F));
//---RTC---//
RCC->APB1ENR |= RCC_APB1ENR_PWREN; //enable PWR
RCC->APB1RSTR |= RCC_APB1RSTR_PWRRST;
RCC->APB1RSTR &= ~RCC_APB1RSTR_PWRRST;
PWR->CR |= PWR_CR_DBP;
//---LSE----//
RCC->CSR |= RCC_CSR_LSEON; //LSE on
while(!(RCC->CSR & RCC_CSR_LSERDY)); //wait for LSERDY 
RCC->CSR |= RCC_CSR_RTCSEL_0; //LSE clock source
RCC->CSR |= RCC_CSR_RTCEN; //enable
//---RTC---//
RTC->WPR = 0xCA; //key
RTC->WPR = 0x53; //key
RTC->CR &=~ RTC_CR_WUTE; //disable WakeUp Timer
while(!(RTC->ISR & RTC_ISR_WUTWF)); //wait for WUTWF
RTC->WUTR = 0x1FF;
RTC->CR |= RTC_CR_WUCKSEL_0; //RTCCLK/8
RTC->CR |= RTC_CR_WUTIE; //enable interrupt
RTC->CR |= RTC_CR_WUTE; //enable WakeUp Timer
RTC->WPR = 0xFF; //key
while(1){
for(i=0;i<
0xAFFF0
; i++);
GPIOC->ODR ^= GPIO_ODR_ODR_8;
}
}
/*---Interrupt by WakeUp Timer---*/
void RTC_WKUP_IRQHandler(void)
{
if(RTC-> ISR & RTC_ISR_WUTF){ 
GPIOC->ODR ^= GPIO_ODR_ODR_9;
RTC->ISR &=(~ RTC_ISR_WUTF);
}
EXTI->PR |= EXTI_PR_PR20; 
return;
}

#wakeup #exti #stm32l100 #worst-forum-software-ever
3 REPLIES 3
chiptron
Associate II
Posted on April 16, 2015 at 15:26

New info. If I load code to the STM32L100, the uP doesn't work. But, If I connect STM32L100 discovery to the USB, the uP works! And when I press reset, the uP doesn't work again ... :\

Posted on April 17, 2015 at 12:17

Ahoj Petus,

I don't know the exact reason why it won't work as you expect - and you failed to describe what do you expect and what do you experience, ''does not work'' does not qualify as a description for that :) - but this is certainly wrong:

RTC->ISR &=(~ RTC_ISR_WUTF);   Hint: rc_w0 and description of RTC_ISR in RM.   Similarly with  EXTI->PR |= EXTI_PR_PR20;    See this as a lesson in ''peripheral registers is NOT memory, think twice before performing a read-modify-write on them''. (Sidenote: using bit-banding is a RMW operation, too, from the peripheral register's viewpoint).   You may also need to unlock the RTC registers in the ISR, if it fires before main succeeds to get at the unlock sequence (this is probably not the case now, but may be in future).    Also, set a pin at the ISR entry and clear it at exit, and observe using oscilloscope/LA.   This one:  GPIOC->ODR &= ~GPIO_ODR_ODR_9 | GPIO_ODR_ODR_8;   may not be what you wanted, too.   Report back with your findings.   wek 

chiptron
Associate II
Posted on April 18, 2015 at 00:27

It works :)

''In addition, the RTC keeps on running under system reset if the reset source is different

from the power-on reset one. When a power-on reset occurs, the RTC is stopped and all the

RTC registers are set to their reset values.''

If the RTC is running, then is set interrupt flag, negation of LED and start of RTC timer again. This is function of my code.

And solution of my problem. If the RTC is running and I press reset button (at this time settings of flag), this flag isn't clear beacause in my code isn't line for clearing of this flag. 

How to do?

Enable PWREN, and DBP of PWR_CR register and next, clear WUTF:

RTC->ISR &= ~RTC_ISR_WUTF;

and that's all :)

Thanks a lot mr. wek :)