cancel
Showing results for 
Search instead for 
Did you mean: 

Alarm interrup doesn't work

jampino
Associate II
Posted on June 22, 2016 at 17:29

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

3 REPLIES 3
slimen
Senior
Posted on June 22, 2016 at 19:26

Hi,

I recommend you start with RTC_Alarm example under the

/content/my_st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef2.license=1466615123html

cube firmware package:STM32Cube_FW_F2_V1.3.0\Projects\STM322xG_EVAL\Examples\RTC\RTC_Alarm

This application example guides you through the different configuration steps by mean of HAL APIto ensure Alarm configuration and generation using the RTC peripheral.

You find the needed for your project under this application which can help you as an implementation example and get inspiration to achieve you goal.

Regards

jampino
Associate II
Posted on June 27, 2016 at 11:54

Hello forumstm32,

thanks for your answer.

I have a STM3220G-Eval board, I've tried that example but it doesn't work I am not sure what can be the problem.

I am trying to set up the alarm and wake up from stop mode when the alarm occurs but nothing happen.

Thanks

jampino
Associate II
Posted on June 28, 2016 at 11:51

Hello,

Finally I have managed to make ''work'' the alarm, I have set a fix time and date and then set the alarm with a different time to wake up 10 secs after going to sleep.

It seems to work fine first time  but when I wake up form stop mode and configure again the time and alarm, it never wakes up again.

It looks like is always waiting for an interruption alarm but it never happens and does not leave the stop mode.

I have try to clear the flags when wake up first time but without differences.

Any suggestion?

Thanks