Two externals interrupts EXTI0 and EXTI9_5 doesn't work well
Hi everybody,
I try to use two buttons on external interrupts on two different lines.
I wired a RGB diode and more.
The aim is to use the PA_0 button to select one of three colors, and PA_6 button to switch a color.
I try to use two buttons on external interrupts on two different lines.
I wired a RGB diode and more.
The aim is to use the PA_0 button to select one of three colors, and PA_6 button to switch one color.
Unfortunately, the buttons use both indifferently functions of the canals. If I press the “Select” button to increment the variable “ColorSelect” she increments, but she is also a switch for the LED colors.the other button as it passes through the two functions.
main.c
- include “stm32f3xx_hal.h”
/* Private function prototypes -------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
/* Private function prototypes -------------------*/
void Color_Select(void);
void kon_Off(void);
/*r=0;g=1;b=2*/
int ColorSelect=0;
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
while (1)
{
}
}
void EXTI0_IRQHandler(void)
{
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
}
void EXTI9_5_IRQHandler(void)
{
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_6);
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){
if (GPIO_Pin == GPIO_PIN_0) {
Color_Select();
}
if (GPIO_Pin==GPIO_PIN_6) {
kon_Off();
}
}
void Color_Select(void)
{
ColorSelect++;
if (ColorSelect>2) {
ColorSelect = 0;}
}
void kon_Off(void){
switch (ColorSelect) {
case 0:
HAL_GPIO_TogglePin(GPIOA,red_Pin);
break;
case 1:
HAL_GPIO_TogglePin(GPIOA,green_Pin);
break;
case 2:
HAL_GPIO_TogglePin(GPIOA,blue_Pin);
break;
}
}
void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin : PF1 */
GPIO_InitStruct.Pin = GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
/*Configure GPIO pins : select_Pin onOff_Pin */
GPIO_InitStruct.Pin = select_Pin|onOff_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
/*Configure GPIO pins : green_Pin red_Pin blue_Pin */
GPIO_InitStruct.Pin = green_Pin|red_Pin|blue_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, green_Pin|red_Pin|blue_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : VCP_TX_Pin VCP_RX_Pin */
GPIO_InitStruct.Pin = VCP_TX_Pin|VCP_RX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
___
stm32f3xx_hal_gpio.c
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
{
/* EXTI line interrupt detected */
if(__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)
{
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
HAL_GPIO_EXTI_Callback(GPIO_Pin);
}
}
_
Could you help me understand what I missed? Thank you.