10 years, 3 months ago.

Multiple external interrupts

Hello all,

I am having unexpected behaviour when I try to use several InterruptIn on Nucleo F030R8:

Multiple external interrupts snippet

#include "mbed.h"

Serial pc(SERIAL_TX, SERIAL_RX);

InterruptIn push1(PF_6);
InterruptIn push2(PF_7);
InterruptIn push3(PA_13);

void pressed1() {
    pc.printf("1");
}
void pressed2() {
    pc.printf("2");
}
void pressed3() {
    pc.printf("3");
}
int main()
{
    push1.mode(PullUp);
    push1.fall(&pressed1);
    push2.mode(PullUp);
    push2.fall(&pressed2);
    push3.mode(PullUp);
    push3.fall(&pressed3);
    for(;;);
}

If I only have declared one InterruptIn interrupt, the program works fine, but if I declare more than one, the programs hangs up unexpectedly on interrupt callback.

Reading the uC datasheet, I think that the problem might be that the pins PF_6, PF_7 and PA_13 share the same interrupt vector.

Does anybody know how to manage this situation? I have tried to use the same function callback for the three interrupts but it does not work.

I am using mbed library Revision 88.

Thank you so much for your help.

Question relating to:

Affordable and flexible platform to ease prototyping using a STM32F030R8T6 microcontroller.

1 Answer

10 years, 3 months ago.

You describe exactly the issue, it only accepts one interrupt per vector. IIRC technically it can quite easily be changed to accept one interrupt per number (eg: those pins you want could work, but for example PF_6 and PB_6 cannot be used at the same time). But then it has to do some decoding, imo it would be nice if that is added, and iirc it is doable, but short term the easier solution for you most likely is to try to use pins with different interrupt vectors.

Accepted Answer

Hi Erik,

Thank you for your answer.

Could you detail me what I need to change to accept one interrupt per number? I do not mind if I have to decode what pin has caused the interrupt, it is not a critical time task.

Thank you so much again.

Regards!

posted by Ru ben 12 Sep 2014

Problem is that it would need to be changed in the mbed-src. Which you could import and do. There is a register which sets which number of the pin interrupts is active, it is in the reference manual, but I wouldn't know it directly which one it is.

posted by Erik - 12 Sep 2014

That is the way I have implemented it. I thought there were some way to do it without modifying CPU registers directly (which is not really portable).

Thank you so much Erik!

Regards.

posted by Ru ben 12 Sep 2014