Determining Wakeup Source

Hi All

I have a counter wired to the WKP interrupt on an Electrion (0.6.2)

#define METER_INPUT WKP

void meterPulsedInterrupt (void){
	//this is an interrupt keep it quick
	counter_totalising++;
	detachInterrupt(METER_INPUT); //turn off interrupt for debounce (we turn it back on in our handler. )
}

setup(){

	pinMode(METER_INPUT, INPUT_PULLUP);
	attachInterrupt(METER_INPUT, meterPulsedInterrupt, FALLING);
}

in another function I put the Electron into SoftPowerOff
System.sleep(SLEEP_MODE_SOFTPOWEROFF, sleep_time);

When sleep_time OR wakeup expires, the unit is going to go through setup() / loop() again

How do I know what the wakeup source was/is I want to increment the count if the interrupt woke us, or not increment the count if the timer expired.

Thanks
Marshall

1 Like

Hi @marshall,

Good question! I solve this on my projects by using system_mode manual, and by checking the status of the WKP pin during my setup / loop with a simple pinmode input, and a digitalread. So long as your WKP pin stays high for a while (long enough for the electron to wake from sleep and read the state of the pin), then you can assert that the WKP pin is probably why you were woken up. :slight_smile:

Thanks,
David

2 Likes

Is there a way to read the uC registers directly.

Page 576 of the user manual for the F205 has a Flag that is set when the RTC wakes the device (the WUTF flag) I assume that the RTC is what is being used for the sleep function, so if we can read this before its cleared we’ll know for sure what the source was?

I also read in the user manual that the wakeup pin is pulled down with a RISING edge detection on it,. so my code above needs inversion?

Regards
Marshall

1 Like