Question

i'm writing a program to decode multiple ppm signals from a rc receiver for a stm32f103 microcontroller. But in a cortex-m3 microcontroller multiple I/O pins are mapped on the same external interrupt controller. Is it possible to retrieve which I/O pin triggered the interrupt in the interrupt handler?

Was it helpful?

Solution

Sorry, but you can't have multiple pins, from different ports but with the same pin number (e.g. PA0 and PD0, or PC10 and PE10), trigger an interrupt in the STM32. You may think you're doing that, but what's happening is that a single pin is triggering the interrupt, and you may think the others are triggering the interrupt as well, but you're mistaken.

I'll explain why, but don't take my word for it -- you can try it on your own board and you'll see that only, e.g. PA0 will trigger the interrupt and not PB0, PC0, etc. By default it's indeed the PAx pins that do, unless you used the GPIO_EXTILineConfig() function from the Standard Peripheral Library or changed the AFIO_EXTICRx registers described below.

Refer to the AFIO_EXTICRx, x = { 1, 2, 3, 4 }, registers on the reference manual (RM0008). For example, here's the explanation text for bits 15:0 of AFIO_EXTICR1:

EXTIx[3:0]: EXTI x configuration (x= 0 to 3)

These bits are written by software to select
the source input for EXTIx external interrupt.
Refer to Section 10.2.5: External
interrupt/event line mapping on page 200

0000: PA[x] pin
0001: PB[x] pin
0010: PC[x] pin
0011: PD[x] pin
0100: PE[x] pin
0101: PF[x] pin
0110: PG[x] pin

So as you can see, you have to choose one of the ports (PA, PB, PC, PD, PE, PF or PG). You can't have multiple ports enabled because it's not a bitfield.

If you're still in doubt, have a look at Figure 21 of section 10.2.5 of the manual on page 201 (at least that's the figure and page number on my version of the manual). A multiplexer controls the signal that's passed to the EXTIx lines, and that multiplexer is controlled by the AFIO_EXTICRx registers mentioned above. Since it's a multiplexer and not an OR gate, you can't trigger the interrupt from multiple ports.

OTHER TIPS

Yes, for example:

if (EXTI_GetITStatus(EXTI_Line0) != RESET)
{
    // Do here whatever you want to do
    EXTI_ClearITPendingBit(EXTI_Line0);
}

You can find all the relevant external-interrupt-line definitions in file stm32f1xx_exti.h.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top