cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 RTC Wake-up Timer

SSone.1
Associate III

I am trying to go in standby and wake up after few seconds repeatedly with using RTC wake-up timer but I am having problem after second sleep. It goes sleep, wakes up and then goes sleep again like I expected but after that point(after second sleep) it never wakes up again. I am too having sleep disorder sometimes but I think it is problem for health forums. Anyway my code is like that:

int main(void)

{

 HAL_Init();

 SystemClock_Config();

uart_init();

led_init();

adc_init();

while(HAL_ADC_Start_IT(&pADC1)!=HAL_OK) {HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_15); HAL_Delay(100);}

HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_15);

HAL_Delay(1000);

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

enter_standby_mode();

 while (1)

 {

 }

}

void enter_standby_mode(void)

{

RCC->APB1ENR |= RCC_APB1ENR_PWREN; //enable PWR

RCC->APB1RSTR |= RCC_APB1RSTR_PWRRST;

RCC->APB1RSTR &= ~RCC_APB1RSTR_PWRRST;

PWR->CR |= PWR_CR_DBP; //Disable backup domain write protection

RCC->CSR |= RCC_CSR_LSION; //LSI on

while(!(RCC->CSR & RCC_CSR_LSIRDY)); //wait for LSIRDY 

RCC->BDCR |= RCC_BDCR_RTCSEL_1; //LSI clock source

RCC->BDCR |= RCC_BDCR_RTCEN; //enable

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 = 0x02EE0;

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

HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_13);

HAL_Delay(100);

HAL_PWR_EnterSTANDBYMode(); 

}

1 ACCEPTED SOLUTION

Accepted Solutions
SSone.1
Associate III

Adding this " RTC->ISR &=~ RTC_ISR_WUTF; " below "RTC->WUTR = 0x02EE0; " sloved my problem. I hope this helps anyone looking for wake-up timer.

View solution in original post

1 REPLY 1
SSone.1
Associate III

Adding this " RTC->ISR &=~ RTC_ISR_WUTF; " below "RTC->WUTR = 0x02EE0; " sloved my problem. I hope this helps anyone looking for wake-up timer.