How to detach or disable InterruptIn?

19 Nov 2009

Hello,

After attaching the interrupt handling function to an InterruptIn pin, how to detach or disable the handling function in runtime?

Is it possible to change the handling function in runtime?

Best regards,

Paul

19 Nov 2009 . Edited: 19 Nov 2009

Hi Paul,

Paul Kang wrote:
After attaching the interrupt handling function to an InterruptIn pin, how to detach or disable the handling function in runtime?

The eagle-eyed will spot it in the documentation, but it doesn't exactly jump out at you:

All you do to set there to be no interrupt/handler is set the function to NULL (or 0), like:

InterruptIn interrupt(p20);
interrupt.rise(NULL);

This probably almost answers your second question:

Paul Kang wrote:
Is it possible to change the handling function in runtime?

Yep! Just use the same technique. Here is a simple test program showing both these cases:

#include "mbed.h"

DigitalOut led1(LED1);
DigitalOut led2(LED2);
InterruptIn interrupt(p20);

void foo() {
    led1 = !led1;
}

void bar() {
    led2 = !led2;
}

int main() {
    while(1) {
        interrupt.rise(&foo);
        wait(5);
        interrupt.rise(&bar);
        wait(5);
        interrupt.rise(NULL);
        wait(5);
    }
}

So in this example, the handler will change every 5 seconds. If you create rising edges on p20 (e.g. tap a wire on p20 connected to VOUT), you should see LED1 responding, then LED2, then nothing. Rinse, repeat.

Hope this answers your question and gives you what you need.

Simon

20 Nov 2009

Thank you Simon. I should check the document more carefully.

Best regards,

Paul

17 Dec 2010

Very strange ... according to handbook "Any of the numbered mbed pins can be used as an InterruptIn, except p19 and p20. "

So how it works this program?