Why does this IRQ fire?

08 Jul 2010 . Edited: 08 Jul 2010

I was stumbling with an IRQ problem. So, as usual, reduced the problem to it's minimum.

So, given this code snippet why does the interrupt fire when the mbed is rebooted or powered on?

#include "mbed.h"

Serial pc(USBTX, USBRX); 
InterruptIn test(p29);
DigitalOut myled(LED1);
DigitalOut led2(LED2);

void test_irq(void) {
    printf("This should never be called\r\n");
    led2 = 1;
}

int main() {

    led2 = 0;
 
    test.mode(PullDown);
    test.rise(&test_irq);

    while(1) {
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
    }
}


Given that nothing is connected to p29 (it's left floating), by setting PullDown and then adding an IRQ function, when the Mbed powers on, the pin irq routine is called once and only once.

Why is that? Given that I pulled it down before adding the IRQ vector, why does it fire when there is no rising edge on the pin?

 

Edit: I added a wire link from p29 to GND and the IRQ doesn't fire. So not sure where the spurious IRQ edge comes from in the example above. So I suppose I need to find out in my project why the external device doesn't take p29 low fast enough! Can't even spot it with the scope.

09 Jul 2010

Follow-up:

In addition to the above problem, the external device was also suffering start-up problems. Breif description: p29 was connected to a GPS 1PPS output and the IRQ was to detect the positive going pulse from the GPS unit. However, annoyingly, the GPS also failed to boot at power on if the 1PPS was directly connected to Mbed p29.

So, I added a FET with a pullup resistor. The 1PPS signal is applied to the gate and the source then pulls the low. So I inverted the software using the .fall(&fn) method to detect the now negative going pulse.

Effect: The GPS unit always starts. No "false" IRQ occurs during boot-up. Problem solved.