Sleep x ms and wakeup automatically

Generic boards that are not Maple or Maple mini clones, and don't contain the additional USB reset hardware
Post Reply
terraduino
Posts: 14
Joined: Tue Jun 27, 2017 6:34 pm

Sleep x ms and wakeup automatically

Post by terraduino » Wed Oct 11, 2017 11:12 pm

I want my STM32F103C8 to sleep for x ms. When sleeping for seconds, I use this code

Code: Select all

#include <STM32Sleep.h>
#include <RTClock.h>
RTClock rt(RTCSEL_LSE);
...
sleepAndWakeUp(STOP, &rt, iSecondsToSleep);
which works as expected.

Unfortunately, I failed to implement "sleep for x milliseconds" myself. I read the forum, searched the web, searched the core files and read the STM32 manual. I tried HardwareTimer just to find out that these don't wake up the STM32 from goToSleep(STOP); of STM32Sleep.h. :(
I tried to use the IWDG but failed again. Maybe I don't understand how the IWDG works. I thought it's similar to ATMega328p's watchdog. I've tried

Code: Select all

void loop() {
  lstate = ! lstate;
  digitalWrite(LED_PIN, lstate);
  iwdg_init(IWDG_PRE_256,2000);
  goToSleep(STOP); // sleep forever
}
but no blinking.
I don't care about the lack of precision of the IDWG, in case this is the easiest route to solve my problem.
Would be great if someone can point me in the direction.

Thanks & best

User avatar
RogerClark
Posts: 7478
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Sleep x ms and wakeup automatically

Post by RogerClark » Wed Oct 11, 2017 11:43 pm

The RTClock library got updated just a few days ago,

You may want to take a look at the lastest version to see if it has anything new which you could use

https://github.com/rogerclarkmelbourne/ ... 2/pull/334

terraduino
Posts: 14
Joined: Tue Jun 27, 2017 6:34 pm

Re: Sleep x ms and wakeup automatically

Post by terraduino » Thu Oct 12, 2017 12:22 am

Thank you for the link.
I'll have a look if I can solve my problem with the updates and get back here later.

Best

User avatar
RogerClark
Posts: 7478
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Sleep x ms and wakeup automatically

Post by RogerClark » Thu Oct 12, 2017 12:31 am

BTW.

Post a link to that other library "STM32sleep" you are using, as its not part of the core

terraduino
Posts: 14
Joined: Tue Jun 27, 2017 6:34 pm

Re: Sleep x ms and wakeup automatically

Post by terraduino » Thu Oct 12, 2017 12:41 am

Oh, sorry. Wasn't aware of it's origin. It's readme.md refer to viewtopic.php?f=3&t=658

Best

Post Reply