5 years, 6 months ago.

Getting InterruptIn to fire properly

  1. include "mbed.h"

I had an application running fine and something went wrong and now it does not work. The interrupt is not firing. It is possible that it is a hardware problem but I highly doubt it. To test the interrupt I wrote this simple application to fire it and it does not work. Is there something someone sees I am doing wrong?

Thanks in advance.

Board is an NRF52_DK

code- InterruptIn button(p12); DigitalOut led1(LED1); DigitalOut led2(LED2);

void trigger(){ led1 = 0; }

int main() { led1 = 1; led2=0; button.enable_irq(); button.rise(&trigger); } -end code-

1 Answer

5 years, 6 months ago.

Hello Mark,

I have tested your code (without having the endless loop in place) on an LPC1768 and for my surprise it worked. But maybe the following will help make it work again on your board:

#include "mbed.h"

InterruptIn button(p12);
DigitalOut  led1(LED1);
DigitalOut  led2(LED2);

void trigger()
{
    led1 = 0;
}

int main()
{
    led1 = 1;
    led2 = 0;
    button.mode(PullDown);  // pulls the input LOW
    button.enable_irq();
    button.rise(&trigger);
    while(1) {};            // endless loop
}

ADVISE: To have a more readable code after pasting it here (to mbed pages) try to mark it up as below (with <<code>> and <</code>> tags, each on separate line at the begin and end of your code)

<<code>>
text of your code
<</code>>