8 years, 5 months ago.

How to solve strange runtime error.

Hi guys, could someone help me out with this? I'm roughly copying this code:

  1. include "mbed.h"

InterruptIn button(p5); DigitalOut led(LED1); DigitalOut flash(LED4);

void flip() { led = !led; }

int main() { button.rise(&flip); attach the address of the flip function to the rising edge while(1) { wait around, interrupts will interrupt this! flash = !flash; wait(0.25); } }

and it works and compiles fine, but if I change p5 to p19, I get a runtime error. I was under the impression that I could use any number pin for an interrupt, so what's going on?

Thanks in advance

1 Answer

8 years, 5 months ago.

This is on an LPC1768?

The LPC1768 doesn't allow GPIO pins in IO bank 2 to be used for interrupts.

Guess which bank p19 and p20 are on.

All of the others will work except for those two. I think everyone has been caught out by this at some point or other.

Also FYI for future posts if you do:

<<code>>
#include "mbed.h"
InterruptIn button(p5);
DigitalOut led(LED1);
DigitalOut flash(LED4);
  //etc...
<</code>>

and you'll get

#include "mbed.h"
InterruptIn button(p5);
DigitalOut led(LED1);
DigitalOut flash(LED4);
  //etc...

which is a lot easier to read

Accepted Answer

Ahhh thank you so much, I'd worked out that it was just those 2 pins, but couldn't work out what was causing it. Absolute lifesaver.

posted by Chas Sheppard 28 Apr 2017