Skip to main content
SSone.1
Associate II
May 13, 2020
Solved

STM32F4 RTC Wake-up Timer

  • May 13, 2020
  • 1 reply
  • 965 views

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(); 

}

    This topic has been closed for replies.
    Best answer by SSone.1

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

    1 reply

    SSone.1
    SSone.1AuthorBest answer
    Associate II
    May 14, 2020

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