cancel
Showing results for 
Search instead for 
Did you mean: 

EXTIn: n > 4

cmcquaid
Associate
Posted on March 29, 2012 at 07:30

I have one external interrupt working fine, but I need to add a few more and I'm failing to understand how it all maps out.

The one I have implemented is on PA3 and the ISR is void EXTI3_IRQHandler(void). 

Although the UM says that almost all pins on all ports can be used as EXTIs, there are only 5 EXTI IRQs. There does not seem to be an explicit way to map a pin to an ISR,

 so is it the case that only pins 0..4 on a port can be used for EXTI?

If not, I would be grateful if someone could illustrate how to do so.

(Using STM32F4Discovery/Keil with peripheral library 1.1.0)

2 REPLIES 2
Posted on March 29, 2012 at 15:11

Although the UM says that almost all pins on all ports can be used as EXTIs, there are only 5 EXTI IRQs. There does not seem to be an explicit way to map a pin to an ISR,  so is it the case that only pins 0..4 on a port can be used for EXTI?

No, it means that some of your EXTI interrupt handlers (5-9) and (10-15) will need to differentiate the source as the first step of processing/dispatching the request.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cmcquaid
Associate
Posted on March 30, 2012 at 19:57

Thanks for pointing me in the right direction, Clive.

I had seen the first five handlers:

EXTI0_IRQHandler ; EXTI
Line0 
EXTI1_IRQHandler ; EXTI Line1 
EXTI2_IRQHandler ; EXTI Line2 
EXTI3_IRQHandler ; EXTI Line3 
EXTI4_IRQHandler ; EXTI Line4 

... but I missed the other two:

EXTI9_5_IRQHandler ; External Line[9:5]s 
EXTI15_10_IRQHandler ; External Line[15:10]s

For the benefit of anyone else in the same situation, I've stripped the relevant code out of my app. I believe it is complete, but I have not tested the isolated fragment. Curiously, my EXTI3 interrupt worked fine without enabling the SYSCFG clock.

void config(void){
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
/* SYSCFG clock enable */ 
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* external int config register is in SYSCFG */
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource12);
/* GPIOB clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
/* configure GPIO pin as input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* configure PB12 as interrupt on falling edge */
EXTI_InitStructure.EXTI_Line = EXTI_Line12; 
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure); 
/* Configure and enable EXTI interrupt on PB12 */
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
} 
void EXTI15_10_IRQHandler(void){
// did we get here due to falling edge on PB12
if(EXTI_GetITStatus(EXTI_Line12)){
EXTI_ClearITPendingBit(EXTI_Line12);
}else if( /* test for another interrupt */){
}
}