Determine wakeup reason (RTC or interrupt)
- This topic has 10 replies, 3 voices, and was last updated 6 years, 1 month ago by Ryan Klaassen.
-
AuthorPosts
-
October 17, 2018 at 12:25 pm #26536mike_cat_taylor@hotmail.comParticipant
Hi
I have just joined and I am playing with my first mDot from the TTN UK conference.
I have the “Dot-Examples” running, and I am just tweaking the code to play, however I would really like the know the reason for coming out of the function “sleep_wake_rtc_or_interrupt”, was it due to timer or pin, so I can send different messages. Is this possible?
Ideally, I would like the interrupt pin (D3?) to be a normally closed loop to ground.
Regards
MikeOctober 17, 2018 at 1:25 pm #26537Ryan KlaassenBlockedAdd a bool and set to true on rise of the pin on interrupt. Set to false before sleep. Check if true then the pin was the cause, else it was the rtc.
October 17, 2018 at 3:28 pm #26570mike_cat_taylor@hotmail.comParticipantThanks for your assistance Ryan, I have made some progress. Here is what I have implemented.
bool rise_flag = false; bool fall_flag = false; void rise_handler(void) { rise_flag = true; } void fall_handler(void) { fall_flag = true; }
And just before the sleep_wake_rtc_or_interrupt() call, I set:-
InterruptIn in(PA_0); in.rise(&rise_handler); in.fall(&fall_handler);
I seem to get the fall flag set, but the rise_flag never gets set, even though it returns from the sleep.
Any ideas?
October 17, 2018 at 3:41 pm #26571Ryan KlaassenBlockedtry setting the mode to pullup or pulldown
October 17, 2018 at 3:57 pm #26572mike_cat_taylor@hotmail.comParticipantTried that and no joy, but I think I’ve been starring at this for too long now. Will try again tomorrow.
Thanks for your assistance.
October 18, 2018 at 5:32 am #26581mike_cat_taylor@hotmail.comParticipantThis is my code as it stands. On opening the circuit (i.e. so it is no longer grounded), the processor comes out of sleep, but it seemingly never goes through the ISR to set the flag to true. I am a bit lost as what else to try now. Any suggestions most welcome.
mDot* dot = NULL; lora::ChannelPlan* plan = NULL; Serial pc(USBTX, USBRX); static bool deep_sleep = false; // define ISR's bool rise_flag = false, fall_flag = false; void rise_handler(void) { rise_flag = true; } void fall_handler(void) { fall_flag = true; } DigitalIn pa0pin(PA_0); int main() { // Custom event handler for automatically displaying RX data RadioEvent events; pc.baud(115200); mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); plan = new lora::ChannelPlan_EU868(); dot = mDot::getInstance(plan); assert(dot); // attach the custom events handler dot->setEvents(&events); logInfo("--Starting (version %f)--", VERSION); pa0pin.mode(PullUp); //set the board to use a pullup resistor on pin PA0 InterruptIn in(PA_0); in.rise(&rise_handler); in.fall(&fall_handler); while (true) { rise_flag = fall_flag = false; logInfo("--Going to sleep now, deep_sleep=%d--",deep_sleep); sleep_wake_rtc_or_interrupt(deep_sleep); //logInfo("\r\n"); logInfo("--Back from sleep (rise_flag=%d fall_flag=%d, pin=%d)--",rise_flag,fall_flag,pa0pin.read() ); } return 0; }
Sample output from opening the circuit:-
[INFO] –Back from sleep (rise_flag=0 fall_flag=0, pin=1)–
[INFO] –Going to sleep now, deep_sleep=0–
[INFO] sleeping 10s or until interrupt on DIO7 pin
[INFO] application will resume after waking upOctober 18, 2018 at 8:13 am #26585Jason ReissKeymasterYou could save the RTC time before sleep in a backup register and then read RTC when you wakeup and compare.
October 18, 2018 at 8:28 am #26587Jason ReissKeymasterYou might be able to check this register for time left until alarm is to fire. Time left will be 0 if the alarm was complete.
RTC->ALRMAROctober 18, 2018 at 8:30 am #26589mike_cat_taylor@hotmail.comParticipantThanks, that’s more to try… I am just giving this guys code a whirl just in case there is something different about it https://os.mbed.com/users/janjongboom/code/mdot_two_way/file/0fd5e5e121ea/main.cpp/
October 19, 2018 at 3:06 am #26590mike_cat_taylor@hotmail.comParticipantOddly, it comes back out of sleep, but it never goes through the ISR.
[INFO] ~~woke up, fromInterrupt=0~~
[INFO] –Back from sleep (woke_from_interrupt=0, pin=1)–
…
[INFO] Going back to sleep (INTERRUPT On DIO7 Pin)
[INFO] entering sleep (stop) mode 00000037The fact that the pin is still high, means I know why it exited.
October 19, 2018 at 8:48 am #26598Ryan KlaassenBlockedDoes the interrupt go through the ISR without going to sleep?
- This reply was modified 6 years, 1 month ago by Ryan Klaassen.
-
AuthorPosts
- You must be logged in to reply to this topic.