Photon resets on wake from sleep

I’m trying to use Sleep with an interrupt for wake. The Photon does go to sleep just fine, but when I trigger the interrupt to wake, it immediately flashes red and resets. That may work for my application, but I don’t really want to make the user wait for the reset to complete.

I’m also not clear from the docs on what actually happens during sleep and wake. Should execution resume right after the sleep function, as if the Photon had not gone to sleep?

If it matters, I’m also using the sleep interrupt pin with a regular interrupt (it’s a line from a touch screen). I have tried to detachInterrupt before using it for sleep, but that didn’t seem to matter.

I’m not sure where I should be looking to find out why it would crash on wake.


That depends on which sleep mode you’re using. In SLEEP_MODE_DEEP, the device does reset when it awakens, but it shouldn’t in any other mode. It shouldn’t flash red in any case, so it would be helpful to see your code, and a description of what you have attached to the Photon.

I’m not using deep sleep mode, but according to the docs I’m using “stop mode,” which should not reset. The Photon is connected to a touch screen and a charge controller. The interrupt is being triggered by the touch screen.

I’d still like to understand if I need to detach an existing interrupt for my wake pin, and what exactly happens when execution resumes on wake. Can my code even know it’s just woken up? Does my code resume just after the sleep function? If I knew some of that, I might be able to do some additional debugging.

Posting all of the code would be tricky, as it’s around ~10k lines, however, here’s my sleep function (at least one iteration of it):

void fbSleep() {
  // detachInterrupt(touchPin);
  digitalWrite(touchPin, LOW);

  display.drawStrAbs(55, 100, "Sleeping...");
  // sleeping = true;
  display.allOff(); // Shut down screen
  // delay(5000);

Yes, it does. In the case of the code you posted, it should resume with the line after the one from which you called fbSleep. As for detaching the interrupt, I’m not sure. Can you try using a different pin to wake from sleep to see if that makes a difference?

What is the exact red color code you see after wake?
I see you doing digitalWrite(touchPin, LOW), but if you have an interrupt attached to that pin, what’s the pinMode() you were using before?
And you might need to consider that System.sleep(touchPin, FALLING) will put the pin into INPUT_PULLUP mode to ensure the wake signal to be non-floating.

And how is fbSleep() called by your code?
It’s not allowed to be called as ISR nor from a Software Timer or other “exotic” ways :wink:

1 Like