AnsweredAssumed Answered

STM32L152 RTC periodic wakeup

Question asked by Mat on Nov 5, 2013
Latest reply on Nov 5, 2013 by Mat
Hi all,

I'm quite new with STM32 and I'm trying to set up the RTC module to raise a periodic wake-up interrupt every second (using LSI).

The configuration seems to be working, the interrupt is effectively raised, but the firmware is blocked inside the library function "RTC_GetITStatus" and loops inside it.
The code in that moment is running with Interrupt "priviledges" and the result is that the whole firmware is "bloked".


This is the code I'm using... can anybody tell-me how to unlock the situation?

/**********************************************************************/
void RTC_Config()
{
     NVIC_InitTypeDef NVIC_InitStructure;
     EXTI_InitTypeDef EXTI_InitStructure;     
     
     /* Enable the PWR clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);


  /* Allow access to RTC */
  PWR_RTCAccessCmd(ENABLE);
    
  /* Enable the LSI OSC */ 
  RCC_LSICmd(ENABLE);                    // The RTC Clock may varies due to LSI frequency dispersion


  /* Wait till LSI is ready */  
  while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET);


  /* Select the RTC Clock Source */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
  
     /* Enable the RTC Clock */
  RCC_RTCCLKCmd(ENABLE);


  /* Wait for RTC APB registers synchronisation */
  RTC_WaitForSynchro();
     
     /* EXTI configuration *******************************************************/
  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);
     
     // Configuring RTC_WakeUp interrupt
  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 Wakeup Configuration
     RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_16bits);
     
     // RTC Set WakeUp Counter
     RTC_SetWakeUpCounter(0);
     
     // Enabling RTC_WakeUp interrupt
     RTC_ITConfig(RTC_IT_WUT, ENABLE);
     
     // Disabling Alarm Flags
     RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
     RTC_AlarmCmd(RTC_Alarm_B, DISABLE);
     
     // RTC Enable the Wakeup Function
     RTC_WakeUpCmd(ENABLE);
}

/**********************************************************************/

void RTC_WKUP_IRQHandler(void)
{
     if(RTC_GetITStatus(RTC_IT_WUT) != RESET)
     {
          RTC_ClearITPendingBit(RTC_IT_WUT);
          
          GPIO_ToggleBits(LD4_GPIO_PORT, LD4_PIN);
     }
}

/**********************************************************************/

Thanks a lot!

Outcomes