Skip to content

DeepSleepExternalOrTimeWakeup.ino, wakes up immediately without DeepSleep for 10 seconds #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
msfujino opened this issue Feb 26, 2025 · 10 comments

Comments

@msfujino
Copy link

I am trying “DeepSleepExternalOrTimeWakeup.ino” but it wakes up immediately without DeepSleep for 10 seconds.
I think there is a problem with LINE130 ~ LINE134 in "ArduinoLowPower.cpp".

@grobasoz
Copy link

It could be because the same pin PC0 is used for the Wakeup as well as the Escape Pin for programming. I used a different Wake Pin (PA5 = D10) and it works fine.

@msfujino
Copy link
Author

I tried changing the pin, but it just wakes up when I put my finger near the pin.
It does not appear to be pulled down.

@grobasoz
Copy link

I suggest you initialise the pin to either pullup or pulldown. I use PA5 as it can be used to wake from sleep modes using the attachInterrupt function.

  // Running IRQ Pin
  pinMode(WAKE_UP_PIN, INPUT_PULLUP);
  attachInterrupt(WAKE_UP_PIN, myWakeup, FALLING);

  // Set up the wake-up pin
  LowPower.attachInterruptWakeup(WAKE_UP_PIN, nullptr, FALLING);

@msfujino
Copy link
Author

This problem does not occur with ExternalWakeup; it occurs when TimedWakeup and ExternalWakeup are used at the same time.
I think there is a problem with LINE130 ~ LINE134 in "ArduinoLowPower.cpp".

@grobasoz
Copy link

I'm using the example you mentioned, viz DeepSleepExternalOrTimedWakeup.ino...

@msfujino
Copy link
Author

msfujino commented Feb 28, 2025

Here is the code being executed and the serial monitor results. BSP2.3.0 stack "None"
Nothing is connected to PA5.
It wakes up immediately without sleeping for 10 seconds.

`#include "ArduinoLowPower.h"

#define WAKE_UP_PIN PA5

void setup()
{
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LED_BUILTIN_INACTIVE);
Serial.println("Deep sleep with external or timed wakeup");

// Running IRQ Pin
pinMode(WAKE_UP_PIN, INPUT_PULLUP);
attachInterrupt(WAKE_UP_PIN, myWakeup, FALLING);
// Set up the wake-up pin
LowPower.attachInterruptWakeup(WAKE_UP_PIN, nullptr, FALLING);
}

void loop()
{
digitalWrite(LED_BUILTIN, LED_BUILTIN_ACTIVE);
delay(500);
digitalWrite(LED_BUILTIN, LED_BUILTIN_INACTIVE);
delay(500);

Serial.printf("Going to deep sleep for 10s at %lu\n", millis());
LowPower.deepSleep(10000);
}

void myWakeup () {
}`

`09:44:17.389 -> Going to deep sleep for 10s at 1014

09:44:17.980 -> Deep sleep with external or timed wakeup

09:44:18.995 -> Going to deep sleep for 10s at 1014

09:44:19.589 -> Deep sleep with external or timed wakeup

09:44:20.604 -> Going to deep sleep for 10s at 1014

09:44:21.197 -> Deep sleep with external or timed wakeup

09:44:22.215 -> Going to deep sleep for 10s at 1014

09:44:22.776 -> Deep sleep with external or timed wakeup

09:44:23.791 -> Going to deep sleep for 10s at 1014

09:44:24.380 -> Deep sleep with external or timed wakeup

`

@grobasoz
Copy link

I tested your code and it worked fine. At 11:06:54 I triggered a Pin Wake (PA5).

11:06:28.091 [10.657] RX> Deep sleep with external or timed wakeup
11:06:29.071 [00.979] RX> Going to deep sleep for 10s at 1037
11:06:39.735 [10.663] RX> Deep sleep with external or timed wakeup
11:06:40.716 [00.980] RX> Going to deep sleep for 10s at 1037
11:06:51.380 [10.662] RX> Deep sleep with external or timed wakeup
11:06:52.361 [00.979] RX> Going to deep sleep for 10s at 1037
11:06:54.852 [02.490] RX> Deep sleep with external or timed wakeup
11:06:55.833 [00.979] RX> Going to deep sleep for 10s at 1037
11:07:06.497 [10.662] RX> Deep sleep with external or timed wakeup
11:07:07.479 [00.980] RX> Going to deep sleep for 10s at 1037
11:07:18.142 [10.661] RX> Deep sleep with external or timed wakeup
11:07:19.122 [00.978] RX> Going to deep sleep for 10s at 1037

@msfujino
Copy link
Author

It's strange. My XIAO_MG24 is floating in the air with nothing connected to its pins except it is connected to the PC via USB-C so that it is not affected by its surroundings.

I am wondering why LINE130-134 in ArduinoLowPower.cpp has a different command order compared to LINE102-108. If I change the order to be similar to LINE102-108, the problem will not occur.

@grobasoz
Copy link

OK - I see now. You want to enable Pin Retention on exit from EM4?
Yes, I suppose that would be necessary if the pin was intended to be just left floating...
In my testing, I had the PA5 pin set to a defined state - either High or Low, never just floating.

@msfujino
Copy link
Author

A mechanical switch was assumed for the wake-up signal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants