cancel
Showing results for 
Search instead for 
Did you mean: 

two EXTI conflict

m_a_amirian
Associate II
Posted on June 12, 2016 at 08:51

Hi!

Im trying to use two EXTI on PE2 and PE3 pins simultaneously. Two push bottons are connected to these two pins with a pull-up resistor and a capacitor filter prohibitting debounce phenomenon. As shown in the code below, in one ISR ''h'' is increased and in the other ''n''. the problem is that when I press one of the bottoms both ''h'' and ''n'' increase multiple times. On oscope PE2 and PE3 signals are correct but the stm32f4 processor is unpredictable. I don't understand what is happening!

#include ''stm32f4xx.h''

EXTI_InitTypeDef   EXTI_InitStructure;

GPIO_InitTypeDef   GPIO_InitStructure;

NVIC_InitTypeDef   NVIC_InitStructure;

uint16_t n,h=0;

static void EXTI_Configuration(void);

int main(void)

{

  SystemInit(); 

//  SysTick_Config(SystemCoreClock/1000);

  EXTI_Configuration();

  while(1);

}

static void EXTI_Configuration(void)

{

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE , ENABLE);

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;  

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; 

  GPIO_InitStructure.GPIO_Pin =GPIO_Pin_2|GPIO_Pin_3;

  GPIO_Init(GPIOE, &GPIO_InitStructure);

  

  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource2);

  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource3);   

 

  EXTI_InitStructure.EXTI_Line = EXTI_Line2|EXTI_Line3;                              

  EXTI_InitStructure.EXTI_LineCmd = ENABLE;

  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;

  EXTI_Init(&EXTI_InitStructure);  

  

  NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);    

  

  NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;

  NVIC_Init(&NVIC_InitStructure);

}

void EXTI2_IRQHandler(void){

  if(EXTI_GetITStatus(EXTI_Line2) != RESET)

  {

    n++;

    EXTI_ClearITPendingBit(EXTI_Line2);    //Clear the  EXTI line 2 pending bit

  }

}

void EXTI3_IRQHandler(void){

  if(EXTI_GetITStatus(EXTI_Line3) != RESET)

  {

    h++;

    EXTI_ClearITPendingBit(EXTI_Line3);

  }

}

3 REPLIES 3
knielsen
Associate II
Posted on June 12, 2016 at 09:27

Hm, I would not expect a simple capacitor to be sufficient to prevent bounces on a pushbutton.

But if you meant that a single press on button 1 increments _both_ ''h'' and ''n'', then I would double-check the hardware for shorts.

BTW, you should declare the ''h'' and ''n'' counters as volatile when they are updated in an interrupt.

Hope this helps,

 - Kristian.

m_a_amirian
Associate II
Posted on June 12, 2016 at 13:07

Thanks for your reply Kristian!

I think parameter definition is not the point, since when i tried to set and reset PC10 in one ISR and PC11 in the other, this conflict happened again.

By the way what would you recommend to prevent bounce on a pushbotton?

Radosław
Senior II
Posted on June 12, 2016 at 17:49

buttons + external interrupts = stupidity,

Check buttons in timer interrupt in period 50-100ms.