cancel
Showing results for 
Search instead for 
Did you mean: 

How to setup GPIOA_Pin12 and GPIOB_Pin12 to the same interrupt handler?

robertryberg9
Associate II
Posted on December 06, 2009 at 12:03

How to setup GPIOA_Pin12 and GPIOB_Pin12 to the same interrupt handler?

4 REPLIES 4
robertryberg9
Associate II
Posted on May 17, 2011 at 13:32

I'm changing a polling task to an interrupt driven solution.

One button is connected to GPIOA.Pin12 and the other to GPIOB.Pin12.

Q1:

Is it possible to set up both GPIOs to the same interrupt handler?

If so, could you point out what's incorrect in the code below?

Q2:

How in the interrupt handler detect the GPIO source (i.e. GPIOA or GPIOB?)

I've only found EXTI-functions to check active Pin..

When I use either GPIOA or GPIOB it is working fine.

Here follow parts of the code:

NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQChannel;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_KERNEL_INTERRUPT_PRIORITY;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOB, &GPIO_InitStructure);

GPIO_Init(GPIOC, &GPIO_InitStructure);

GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource12);

GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource12);

EXTI_InitStructure.EXTI_Line = EXTI_Line12;

EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;

EXTI_InitStructure.EXTI_LineCmd = ENABLE;

EXTI_Init(&EXTI_InitStructure);

//-------------------------------------------------------------------------

void rcc_config(void)

{

.

.

.

RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM4, ENABLE );

/* Enable GPIOA, GPIOB, GPIOC, ADC1, USART1 clocks

* AFIO registers are needed to know on which port each EXTI need to be.

*/

RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_ADC1 | RCC_APB2Periph_USART1, ENABLE );

//-------------------------------------------------------------------------

void button_IRQHandler_Pin10_Pin15(void)

{

if(EXTI_GetITStatus(EXTI_Line12) != RESET)

{

// do stuff..

EXTI_ClearITPendingBit(EXTI_Line12);

}

}

sofiene
Associate III
Posted on May 17, 2011 at 13:32

Hi robert,

For your first question I didn't check if you can do this: generate the same interrupt with two diffrent sources. But I can ask Q2:

If Q1 is feasable, in IRQ and after the EXI_Line_12 check, you can read the status of each pin to decide which was the source of the interrupt.

PS:

You mentionned that you are using GPIOA and GPIOB to generate the interrupts but in your code you configured GPIOC instead of GPIOA to generate the external interrupt. Just check it..

GPIO_Init(GPIOB, &GPIO_InitStructure);

GPIO_Init(GPIOC, &GPIO_InitStructure);

.....

...

GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource12);

GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource12);

B.R.

M3allem

[ This message was edited by: M3allem on 03-12-2009 17:54 ]

robertryberg9
Associate II
Posted on May 17, 2011 at 13:32

M3allem: Thanks for the reply.

The title is incorrect, I'm using GPIOB and GPIOC.

I thought (wrongly) that the EXTI_GetITStatus(EXTI_Line12) would return the Pin12's status of SET/RESET, but I still understand now that I still need to read the data bit by:

statusA = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_12);

statusB = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_12);

Thanks!

Re,

Robert.

[ This message was edited by: robert.ryberg on 04-12-2009 10:19 ]

tomas23
Associate II
Posted on May 17, 2011 at 13:32

All wrong, EXTI bit XX can be assigned ONLY to one GPIO unit. Check the body of EXTILineConfig and associated register description.

Moreover, EXTI_GetITStatus checks the pending bit, not the port itself.