I am looking at the spec for the new Sleep functionality now available on Gen3 devices. However, it is not clear how to use sleep() if I am only interested in sleeping for a certain amount of time without waking up using a pin.
System.sleep(uint16_t wakeUpPin, uint16_t edgeTriggerMode, long seconds) can be used to put the entire device into a stop mode with wakeup on interrupt or wakeup after specified seconds. In this particular mode, the device shuts network subsystem and puts the microcontroller in a stop mode with configurable wakeup pin and edge triggered interrupt or wakeup after the specified seconds. When the specific interrupt arrives or upon reaching the configured timeout, the device awakens from stop mode. The device will not reset before going into stop mode so all the application variables are preserved after waking up from this mode. The voltage regulator is put in low-power mode. This mode achieves the lowest power consumption while retaining the contents of RAM and registers.
// EXAMPLE USAGE
// Put the device into stop mode with wakeup using RISING edge interrupt on D1 pin or wakeup after 60 seconds whichever comes first System.sleep(D1,RISING,60);
// The device LED will shut off during sleep
I guess you use an unused pin if you only want a time based sleep.
@will@Fragma@KyleG thanks for your help. What I mean is, is there a version of the function where a pin and a trigger mode don’t need to be specified? Or perhaps NULL could be put in their place?
And if I need to use an “unused pin”, what would be best?
NULL won’t work as this would just evaluate to 0 which in turn means D0.
But you can use PIN_INVALID or an empty pin list (e.g. System.sleep( {}, {}, 60);).
Good question. Good workaround from @ScruffR
I have not tested this but another potential approach could be to use the wake reason like the example given in the reference documents [BTW who ever thought of including this ]
SleepResult result = System.sleepResult();
if (result.wokenUpByRtc()) {
Log.info("Xenon was woken up by the RTC (after a specified number of seconds)");
}