9 years, 11 months ago.

Nucleo 401 Multiple InterruptIn Pins

I have tried to use InterruptIn on two different pins (PA_6 & PA_7), but it does not appear to be working. If I only declare either one or the other pin using InterruptIn, then the corresponding Interrupt Service Routine (ISR) works exactly as expected. I have not delved into the source code, but maybe more than one pin is not yet supported? If not, then does anyone know when more than one pin might be supported or if there is a work-around?

InterruptIn leftEncoderClk(PA_6);

InterruptIn rightEncoderClk(PA_7);

int leftEncoderTicks = 0;

int rightEncoderTicks = 0;

void leftEncoderTick() { leftEncoderTicks++; }

void rightEncoderTick() { rightEncoderTicks++; }

int main() {

leftEncoderClk.mode(PullDown);

rightEncoderClk.mode(PullUp);

leftEncoderClk.rise(&leftEncoderTick);

rightEncoderClk.fall(&rightEncoderTick);

}

Regards, Abe

Question relating to:

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

2 Answers

9 years, 11 months ago.

I think this is because EXTI5 to EXTI9 are sharing the same interrupt vector. this means all port pins with number from 5 to 9 will trigger the same interrupt routine (PA_6, PA_7, PB_8...)

regards, MaxT

Accepted Answer

Maxime, thanks for the information. Now the resulting behavior makes some sense. I just downloaded the reference and programming manual for the STM32401RE, so I should be able to take a closer look. I am hoping that there is a flag or some way for me to identify which pin triggered the corresponding interrupt. Then I can simply have one ISR that checks for a PA_6 or PA_7 trigger event.

Regards, Abe

posted by Abraham Howell 12 May 2014

I went ahead and used PH0 & PH1 since they use EXTI0 & EXTI1 respectively and I am able to decipher encoder transitions. Now I understand how the interrupts function on the STM32s. I hope this helps other people out.

posted by Abraham Howell 13 May 2014
9 years, 11 months ago.

I don't have it myself, so cannot test it, but is your mbed library up to date? Afaik that should be possible with the newer mbed libs (you just cannot have several interrupts on the same pin number, so not PA_6 and PB_6, hardware limitation.

Click on your mbed lib in the compiler, check if there is an update button at the right side.

I have the latest mbed library, but the interrupts do not function as expected. If I only use one or the other, then the active interrupt functions properly. When I activate both interrupts, then only the PA_7 interrupt is triggered, but it is triggered far more times than it should and it appears that a transition on PA_6 induces the additional triggering.

I don't understand the PA_6 & PB_6 limitation as PB_6 is D10 & PA_6 is D12?

Regards, Abe

posted by Abraham Howell 11 May 2014

Just tried removing PA_6 and used PA_7 & PB_8, but the same behavior persists when two InterruptIns are implemented.

Regards, Abe

posted by Abraham Howell 11 May 2014

That limitation isn't relevant for you. But since I don't have it I cannot help you further, hopefully someone else who does have it can help.

posted by Erik - 11 May 2014

Erik, thanks for taking the time to help out. When I get time I'll dig into this some more. My experience is predominantly with PIC micros, so I am used to configuring registers and ISRs.

Regards, Abe

posted by Abraham Howell 11 May 2014