arduino-libraries / ArduinoLowPower

Powersave features for SAMD boards
GNU Lesser General Public License v2.1
81 stars 57 forks source link

Not working on SAMD #5

Open disk91 opened 6 years ago

disk91 commented 6 years ago

The following code never wakeup after the first sleep call (led always on)

include

void setup() { // put your setup code here, to run once: pinMode(6,OUTPUT); }

void loop() { // put your main code here, to run repeatedly: digitalWrite(6,HIGH); LowPower.sleep(500); digitalWrite(6,LOW); LowPower.sleep(500); }

disk91 commented 6 years ago

tested on Arduino MKRFOX1200

disk91 commented 6 years ago

To be more precise : it works correctly if I remove power supply and restore power it. But it stops working when the device has been programmed from USB.

facchinm commented 6 years ago

Hi @disk91 , this may depend on your operating system/USB connection; the code path in case of USB connection is quite different from the normal one. Could you try reverting https://github.com/arduino-libraries/ArduinoLowPower/commit/8cf4c737ddb755e76c20407df3d70cc507bd9651 and see if the behaviour is the expected one (in your setup)?

sjernigan commented 6 years ago

We are seeing a similar problem. We also see that sometimes the first sleep call almost immediately returns. Current Setup: Feather M0, using Mac to program/power, reverted the commit above as asked-- When powered from a battery (no data signal), the first call immediately returns, subsequent calls work correctly. Same for power by mac after unplugging. However, after you reprogram, the first call will never return. The reset button continues the previous behavior (ie., it does not change it to the unplugged/replug behavior).

warriorfenixSM commented 6 years ago

I have the same problem

sslupsky commented 5 years ago

I think I have this problem as well. I think it may have something to do with the rtc. Recently I added an rtc.begin() in my setup() and this has stopped the OP’s issue from happening.

sslupsky commented 5 years ago

I found another reference to this issue:

https://forum.arduino.cc/index.php?topic=499101.0

Gormd reported that using LowPower.attachInterruptWakeup() also cleared this up. Seem's to me there is a bug here related to declaration or construction of the RTC object?

DanielRIOT commented 4 years ago

You could call
SerialUSB.end(); just before calling LowPower.sleep(); to stop the USB interrupts from happening and continuously waking the system

nekuneko commented 3 years ago

Hi @disk91 , this may depend on your operating system/USB connection; the code path in case of USB connection is quite different from the normal one. Could you try reverting 8cf4c73 and see if the behaviour is the expected one (in your setup)?

@facchinm Is there any reason to use USBDevice.standby(); call ? I think it doesn't work in the propper way and in order to avoid issues, I would leave sleep() function simply as this:

void ArduinoLowPowerClass::sleep() {
    USBDevice.detach();
    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
    __DSB();
    __WFI();
       USBDevice.attach();
}

If standbyis used, wouldn't it be necessary to have a function to "resume" and callrunInStandby() as well standbyfunction calls noRunInStandby()?