Read a pin using interrupts on edge detection
Since pin 5 is been used it is necessary to enable the vector interrupt corresponding that pin, ion this particular case is the one identified by EXTI4_15_IRQn
and both callback function are in use
#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; /*pin to set as output*/
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; /*input mode with interrupts enable on falling and rising edges*/
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 );
while (1)
{
}
}
/* when the pin 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 )
{
/*do something while still in the ISR, the parameter GPIO_Pin
received by the callback function can be use to corroborate
the pin that cause the interrupt*/
}
/* when the pin changes from low to high 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_Rising_Callback( uint16_t GPIO_Pin )
{
/*do something while still in the ISR, the parameter GPIO_Pin
received by the callback function can be use to corroborate
the pin that cause the interrupt*/*/
}
ints.c
/*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_5 );
}