stm32 sets the external interrupt and whether the key needs to be removed

Turn from https://www.amobbs.com/thread-5627222-1-1.html?_dsign=7e90158f

For example, my setting is: the external interrupt is in falling edge mode, the input of GPIO is in pull-up mode, and the interrupt response is in reverse state at the output end -- the small light is on and off. When you press the key, there should be a falling edge. Press to turn off the light, and then press to turn on the light.  

But the phenomenon is: sometimes it can be on, but sometimes the status of the small light remains the same. What's the reason? Do you want to shake?
(beginner, wildfire program)
 

//Interrupt response function
void EXTI9_5_IRQHandler(void)
{
        if(EXTI_GetITStatus(EXTI_Line5) != RESET) //Make sure the EXTI Line interrupt is generated
        {
                // LED1 negates 
                GPIO_WriteBit(GPIOC, GPIO_Pin_3, 
                        (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_3))));
                EXTI_ClearITPendingBit(EXTI_Line5);     //Clear interrupt flag bit
        }  
}

 

//Interrupt initialization settings
static void NVIC_Configuration(void)
{
          NVIC_InitTypeDef NVIC_InitStructure;
  
          /* Configure one bit for preemption priority -Priority set to first level*/
          NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
        
         /***********Note the interrupt vector of pin 5 of each port is the same************************/ 
          /* Configure P[A|B|C|D|E]5 as the interrupt source */
          NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
          NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
          NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
          NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
          NVIC_Init(&NVIC_InitStructure);
}
//Interrupt function settings
void EXTI_PE5_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure; 
        EXTI_InitTypeDef EXTI_InitStructure;

        /* config the extiline(PE5) clock and AFIO clock */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO,ENABLE);
                                                                                                
        /* config the NVIC(PE5) */
        NVIC_Configuration();

        /* EXTI line gpio config(PE5) */        
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;       
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;         // Pull up input
          GPIO_Init(GPIOE, &GPIO_InitStructure);

        /* EXTI line(PE5) mode config */
        GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource5); 
          EXTI_InitStructure.EXTI_Line = EXTI_Line5;                                                        //The combination of external interrupt lines should be pin number
          EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;                                     //Generally, this interrupt mode is used
          EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;                                         //Falling edge interrupt
          EXTI_InitStructure.EXTI_LineCmd = ENABLE;                                                        //Interrupt enable
          EXTI_Init(&EXTI_InitStructure); 
                                
}

 

 

 

Posted by dineshsjce on Fri, 06 Dec 2019 17:45:17 -0800