cancel
Showing results for 
Search instead for 
Did you mean: 

alarm interrupt missing (sporadic)

bruzzim
Associate II
Posted on January 11, 2011 at 12:48

alarm interrupt missing (sporadic)

15 REPLIES 15
Posted on May 17, 2011 at 14:21

Unless I'm missing something, you are not advancing the RTC Alarm time beyond the current value of time.

You're not incrementing it, and you're masking it with some unknown value.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
bruzzim
Associate II
Posted on May 17, 2011 at 14:21

actually what I do is to set the alarm to the current RTC counter value.

 I see that is the only way to have alarms with 1 second period. If I set alarm to RTC+1 I see alarms every 2 seconds. RTCAlarm_IRQHandler set its new alarm for next second, Do I miss anything?

Posted on May 17, 2011 at 14:21

What is your RTC clocking at (prescaling permits it to be other than 1 second)? What are you masking it with (RTC_LSB_Mask)?

Edit: Never mind, it's a cut'n'paste from the library.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
bruzzim
Associate II
Posted on May 17, 2011 at 14:21

I start from your last question: RTC_LSB_Mask is defined into stm32f10x_rtc.c stm stlib file:

#define RTC_LSB_Mask     ((uint32_t)0x0000FFFF)  /*!< RTC LSB Mask */

void RTC_SetCounter(uint32_t CounterValue)

Back to the problem:

the RTC is set to 1 second tick: (attached the whole rtc.c file) as you can see below.

I realized this (interesting to me): if in my RTCAlarm_IRQHandler(void) i have (as I do now):

      RTC_WaitForSynchro();

      SoftRtc_SetAlarm(SoftRtc_Get());

then I have alarm every 1 second. If I remove the RTC_WaitForSynchro(); then I need to change the following to

SoftRtc_SetAlarm(SoftRtc_Get()+1);

My question is: do I need to issue RTC_WaitForSynchro() every time I quit the stop mode or can I remove from everywhere (exceptint the first configuration)?

Thanks and best regards,

Manfredo

void RTC_Configuration(void)

{

  /* Enable PWR and BKP clocks */

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

 

  /* Allow access to BKP Domain */

  PWR_BackupAccessCmd(ENABLE);

  /* Reset Backup Domain */

  //BKP_DeInit();

  /* Enable LSE */

  RCC_LSEConfig(RCC_LSE_ON);

  /* Wait till LSE is ready */

  while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)

    {

    }

  /* Select LSE as RTC Clock Source */

  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); 

  // save rtc counter

//  MainSeconds = SoftRtc_Get();

  /* Enable RTC Clock */

  RCC_RTCCLKCmd(ENABLE);

 

  // restore rtc counter

//  SoftRtc_Set(MainSeconds);

  /* Wait for RTC registers synchronization */

  RTC_WaitForSynchro();

  /* Wait until last write operation on RTC registers has finished */

  RTC_WaitForLastTask();

  /* Wait until last write operation on RTC registers has finished */

  RTC_WaitForLastTask();

 

  /* Set RTC prescaler: set RTC period to 1sec */

  RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */

 

  /* Wait until last write operation on RTC registers has finished */

  RTC_WaitForLastTask();

 }

bruzzim
Associate II
Posted on May 17, 2011 at 14:21

For some reason my answer is over your message; to avoid the risk you miss it I post this 🙂

damh
Associate II
Posted on May 17, 2011 at 14:21

First: please read this article:

http://www.catb.org/~esr/faqs/smart-questions.html

WKUP and RTC_ALARM are connected through an or-gate to the mcu. => you can loose interrupts, if WKUP isn't low.

If you write (old+1) as new alarm and the rtc has already updated to old+1, there will never (ok, after 136 years) be an alarm interrupt. => Change prescaler at least to factor of 4 and add try alarm=rtc_value+4.

RTC have to be synced everytime the shade registers of rtc are powered down. Look at AN2629. I think in stop and standby mode, you have to do it in every startup phase.
bruzzim
Associate II
Posted on May 17, 2011 at 14:21

> WKUP and RTC_ALARM are connected through an or-gate to the mcu.

> => you can loose interrupts, if WKUP isn't low.

WKUP is the PA0 input, right? I actually don't use it and it's GPIO setting  value is as default. Do you think it could be lead to problems?

> If you write (old+1) as new alarm and the rtc has already updated

> to old+1, there will never (ok, after 136 years) be an alarm interrupt.

> => Change prescaler at least to factor of 4 and add try alarm=rtc_value+4.

I reset the alarm into the alarm interrupt driver and set something like to  SetAlarm(Get_Rtc) so I expect to get the current clock. I see that I have to set the alarm to the very same RTC value to have alarm every 1 seconds. Your comment is interesting, probably the better is to have RTC @ 4Hz and alarms every 4 rtc.

I use the alarm to update the internal software time counter (timestamp) so I need not to drift or loose ticks.

Thanks and best regards

bruzzim
Associate II
Posted on May 17, 2011 at 14:21

At the time I designed the board I left WKUP pin floating since I wanted to use Stop Mode and the user manual states that the WKUP doesn't influence stop mode behaviour. ''RTC simplified block scheme'' on microprocessor user manual shows that WKUP pin is ORed with ALR event so It seems to have some influence on stop mode awake by ALR, Is this correct? In that case I would configure PA0 I/O as input pull down, otherwise I have to change my hardware.

Thanks

bruzzim
Associate II
Posted on May 17, 2011 at 14:21

I have still alarm missing even I did:

- change RTC frequency to 4 hz and set alarm to RTC+3

- configured WKUP pin (PA0) as input pull down

Any idea? I'm lost.

Thanks and best regards.