Read two pins with interrupts on falling edges, both pins has different vector interrupts.
In this case one pin has its corresponding vector interrupt in EXTI4_15_IRQn
but the other one is in EXTI2_3_IRQn
, the reason, well basically is the way the microcontroller has rooted the interrupts. But keep in mind they both calls the same callback
#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_3 | GPIO_PIN_4; /*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 a 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 );
/*Enable interrupt vector EXTI2_3_IRQ where the CPU will jump if a input change
happens on pins 2 or 3*/
HAL_NVIC_SetPriority( EXTI2_3_IRQn, 2, 0 ); /*set to the lowest of the four priorities*/
HAL_NVIC_EnableIRQ( EXTI2_3_IRQn );
while (1)
{
}
}
/* Even thou both pins has a differente ISR vectors both of them calls HAL_GPIO_EXTI_IRQHandler
from the EXTI4_15_IRQHandler or EXTI2_3_IRQHandler interrupt vectors*/
void HAL_GPIO_EXTI_Falling_Callback( uint16_t GPIO_Pin )
{
/*since the library only has a common function to attend both interrupt vectors we still
need to see which one causes the interrupt*/
if( GPIO_Pin == GPIO_PIN_3 )
{
/*if the change was on pin 3, do something*/
}
if( GPIO_Pin == GPIO_PIN_4 )
{
/*if the change was on pin 4, do something*/
}
}
ints.c
In this example we need to use different vectors
/*Declare interrupt service rutine as it is declare in startup_stm32g0b1xx.s file*/
void EXTI2_3_IRQHandler( void )
{
/*HAL library fucntions that attend interrupt on inputs*/
HAL_GPIO_EXTI_IRQHandler( GPIO_PIN_3 );
}
/*Declare interrupt service rutine as it is declare in startup_stm32g0b1xx.s file*/
void EXTI4_15_IRQHandler( void )
{
/*HAL library fucntions that attend interrupt on inputs*/
HAL_GPIO_EXTI_IRQHandler( GPIO_PIN_4 );
}