AnsweredAssumed Answered

Alarm interrup doesn't work

Question asked by jamp on Jun 22, 2016
Latest reply on Jun 28, 2016 by jamp
Hi every one, I am working with stm32f2, I am having problem to wake up from stop mode using the alarm A. Someone can advise me about how to use it. The code I am using is this:

 RTC_InitTypeDef RTC_InitStructure;
    RTC_TimeTypeDef RTC_TimeStruct;
    RTC_AlarmTypeDef RTC_AlarmStructure;
    EXTI_InitTypeDef EXTI_InitStructure;


    __IO uint32_t AsynchPrediv = 0, SynchPrediv = 0;
  
  /* Enable the PWR clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);


  /* Allow access to RTC */
  PWR_BackupAccessCmd(ENABLE);
  
  RCC_LSEConfig(RCC_LSE_ON);


  /* Wait till LSE is ready */  
  while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
  {
  }

  /* Select the RTC Clock Source */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

  SynchPrediv = 0xFF;
  AsynchPrediv = 0x7F;


  /* Enable the RTC Clock */
  RCC_RTCCLKCmd(ENABLE);


  /* Wait for RTC APB registers synchronisation */
  RTC_WaitForSynchro();
  
  /* Configure the RTC data register and RTC prescaler */
  RTC_InitStructure.RTC_AsynchPrediv = SynchPrediv;
  RTC_InitStructure.RTC_SynchPrediv = AsynchPrediv;
  RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_12;
  RTC_Init(&RTC_InitStructure);


  (void)RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct);
    /* Set the alarm to current time + wakeup time*/
    RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_TimeStruct.RTC_H12;
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = RTC_TimeStruct.RTC_Hours;
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = RTC_TimeStruct.RTC_Minutes;
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = RTC_TimeStruct.RTC_Seconds + duration;
    RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_All; // TODO: is this right ?
  
  /* Configure the RTC Alarm A register */
  RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure);
  
  /* Enable RTC Alarm A Interrupt */
  RTC_ITConfig(RTC_IT_ALRA, ENABLE);
  
  /* Enable the alarm */
  RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
  
  RTC_ClearFlag(RTC_FLAG_ALRAF);


  /* EXTI configuration */
  EXTI_ClearITPendingBit(EXTI_Line17);
  EXTI_InitStructure.EXTI_Line = EXTI_Line17;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);


  NVIC_Configuration(RTC_Alarm_IRQn, ENABLE, priority);


  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

 PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
 SYSCLKConfigFromSTOP();



Outcomes