Question
how do I fix an interrupt that fires multiple times on EXTI4-15
Hey,
I am using nucleo F030R8 om window os.
I connected buttons to the board and i proggramted that each push will trigger an interupt(rising and faling). However many times i can see the the unterupt callback function is triggerd twice(2 calls for one edge),for instance tow times for the rising and tow times for the falling. insted only tow(1 for falling, 1 for rising).
I red on the internet that maybe uts is something with the PR register..
I want to figure out the reason behind it. Could someone kindly explain?
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
HAL_NVIC_DisableIRQ(EXTI4_15_IRQn);
printf(
"%s : %d :--------- Inside interrupt handler function - HAL_GPIO_EXTI_Callback------- \r\n",
__FUNCTION__, __LINE__);
uint16_t selectedPin;
GPIO_TypeDef *selectedPort;
int position = 0;
switch (GPIO_Pin) {
case Button1_Pin: {
//Button 1 Press/release
printf("%s : %d : Button 1 Press/release \r\n", __FUNCTION__, __LINE__);
selectedPin = Button1_Pin;
selectedPort = Button1_GPIO_Port;
position = 1;
break;
}
case Button2_Pin: {
// //Button 2 Press/release
printf("%s : %d : Button 2 Press/release \r\n", __FUNCTION__, __LINE__);
selectedPin = Button2_Pin;
selectedPort = Button2_GPIO_Port;
position = 2;
break;
}
case Button3_Pin: {
//Button 3 Press/release
printf("%s : %d : Button 3 Press/release \r\n", __FUNCTION__, __LINE__);
selectedPin = Button3_Pin;
selectedPort = Button3_GPIO_Port;
position = 3;
break;
}
case Button4_Pin: {
//Button 4 Press/release
printf("%s : %d : Button 4 Press/release \r\n", __FUNCTION__, __LINE__);
selectedPin = Button4_Pin;
selectedPort = Button4_GPIO_Port;
position = 4;
break;
}
}
if (position > 0) {
GPIO_PinState state = HAL_GPIO_ReadPin(selectedPort, selectedPin);
int i;
//Bouncing
for (i = 0; i < 15; i++) {
sysSleep(1);
if (state != HAL_GPIO_ReadPin(selectedPort, selectedPin)) {
printf(
"%s : %d :********Bouncing!!********\r\nExiting HAL_GPIO_EXTI_Callback function\r\n ",
__FUNCTION__, __LINE__);
HAL_NVIC_ClearPendingIRQ(EXTI4_15_IRQn);
HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);
return;
}
}
if (state == GPIO_PIN_SET) {
debug("Pin state : %d \r\n", GPIO_PIN_SET);
sendAsyncInput(position, GPIO_PIN_SET);
} else {
debug("Pin state is = %d \r\n", GPIO_PIN_RESET);
sendAsyncInput(position, GPIO_PIN_RESET);
}
HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);
}
}