Skip to main content
michelemancini2
Associate III
October 19, 2012
Question

STM32F0 rtc alarm 1 day

  • October 19, 2012
  • 8 replies
  • 2308 views
Posted on October 19, 2012 at 10:39

Hi, How can I setting rtc to put alarm every 1 day , for all day? Is possible

(I need to wake up stm32f0 every 16:00 pm all day , execute routine and do sleep and wait

the next day

)
    This topic has been closed for replies.

    8 replies

    Tesla DeLorean
    Guru
    October 19, 2012
    Posted on October 19, 2012 at 16:48

    Something like

    /* Disable the Alarm A */

    RTC_AlarmCmd(RTC_Alarm_A, DISABLE);

    /* Set the alarm to 4PM (16:00) daily*/

    RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_H12_PM;

    RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = 0x04;

    RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = 0x00;

    RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = 0x00;

    RTC_AlarmStructure.RTC_AlarmDateWeekDay = 0x31; // Nonspecific

    RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;

    RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_Hours | RTC_AlarmMask_Minutes | RTC_AlarmMask_Seconds; // HH:MM:SS match 

    RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);

    /* Enable RTC Alarm A Interrupt: this Interrupt will wake-up the system from

    STANDBY mode (RTC Alarm IT not enabled in NVIC) */

    RTC_ITConfig(RTC_IT_ALRA, ENABLE);

    /* Enable the Alarm A */

    RTC_AlarmCmd(RTC_Alarm_A, ENABLE);

    /* Clear RTC Alarm Flag */

    RTC_ClearFlag(RTC_FLAG_ALRAF);

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    crt2
    Visitor II
    October 22, 2012
    Posted on October 22, 2012 at 11:08

    Just be aware of oscillator accuracy - if it is possible check frequency with oscilloscope to set Prescaler to more accurate setting because 1% in 24 hours (86400 seconds) might come up to 846 seconds (which is almost 15 minutes) delay - really really fine tuning of capacitors should be considered!

    Tesla DeLorean
    Guru
    October 22, 2012
    Posted on October 22, 2012 at 17:18

    Just be aware of oscillator accuracy - if it is possible check frequency with oscilloscope to set Prescaler to more accurate setting because 1% in 24 hours (86400 seconds) might come up to 846 seconds (which is almost 15 minutes) delay - really really fine tuning of capacitors should be considered!

     

    Most 32.768 KHz crystals are in the PPM range, 20 PPM being 0.002%, less than 2 seconds. If you're losing/gaining 15 minutes a day you've got bigger part selection problems than a couple of capacitors.

    STM32 parts have classically only used LSE to run the RTC when the part is shutdown as it uses far less power than the LSI RC oscillator.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    crt2
    Visitor II
    October 23, 2012
    Posted on October 23, 2012 at 09:55

    I have measured my crystal (i dont have Discovery board btw) with scope and it showed 32.7659 Hz and even if I take the last number as ''mistake'' of scope, then its 2 Hz off what it is suppose to be. Without correction to Prescaler that meant quite nice mistake over longer periods of time (and I have interrupt routine cleared and am printing time in main loop). Without going to assembler I do not think I could optimise my program more, so I cant really say where else would I loose time (i make interrupts every second).

    zzdz2
    Associate
    October 23, 2012
    Posted on October 23, 2012 at 12:43

    What's the problem then.

    If I'm not mistaken 2Hz is about 5s/day -- not bad, you can finetune it with prescaler under 0.5Hz or 1.3sec/day.

    crt2
    Visitor II
    October 23, 2012
    Posted on October 23, 2012 at 15:22

    Then only my maths is wrong...

    Tesla DeLorean
    Guru
    October 23, 2012
    Posted on October 23, 2012 at 15:40

    You want to measure the LSE indirectly, sticking a scope probe on it changes the loading. Other STM32 family parts connect an internal copy to one of the timer inputs.

    On the F0 RTCCLK can be routed to TIM14 CH1, as can the MCO pin, which can be configured to output LSI, LSE, etc.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    arif10808
    Visitor II
    February 22, 2016
    Posted on February 22, 2016 at 20:29

    Hi,

    I am trying to configure rtc alarm which will generate alarm on 23:00:00(hh:mm:ss) everyday.

    here is my code,

     *------------------------------------------------------------------------------*/

    void RTC_IRQHandler(void)

    {

        if(RTC->ISR & RTC_ISR_ALRAF){

            GPIOA-> ODR |= (1 << 1);

        }

        RTC->ISR &= ~(1<<8);

    }

    void RTCAlrmConfig(){

        RTC->WPR = 0xCA;

        RTC->WPR = 0x53;

        RTC->CR &=~ RTC_CR_ALRAE;             //Disable alarm interrupt

        while ((RTC->ISR & RTC_ISR_ALRAWF) != RTC_ISR_ALRAWF)

        {}

        RTC->ALRMAR =0x00230000;    //Set alarm hour=23 and make sec min and day dont care

        RTC->ALRMAR |=RTC_ALRMAR_MSK1 | RTC_ALRMAR_MSK2 | RTC_ALRMAR_MSK3 | RTC_ALRMAR_MSK4;

        RTC->ALRMASSR=RTC_ALRMASSR_MASKSS_0 |RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3;

        RTC->CR = RTC_CR_ALRAE |RTC_CR_ALRAIE;

        NVIC_EnableIRQ(RTC_IRQn);

        NVIC_SetPriority(RTC_IRQn,3);

        RTC->WPR = 0xFE;

        RTC->WPR = 0x64;

    }

    but with this configuration I am not able to generate rtc alarm, please suggest what is wrong in this code.

    Scott Dev
    Senior
    August 9, 2017
    Posted on August 09, 2017 at 15:20

    Hi Mulani

      I am having the same issue, did you get your code working? If so can you please pass it on?

    Many Thanks

    Scott