cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with multiple EXTI on the same Port

benedikt
Associate II
Posted on August 19, 2013 at 23:34

Hey guys !

I have a problem with my STM32F100 Board - I'd like to have PC.0 as EXTI_Line_0 and PC.1 as EXTI_Line_1. Here is my configuration:


EXTI_InitTypeDef EXTI_InitStructure; 

NVIC_InitTypeDef NVIC_InitStructure;

GPIO_InitTypeDef GPIO_InitStructure;


/* Enable GPIO Port C */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); 


/* PC.12 as Output (LED) */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_Init(GPIOC, &GPIO_InitStructure);


/* Inputs and EXTI */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 ;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; 

GPIO_Init(GPIOC, &GPIO_InitStructure); 


/* Selects PC Pins as EXTI Lines */

GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource0);

GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource1);


/* Configure two bit for preemption priority */

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);


/* EXTI */

NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQChannel;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);


NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQChannel;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);


EXTI_InitStructure.EXTI_Line = EXTI_Line0; // PC.0

EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; 

EXTI_InitStructure.EXTI_LineCmd = ENABLE;

EXTI_Init(&EXTI_InitStructure);


EXTI_InitStructure.EXTI_Line = EXTI_Line1; // PC.1

EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; 

EXTI_InitStructure.EXTI_LineCmd = ENABLE;

EXTI_Init(&EXTI_InitStructure);

The IRQ Handlers are configured to do nothing but toggle a LED:


void EXTI0_IRQHandler(void)

{

if(EXTI_GetITStatus(EXTI_Line0) != RESET)

// Ensure get EXTI line 0 pending bit

{


GPIO_WriteBit(GPIOC,GPIO_Pin_12, 1);


EXTI_ClearITPendingBit(EXTI_Line0);

// Clear the EXTI line 0 pending bit

}

}



void EXTI1_IRQHandler(void)

{

if(EXTI_GetITStatus(EXTI_Line1) != RESET)

// Ensure get EXTI line 1 pending bit

{


GPIO_WriteBit(GPIOC,GPIO_Pin_12, 0);


EXTI_ClearITPendingBit(EXTI_Line1);

// Clear the EXTI line 1 pending bit

}

}

My problem now is, that EXTI1 IRQ handler is never executed, and EXTI0 IRQ is executed by PC.1! How is this possible? Did I forget something in the configuration? I am assuming that the wiring is correct. thanks in advance
5 REPLIES 5
Posted on August 20, 2013 at 01:28

  /* Enable AFIO clock */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

Otherwise doesn't look unreasonable

You do look to be using an older firmware library.

  NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;

  NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;

What are the pin states actually doing? Do you need pull up/down settings, or have them externally, diagram circuit.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
benedikt
Associate II
Posted on August 20, 2013 at 19:45

Now I have the same code just with AFIO Clock enabled.

Both Interrupts are now working, but each Interrupt opens both IRQ Handlers. It's own first, and then the other one. 

Do I have something wrong with my board? Resistance between PC.0 and PC.1 is >0,7MOhm - so this should be OK.

When I put a Voltage of 3V3 on PC.0 - PC.1 is under 0,05V and vice versa.

Design is as followed:

0690X00000602mlQAA.jpg

Two Sensors (24VDC) with each a resistor and a Z-Diode

EDIT:

The Programm is also going through the

if(EXTI_GetITStatus(EXTI_Line0) != RESET)

part - also in the wrong IRQ Handler - wich confuses me?!?
aa_talaat
Associate II
Posted on October 28, 2014 at 20:15

Hi,

Were you able to find out why pressing one key generates an interrupt on the correct pin but also on the other pin?

I am facing something similar using PB12-15 on EXTI15_10_IRQHandler

Pressing PB12 for example generated an interrupt on this one as well as the others.

Posted on October 28, 2014 at 20:57

Are you seeing this on an STM32F1 also?

I haven't tried this but looks like it should be easy enough to replicate/validate
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
aa_talaat
Associate II
Posted on October 29, 2014 at 04:04

Hi,

I am seeing this problem on the STM32VL discovery board. Once in the EXTI ISR, I disable the interrupt and clear the pending bit. Is this the right way to disable the interrupt?

void EXTI15_10_IRQHandler(void)
{
DisableButton_IRQ(EXTI15_10_IRQn); // Disable interrupt to avoid any debounce effects
if(EXTI_GetITStatus(EXTI_Line12) != RESET) {
EXTI_ClearITPendingBit(EXTI_Line12); // Clear the EXTI line 12 pending bit
keyIndex=0;
keyPin = KEYPAD_COL1;
} else
=====================
void DisableButton_IRQ(uint8_t interupt_num){
NVIC_InitTypeDef NVIC_InitStructure;
/* Disable and set EXTI10_15 Interrupt to the lowest priority */
NVIC_InitStructure.NVIC_IRQChannel = interupt_num;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
NVIC_Init(&NVIC_InitStructure);
}