cancel
Showing results for 
Search instead for 
Did you mean: 

RTC ALARM is not triggered! - STM32L152

anthony239955_st
Associate II
Posted on August 15, 2016 at 07:22

Hi,

I am running a STM32L152 into stop mode. The MCU sleeps most of the time (waking up every 1hr to read sensors). As I have the watchdog running, I am using RTC to generate an alarm every 10s (watchdog period is ~25s). So when I am sleeping for 1hr, I am setting the alarm in time now + 10s, then go to stopmode, woken up by the alarm and set the alarm to the next 10s etc... 

It is working almost fine but for some reason, sometimes the MCU resets because of the watchdog not kicked. That means I have missed the alarm for some reason. I have been doing some tests and over 3 days it happened 3 times. By saving some flag into a preserved ram I know for sure that the alarm did not work (flag is set to 1 when wakeup occurs and reset before sleep). And I also know that my alarm time and date are set correctly (also saved into the preserved ram section every time).

As anyone ever experienced this kind of issue? I was thinking to generate 2 alarms so that if the MCU missed one, it is very unlikely that it would miss two.

Any previous experience or ideas are welcome.

Cheers,

B.
3 REPLIES 3
jpeacock23
Associate III
Posted on August 15, 2016 at 19:32

If the alarm is missed the most likely explanation is you set the alarm time earlier than the current time, or adjusted the current time past the alarm.  Check the alarm registers when the watchdog fires and test if the alarm setting is greater than the current time.  Do you configure for a periodic alarm every 10 seconds or a fixed time of day?

I use Alarm A to generate an event at the next 15 minute interval before entering low power sleep mode.  I haven't seen any lost interrupts but I ensure there is a minimum of 5 minutes of low power mode between time of day and next alarm (a design requirement).  I also use Alarm B to generate a periodic 250ms event in low power run mode without any problems.

Is there a pattern to when the alarm is lost, a particular time of day?  Capture the RTC register settings when the watchdog triggers to see what's going on.

  Jack Peacock

anthony239955_st
Associate II
Posted on August 16, 2016 at 09:04

Hi Jack,

Thanks for your reply. There is no pattern really. It is really random.

This is an example of the register when the issue occurred:

wakeup=946692614, current=946692613 (unix time)

alarm 1/1/2000 - 2:10:14

Last Interrupt register value

.ALRMAR  = 1021013

.ISR = 127

.ALRMBR  = 0

.CR      = 1100

.DR      = 2101

.TR      = 21013

.TSDR    = 0

.TSTR    = 0

I am saving the RTC register when this is called: HAL_RTC_AlarmAEventCallback()

As you can see, the alarm was set to 2:10:14 but the last interrupt was for 2:10:13.

And I am not blocked in a particular function as when the issue occurred my power consumption is ~20uA.

Also, How did you set up AlarmB every 250ms? I am curious as would like to have ms resolution for the IT. 

Thanks for your help.

B.

anthony239955_st
Associate II
Posted on August 17, 2016 at 01:03

Here is a more detailed RTC register. There is definitely an issue with RTC from what I can see:

The alarm is incremented by a second everytime I wake up from stopmode.

When entered HAL_RTC_AlarmAEventCallback():

.ALRMAR  = 1011909

.ISR = 27

.ALRMBR  = 0

.CR      = 1100

.DR      = 2101

.TR      = 11909

.TSDR    = 0

.TSTR    = 0

After reset by the watchdog:

.AfterResetALRMAR  = 1011910

.AfterResetISR = 27

.AfterResetALRMBR  = 0

.AfterResetCR      = 1100

.AfterResetDR      = 2101

.AfterResetTR      = 11939

.AfterResetTSDR    = 0

.AfterResetTSTR    = 0

After setting the RTC alarm:

.AfterSettingAlarmALRMAR  = 1011910

.AfterSettingAlarmISR = 27

.AfterSettingAlarmALRMBR  = 0

.AfterSettingAlarmCR      = 1100

.AfterSettingAlarmDR      = 2101

.AfterSettingAlarmTR      = 11909

.AfterSettingAlarmTSDR    = 0

.AfterSettingAlarmTSTR    = 0

 Any idea what could be wrong?

I will try to reproduce the issue with STM32L152RET6 nucleo demo board.

Cheers,

B.