6 years, 8 months ago.

InterruptIn problem

Hi guys, I have a simple program with some interrupts and I don't know what am I missing here. I want to define InterruptIn pins in the buffer (for DigitalIn and DigitalOut this is possible is it possible also for InterruptIn?), like I did in the program here (it is not working):

#include "mbed.h"

Serial debug(USBTX, USBRX,230400);

InterruptIn din[] = {PA_0, PC_15, PA_1, PC_14, PA_4, PH_1};

void test(){
    debug.printf("test");
}

int main()
{

    din[0].mode(PullUp);
    din[0].fall(&test);
    
    while(1){}   
}

...but if I do it like in the next program all works perfectly:

#include "mbed.h"

Serial debug(USBTX, USBRX,230400);

InterruptIn din0 = (PA_0);

void test(){
    debug.printf("test");
}

int main()
{

    din0.mode(PullUp);
    din0.fall(&test);
    
    while(1){}   
}

Thanks for all the help.

Ales Zupanc

1 Answer

6 years, 8 months ago.

Hello Ales,
Try to call the constructor for each element when creating the din array as below:

InterruptIn din[] = { InterruptIn(PA_0), InterruptIn(PC_15), InterruptIn(PA_1), InterruptIn(PC_14), InterruptIn(PA_4), InterruptIn(PH_1) };

NOTE:

  • When building offline with GCC toolchain you have to do the same also in your second example. Otherwise the code won't compile.
  • debug has already been declared as static inline void debug(const char *format, ...) in mbed_debug.h so you should choose a different name for the Serial object.

    Zoltan