cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple GPIO interrupts firing when only one is triggered

DSabo
Associate III

I am using the STM32 Nucleo F411RE, and have 5 GPIO pins set up as inputs, each set to trigger an interrupt on the rising and falling edge, configured to use the internal pull down.

However, what I am finding is that causing a level change on one of the pins is triggering an interrupt for all of them.

At first I thought it might be cross talk between the pins, but I added external pull down resistors of 10k to ground and the issue is still there.

So I'm assuming either my configuration is wrong, or my interrupt handlers are, but I don't see any issue..

#define PEDAL_CLAMP_Pin GPIO_PIN_2
#define PEDAL_CLAMP_GPIO_Port GPIOC
#define PEDAL_FORWARD_Pin GPIO_PIN_3
#define PEDAL_FORWARD_GPIO_Port GPIOC
#define PEDAL_REVERSE_Pin GPIO_PIN_6
#define PEDAL_REVERSE_GPIO_Port GPIOC
#define PEDAL_UNCLAMP_Pin GPIO_PIN_8
#define PEDAL_UNCLAMP_GPIO_Port GPIOC
#define SWITCH_PRESSURE_Pin GPIO_PIN_10
#define SWITCH_PRESSURE_GPIO_Port GPIOC
 
void MX_PedalSwitches_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStruct = {0};
	BaseType_t createStatus = pdFAIL; // Init to fail to be safe
 
	/* GPIO Ports Clock Enable */
	__HAL_RCC_GPIOC_CLK_ENABLE();
	__HAL_RCC_GPIOH_CLK_ENABLE();
	__HAL_RCC_GPIOA_CLK_ENABLE();
	__HAL_RCC_GPIOB_CLK_ENABLE();
 
	GPIO_InitStruct.Pin = PEDAL_CLAMP_Pin|PEDAL_UNCLAMP_Pin|PEDAL_FORWARD_Pin|PEDAL_REVERSE_Pin
						  |SWITCH_PRESSURE_Pin;
	GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
	GPIO_InitStruct.Pull = GPIO_PULLDOWN;
	HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 
	HAL_NVIC_SetPriority(EXTI15_10_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY, 0);
	HAL_NVIC_SetPriority(EXTI3_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY, 0);
	HAL_NVIC_SetPriority(EXTI2_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY, 0);
	HAL_NVIC_SetPriority(EXTI9_5_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY, 0);
 
	HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
	HAL_NVIC_EnableIRQ(EXTI3_IRQn);
	HAL_NVIC_EnableIRQ(EXTI2_IRQn);
	HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
 
	createStatus = xTaskCreate(SwitchDebounceTask, "Pedal Switch task", configMINIMAL_STACK_SIZE,(void*) NULL,1, &switchTaskHandle);
	configASSERT(createStatus == pdPASS);
}
 
void EXTI2_IRQHandler(void)
{
	BaseType_t xHigherPriorityTaskWoken = pdFALSE;
 
	uint32_t notifyValue = 0;
 
	if(__HAL_GPIO_EXTI_GET_IT(PEDAL_CLAMP_Pin) != RESET)
	{
		notifyValue = 1 << PEDAL_CLAMP_PRESSED;
 
		xTaskNotifyFromISR(switchTaskHandle, notifyValue, eSetBits, &xHigherPriorityTaskWoken);
	}
 
	__HAL_GPIO_EXTI_CLEAR_IT(PEDAL_CLAMP_Pin);
 
	portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
 
void EXTI3_IRQHandler(void)
{
	BaseType_t xHigherPriorityTaskWoken = pdFALSE;
	uint32_t notifyValue = 0;
 
	if(__HAL_GPIO_EXTI_GET_IT(PEDAL_FORWARD_Pin) != RESET)
	{
		notifyValue = 1 << PEDAL_FORWARD_PRESSED;
		xTaskNotifyFromISR(switchTaskHandle, notifyValue, eSetBits, &xHigherPriorityTaskWoken);
 
    }
 
	__HAL_GPIO_EXTI_CLEAR_IT(PEDAL_FORWARD_Pin);
 
	portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
 
void EXTI9_5_IRQHandler(void)
{
	BaseType_t xHigherPriorityTaskWoken = pdFALSE;
	uint32_t notifyValue = 0;
 
	if(__HAL_GPIO_EXTI_GET_IT(PEDAL_REVERSE_Pin) != RESET)
	{
		notifyValue = 1 << PEDAL_REVERSE_PRESSED;
 
		xTaskNotifyFromISR(switchTaskHandle, notifyValue, eSetBits, &xHigherPriorityTaskWoken);
 
		__HAL_GPIO_EXTI_CLEAR_IT(PEDAL_REVERSE_Pin);
    }
 
	if(__HAL_GPIO_EXTI_GET_IT(PEDAL_UNCLAMP_Pin) != RESET)
	{
		notifyValue = 1 << PEDAL_UNCLAMP_PRESSED;
 
		xTaskNotifyFromISR(switchTaskHandle, notifyValue, eSetBits, &xHigherPriorityTaskWoken);
 
		__HAL_GPIO_EXTI_CLEAR_IT(PEDAL_UNCLAMP_Pin);
    }
 
	portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
 
void EXTI15_10_IRQHandler(void)
{
	BaseType_t xHigherPriorityTaskWoken = pdFALSE;
 
	uint32_t notifyValue = 0;
 
	HAL_EXTI_IRQHandler(&H_EXTI_13);
 
	if(__HAL_GPIO_EXTI_GET_IT(SWITCH_PRESSURE_Pin) != RESET)
	{
		notifyValue = 1 << SWITCH_PRESSURE_PRESSED;
 
		xTaskNotifyFromISR(switchTaskHandle, notifyValue, eSetBits, &xHigherPriorityTaskWoken);
 
		__HAL_GPIO_EXTI_CLEAR_IT(SWITCH_PRESSURE_Pin);
    }
 
	portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}

10 REPLIES 10
CWies.1
Associate III

Was there any solution to this issue. We are facing the same issue in our circuit. With the nucleo board, it does not happen, with the same circuit but different STM32. On our custom baord there is a STM32L432KBU6 and on the nucleo it is STM32L476RG. But I guess it should work the same. The debouncing circuit is exactly as with the nucleo. Any hint would be helpful.