0
\$\begingroup\$

I am using an STM32L053C8 and I am trying to set up an RTC wakeup event, and while I am successful, I can only do it to a max time which is a couple of seconds. I need to put it in standby and wake up days later. At the moment I am using the low speed internal 40KHz as the RTC clock, eventually i will get a 32.768 crystal. enter image description here

According to Carmine Noviello-Mastering STM32 i should be able to set the wakeup delay for a pretty long time. And while I do know it says using an external clock, using the internal one of a few Khz should still be able to provide a fairly decent delay for testing purposes. I just cannot figure it out. When I chose the 1Hz setting for the wake up clock, that only means it will use the RTC clock (40Khz)/(Asynch_prediv +1 x Synch_prediv+1) = new wake up clock frequency.It calls it 1Hz because it assumes you have set up the calendar to have a 1Hz frequency. Its too bad I can use the calendar as a wake up event.

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Which particular STM32 are you using? \$\endgroup\$ – Jan Dorniak Aug 19 '18 at 3:03
  • \$\begingroup\$ opps forgot to mention it STM32L053C8 \$\endgroup\$ – Edwin Fairchild Aug 19 '18 at 3:38
  • 1
    \$\begingroup\$ Almost the one I worked with - only difference is I had LQFP64 instead of LQFP48. Answer in progress. \$\endgroup\$ – Jan Dorniak Aug 19 '18 at 3:39
  • 1
    \$\begingroup\$ And maybe edit your question. \$\endgroup\$ – Jan Dorniak Aug 19 '18 at 3:39
  • 1
    \$\begingroup\$ As a side note: once you start making your own board consider adding a test point on PC13 - it has RTC calibration output \$\endgroup\$ – Jan Dorniak Aug 20 '18 at 10:44
3
\$\begingroup\$

The assumption about CK_SPRE being 1 Hz is caused by the fact that this is essential for correct timekeeping.

What you are missing are the wakeup counters (below wakeup clock in your screen). That is - the RTC counts the clock pulses (say coming from CK_SPRE) and only wakes you up when the count reaches the value set in wakeup counter. Assuming CK_SPRE is at 1 Hz this gives you a maximum wakeup period of 36 hours (as stated in the reference manual).

Now, where did those 48 days come from? Either the author somehow mistakenly multiplied the period by 2 ** 5 or he assumed that CK_SPRE is 1/32 Hz (which wrecks timekeeping).

There are two workarounds to this:

  • software counter
  • alarms

Software counters - simply use a variable in your code and do something like this in your main:

int i = 0;
while(true) {
    sleep(WFE); // forgot exact code
    ++i;
    if(i % 10 != 0)
        continue;

    // your stuff goes here
}

Use RTC alarms (which are just before wakeup counters in your book):

  • wake up (same WFE)
  • get current time from RTC
  • add N days to this time
  • set next alarm
  • do your stuff.
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.