cancel
Showing results for 
Search instead for 
Did you mean: 

external interrupt

XooM
Associate III

 

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
    if (GPIO_Pin == GPIO_PIN_1) 
        {
    	 uint32_t current_time = HAL_GetTick();  
    	 	   if ((current_time - last_interrupt_time) > 500)
    	 	 	 {
    	 		 last_interrupt_time = current_time;  		 	 
                         Button++;  
    	 	 	 }
        }
}

 

 

  while (1)
  {

	  if (Button== 2) {  
	          Button= 0;    
	       	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14,GPIO_PIN_SET)
	      }
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

 

 

 

Hello. The code I wrote with external interrupt does not work.

If I press the button with intervals shorter than 500ms, it should not detect these button bounces..
If I press the watch button for more than 500ms, I want it to detect it.
Even if I press the watch button for more than 500ms, the value of the button variable does not increase.

 

If I just write the code below, the button variable increases, but because of the button bounces, even though I want it to increase by +1, it increases like +5 to +10.

 

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
       if (GPIO_Pin == GPIO_PIN_1) 
        {
    	
    	 Button++;
    	 	 	
        }
}

 

Why aren't my codes at the beginning of the message working?

0 REPLIES 0