AnsweredAssumed Answered

two EXTI conflict

Question asked by a.m.a on Jun 12, 2016
Latest reply on Jun 12, 2016 by dembek.radoslaw.001
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);
  }
}

Outcomes