Skip to main content
Linda
Associate III
March 5, 2015
Question

Can not make two alarms work in STM32F429i_Disco

  • March 5, 2015
  • 5 replies
  • 949 views
Posted on March 05, 2015 at 14:52

Dear Sir/Miss,

I need 2 alarms, I only can get one alarm work thought Canlandar module, but if make code for alarm A and B, none of them works. Here is my code:

**********

RTC_TimeTypeDef   RTC_TimeStructure;

RTC_AlarmTypeDef  RTC_AlarmStructure;

RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);

sec    =  RTC_TimeStructure.RTC_Seconds;

min    =  RTC_TimeStructure.RTC_Minutes;

hour   =  RTC_TimeStructure.RTC_Hours;

    

            Alarm_Init();

            /*  Alarm A */

            RTC_GetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);

            RTC_AlarmCmd(RTC_Alarm_A, DISABLE);

            /* Disable the RTC Alarm A Interrupt */

            RTC_ITConfig(RTC_IT_ALRA, DISABLE);

            RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = (sec+0X01);

            RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = (min+0X01);

            RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = (hour+0X00);

            RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;

            RTC_AlarmStructure.RTC_AlarmDateWeekDay = day;

            RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);

            /* Enable the RTC Alarm A Interrupt */

            RTC_ITConfig(RTC_IT_ALRA, ENABLE);

            /* Enable the alarm  A */

            RTC_AlarmCmd(RTC_Alarm_A, ENABLE);

            /*  Alarm B */

            RTC_GetAlarm(RTC_Format_BIN, RTC_Alarm_B, &RTC_AlarmStructure);

            RTC_AlarmCmd(RTC_Alarm_B, DISABLE);

            /* Disable the RTC Alarm B Interrupt */

            RTC_ITConfig(RTC_IT_ALRB, DISABLE);

            RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = (sec+0X01);

            RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = (min+0X00);

            RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = (hour+0X00);

            RTC_AlarmStructure.RTC_AlarmDateWeekDaySel =    RTC_AlarmDateWeekDaySel_Date;

            RTC_AlarmStructure.RTC_AlarmDateWeekDay = day;

            RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_B, &RTC_AlarmStructure);

            /* Enable the RTC Alarm B Interrupt */

            RTC_ITConfig(RTC_IT_ALRB, ENABLE);

            /* Enable the alarm  B */

            RTC_AlarmCmd(RTC_Alarm_B, ENABLE);

*****************

void RTC_Alarm_IRQHandler(void)

{

  /* Clear the EXTIL line 17 */

  EXTI_ClearITPendingBit(EXTI_Line17);

  /* Check on the AlarmA falg and on the number of interrupts per Second (60*8) */

  if (RTC_GetITStatus(RTC_IT_ALRA) != RESET)

  {

//    STM_EVAL_LEDOn(LED4);

    alarm_now2 = 0;

    /* Clear RTC AlarmA Flags */

    RTC_ClearITPendingBit(RTC_IT_ALRA);

    RTC_HandlerFlag = ENABLE;

  }

    if (RTC_GetITStatus(RTC_IT_ALRB) != RESET)

  {

//    STM_EVAL_LEDOn(LED4);

     alarm_now = 0;

    /* Clear RTC AlarmA Flags */

    RTC_ClearITPendingBit(RTC_IT_ALRB);

    RTC_HandlerFlag = ENABLE;

  }

}

~~~~~~~~~~~~~~~~~~~~~~

Please help

Thanks

    This topic has been closed for replies.

    5 replies

    Tesla DeLorean
    Guru
    March 5, 2015
    Posted on March 05, 2015 at 19:06

    Would suggest you advance it more than a second, and also roll the seconds/minutes/hours properly.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    Linda
    LindaAuthor
    Associate III
    March 5, 2015
    Posted on March 05, 2015 at 22:15

    I change  

    ~~~~~~~~~~~~         

    RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = (sec+0X01);

    RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = (min+0X00);

    to:

                RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = (sec+0X01);

                RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = (min+0X02);

    ~~~~~~~~~~~~~~~~~~~~~

    Still both of alarm A and Alarm B do not work.

    tm3341
    Associate III
    March 5, 2015
    Posted on March 05, 2015 at 23:02

    Check on link below, maybe it will be helpful to you.

    http://stm32f4-discovery.com/2014/07/library-19-use-internal-rtc-on-stm32f4xx-devices/

    Tesla DeLorean
    Guru
    March 5, 2015
    Posted on March 05, 2015 at 23:11

    Please try to make a complete, free standing example.

    In your system review the peripheral/register states to understand what might be going on.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    Tesla DeLorean
    Guru
    March 6, 2015
    Posted on March 06, 2015 at 05:36

    I have this and it works for me..

    /**************************************************************************/
    void AlarmTest(void)
    {
    RTC_TimeTypeDef RTC_TimeStructure;
    RTC_AlarmTypeDef RTC_AlarmStructure;
    int sec, min, hour;
    int secA, minA, hourA;
    int secB, minB, hourB;
    AlarmInit(); // Initialize NVIC and EXTI
    /* Wait for RTC APB registers synchronisation - Defensive in case your code's broken */
    RTC_WaitForSynchro();
    /* Get Current Time */
    RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
    printf(''Current %02d:%02d:%02d
    '',
    RTC_TimeStructure.RTC_Hours,
    RTC_TimeStructure.RTC_Minutes,
    RTC_TimeStructure.RTC_Seconds);
    sec = RTC_TimeStructure.RTC_Seconds;
    min = RTC_TimeStructure.RTC_Minutes;
    hour = RTC_TimeStructure.RTC_Hours;
    /* ALARM A */
    secA = sec + 1; // At +00:01:01
    minA = min + 1;
    hourA = hour;
    if (secA >= 60) // Rollover
    {
    secA -= 60;
    minA++;
    }
    if (minA >= 60)
    {
    minA -= 60;
    hourA++;
    }
    if (hourA >= 24)
    {
    hourA -= 24;
    }
    printf(''Alarm A %02d:%02d:%02d
    '', hourA, minA, secA);
    /* Get Current Alarm A */
    RTC_GetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);
    /* Disable the Alarm A */
    RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
    /* Disable the RTC Alarm A Interrupt */
    RTC_ITConfig(RTC_IT_ALRA, DISABLE);
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = secA;
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = minA;
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = hourA;
    RTC_AlarmStructure.RTC_AlarmDateWeekDay = 31; // Ignored
    RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
    RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay;
    RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);
    /* Enable the RTC Alarm A Interrupt */
    RTC_ITConfig(RTC_IT_ALRA, ENABLE);
    /* Enable the alarm A */
    RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
    RTC_ClearFlag(RTC_FLAG_ALRAF);
    /* ALARM B */
    secB = sec + 1; // At +00:02:01
    minB = min + 2;
    hourB = hour;
    if (secB >= 60) // Rollover
    {
    secB -= 60;
    minB++;
    }
    if (minB >= 60)
    {
    minB -= 60;
    hourB++;
    }
    if (hourB >= 24)
    {
    hourB -= 24;
    }
    printf(''Alarm B %02d:%02d:%02d
    '', hourB, minB, secB);
    /* Get Current Alarm B */
    RTC_GetAlarm(RTC_Format_BIN, RTC_Alarm_B, &RTC_AlarmStructure);
    /* Disable the Alarm B */
    RTC_AlarmCmd(RTC_Alarm_B, DISABLE);
    /* Disable the RTC Alarm B Interrupt */
    RTC_ITConfig(RTC_IT_ALRB, DISABLE);
    RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_H12_AM;
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = secB;
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = minB;
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = hourB;
    RTC_AlarmStructure.RTC_AlarmDateWeekDay = 31; // Ignored
    RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
    RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay;
    RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_B, &RTC_AlarmStructure);
    /* Enable the RTC Alarm B Interrupt */
    RTC_ITConfig(RTC_IT_ALRB, ENABLE);
    /* Enable the Alarm B */
    RTC_AlarmCmd(RTC_Alarm_B, ENABLE);
    RTC_ClearFlag(RTC_FLAG_ALRBF);
    }
    /**************************************************************************/
    void RTC_Alarm_IRQHandler(void)
    {
    /* Check on the AlarmA flag */
    if (RTC_GetITStatus(RTC_IT_ALRA) != RESET)
    {
    /* Clear RTC AlarmA Flags */
    RTC_ClearITPendingBit(RTC_IT_ALRA);
    /* Clear the EXTI line 17 */
    EXTI_ClearITPendingBit(EXTI_Line17);
    puts(''AlarmA Hit'');
    }
    /* Check on the AlarmB flag */
    if (RTC_GetITStatus(RTC_IT_ALRB) != RESET)
    {
    /* Clear RTC AlarmB Flags */
    RTC_ClearITPendingBit(RTC_IT_ALRB);
    /* Clear the EXTI line 17 */
    EXTI_ClearITPendingBit(EXTI_Line17);
    puts(''AlarmB Hit'');
    }
    }
    /**************************************************************************/

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..