cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L151C8T6 RTC wakeup not counting

Olivier FAURAX
Associate II
Posted on June 08, 2018 at 15:25

Hello,

I try to have a periodic wakeup of my chip.

I read the RTC documentation, and I tried to setup the RTC periodic wakeup unit.

I managed to get a periodic interruption but I don't understand why the counter is not changing.

void RTC_WKUP_IRQHandler(void)

{

  printf('IT RTC %u\n', RTC_GetWakeUpCounter());

  if(RTC_GetITStatus(RTC_IT_WUT) != RESET)

  {

    RTC_ClearITPendingBit(RTC_IT_WUT);

    EXTI_ClearITPendingBit(EXTI_Line20);

  }

}

I always get 'IT RTC 65535', everytime the handler is called (once every second in my case).

Here is my initiliazing code :

    // RTC periodic wakeup

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

    PWR_RTCAccessCmd(ENABLE);

    RCC_RTCResetCmd(ENABLE);

    RCC_RTCResetCmd(DISABLE);

    //MSG('wait HSE');

    RCC_HSEConfig(RCC_HSE_ON);

    while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET) {}

    RCC_RTCCLKConfig(RCC_RTCCLKSource_HSE_Div8);

    RCC_RTCCLKCmd(ENABLE);

    //MSG('wait synchro');

    RTC_WaitForSynchro();

    

    EXTI_InitTypeDef  EXTI_InitStructure;

    EXTI_ClearITPendingBit(EXTI_Line20);

    EXTI_InitStructure.EXTI_Line = EXTI_Line20;

    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;

    EXTI_InitStructure.EXTI_LineCmd = ENABLE;

    EXTI_Init(&EXTI_InitStructure);

    

    NVIC_InitTypeDef  NVIC_InitStructure;

    NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    

    RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div16);

    RTC_SetWakeUpCounter(0xFFFF);

    

    RTC_ITConfig(RTC_IT_WUT, ENABLE);

    RTC_WakeUpCmd(ENABLE);

You can see the 0xFFFF used to initialize the counter (only once).

I tried to change it : I saw the new value in the interrupt printf, and the call to the interrupt changed also.

So the value is used to know when to trigger the interrupt, even if the value doesn't change

What am I missing so that the RTC wakeup counter correctly decrements?

Or am I missing the point, and the value does not decrement at all?

#stm32l1-rtc #stm32-rtc #rtc
0 REPLIES 0