Read two pins when they change from high to low, both pins shares the same interrupt vector.
The example assume an external pull up is connected to each pin. The library uses only one HAL_GPIO_EXTI_Falling_Callback
function for all the pins,s o parameter GPIO_Pin
needs to be use to deduce which pin causes the interrupt
#include "bsp.h"
int main( void )
{
GPIO_InitTypeDef GPIO_InitStruct; /*gpios initial structure*/
HAL_Init(); /*Init HAL library*/
__HAL_RCC_GPIOB_CLK_ENABLE(); /*Enable clock on port B*/
GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_6; /*pins to set as output*/
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; /*input mode with interrupts enable on falling edge*/
GPIO_InitStruct.Pull = GPIO_NOPULL; /*no pull-up niether pull-down*/
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; /*pin speed*/
/*use the previous parameters to set configuration on pin B5*/
HAL_GPIO_Init( GPIOB, &GPIO_InitStruct );
/*Enable interrupt vector EXTI4_15_IRQ where the CPU will jump if an input change
happens on pins 4 to 15*/
HAL_NVIC_SetPriority( EXTI4_15_IRQn, 2, 0 ); /*set to the lowest of the four priorities*/
HAL_NVIC_EnableIRQ( EXTI4_15_IRQn );
while (1)
{
}
}
/* when any of the pins changes from high to low this function will be called by HAL_GPIO_EXTI_IRQHandler
which is in turn called from the EXTI4_15_IRQHandler interrupt vector*/
void HAL_GPIO_EXTI_Falling_Callback( uint16_t GPIO_Pin )
{
/*since both pins shares the same insterrupt vector we need to see which one cause the interrupt*/
if( GPIO_Pin == GPIO_PIN_5 )
{
/*if the change was on pin 5, do something*/
}
if( GPIO_Pin == GPIO_PIN_6 )
{
/*if the change was on pin 5, do something*/
}
}
ints.c
it is necessary to call the HAL_GPIO_EXTI_IRQHandler
for both pins
/*Declare interrupt service rutine as it is declare in startup_stm32g0b1xx.s file*/
void EXTI4_15_IRQHandler( void )
{
/*HAL library functions that attend interrupt on inputs*/
/*first we called to see if pin 5 triggers the interrupt*/
HAL_GPIO_EXTI_IRQHandler( GPIO_PIN_5 );
/*then called again to see if pin 6 triggered*/
HAL_GPIO_EXTI_IRQHandler( GPIO_PIN_6 );
}