Determine wakeup reason (RTC or interrupt)

Home Forums mDot/xDot Determine wakeup reason (RTC or interrupt)

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #26536

    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
    Mike

    #26537
    Ryan Klaassen
    Blocked

    Add 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.

    #26570

    Thanks 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?

    #26571
    Ryan Klaassen
    Blocked

    try setting the mode to pullup or pulldown

    #26572

    Tried 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.

    #26581

    This 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 up

    #26585
    Jason Reiss
    Keymaster

    You could save the RTC time before sleep in a backup register and then read RTC when you wakeup and compare.

    #26587
    Jason Reiss
    Keymaster

    You 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->ALRMAR

    #26589

    Thanks, 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/

    #26590

    Oddly, 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 00000037

    The fact that the pin is still high, means I know why it exited.

    #26598
    Ryan Klaassen
    Blocked

    Does the interrupt go through the ISR without going to sleep?

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.