For the STM32WBA65I-DK1 an external button (e.g. the center button of the blue joystick B1) would need to be handled either by GPIO polling or via GPIO EXTI interrupt configuration.
For a simple button input, polling is often the more practical approach. It avoids the additional interrupt load caused by contact bounce and is generally easier to implement and validate.
You could use one of the following methods:
- Polling: if its frequency is chosen appropriately, explicit debouncing may not be necessary for very simple applications. However, for a more robust solution, a small software debounce filter is usually recommended.
- Interrupts: a valid approach when a fast, event-driven response is required. In that case, it is best practice to keep the ISR very short and handle the actual button action in the main context or in a task.
If you still want to try it with an interrupt, you can define the USER_Button (PA3) as EXTI with falling edge (there is already an external pull-ip R56) and enable EXTI3 in the NVIC. The EXTI callback can then be used to set a flag in software, while the actual button action is handled in the main loop:
/* USER CODE BEGIN PV */
volatile uint8_t user_button_pressed = 0; // example flag
/* USER CODE END PV */
/* USER CODE BEGIN 0 */
void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)
{
if (GPIO_Pin == GPIO_PIN_3) user_button_pressed = 1;
}
/* USER CODE END 0 */
In your while loop you could add something like:
while (1)
{
if (user_button_pressed)
{
user_button_pressed = 0; // reset the flag
// ... some button action ...
}
}
If you also want to use the four other buttons on the blue joystick B1, then instead of the method described below, analogue polling of all 5 buttons via the ADC is more appropriate.
Hope that helps?
Regards
/Peter