InterruptIn triggers on startup?

02 Dec 2010

Hello!

I use an InterruptIn for detecting a switch-change. The switch is directly connect to the mbed without an external Pull Up.

When I start or reset mbed, the Interrupt always triggers once. But the switch was not pressed.

 

Here is a test-programm:

#include "mbed.h"

//define digital interrupt pin
InterruptIn intPin(p23);

Serial pc(USBTX, USBRX); // tx, rx

// callback function when interrupted
void trigger() {
     pc.printf("\n\rtriggered\r\n");
}


int main() {
    //wait(1);
    pc.printf("\n\rConnected to mBed\r\n");
    intPin.mode(PullUp);          // Enable internal pullup
    wait(1);                        // no effect
    intPin.fall(&trigger);          // Call function 
    //intPin.rise(&trigger);        // Call function 
    while(1) {
        wait(1);
        pc.printf(".");
    }
}
Output:

Connected to mBed

triggered
........

Changing PullUp / PullDown has no effect on the "startup-trigger".

Waiting after setting the pin to PullUp doesn't change this.

How can I prevent InterruptIn from triggering on startup?

 

Regards - Charly

 

03 Dec 2010

Although I can't offer an explanation as to why it does that (the Mbed libs are not open source) I can give you a workaround to make the problem go away:-

#include "mbed.h"

//define digital interrupt pin
InterruptIn intPin(p23);

Serial pc(USBTX, USBRX); // tx, rx

// callback function when interrupted
void trigger() {
     pc.printf("\n\rtriggered\r\n");
}

int main() {
    //wait(1);
    pc.printf("\n\rConnected to mBed\r\n");
    intPin.mode(PullUp);          // Enable internal pullup
    wait(1);                        // no effect

    // Before attaching callbacks clear any pending interrupts
    LPC_GPIOINT->IO0IntClr = 0xFFFFFFFFUL;
    LPC_GPIOINT->IO2IntClr = 0xFFFFFFFFUL;
    intPin.fall(&trigger);          // Call function 
    //intPin.rise(&trigger);        // Call function 
    while(1) {
        wait(1);
        pc.printf(".");
    }
}

03 Dec 2010

Hi Karl,

Thanks for the example program. Made it very easy to reproduce.

I've posted a library with the provisional bugfix for this. To get hold of it:

  • Delete the mbed library from your project
  • Right-click your project and choose "Import Library..."
  • Enter the source url as http://mbed.org/projects/libraries-testing/svn/bugfix-561

It'd be great if you could confirm this eliminates the problem from your original program.

Thanks, Simon

03 Dec 2010

Confirm bugfix-561 fixes the problem on my test systems.

03 Dec 2010

Hi Simon and Andy!

Thanks for the quick response and fix.

Yes, both the workaround and the bugfix-library fix the problem! No interrupt is generated at startup.

Thank you again - charly

19 Dec 2010
31 Jan 2011

Simon,

There's no sign of this thread in /cookbook/mbed-Bugs-and-Suggestions. Would be good to if/when this fix is released.

[Edit, I added a reference to this thread in the Known Bugs section. Awaiting Mbed team update]

31 Jan 2011

Thanks, updated. This should now be fixed in v27.

Simon