Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


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

  1. 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.

France

Hi,

I think your code has several flaws and could not work properly;

  • In kon_Off, you must save in some variable the state of the LED (on or off)
  • In the Color_Select code you must
    1. If the LED state is ON, shut down the currently on LED (with the current color)
    2. Change the color (as you did)
    3. If the LED was ON, light the new LED

Your current code may work only if yu change the color while the LED is OFF; otherwise LEDs behavior will be quite strange...

Bernard (Ac6)


 

Newest Forum Posts

  1. Можно ли установить камин на балконе или лоджии? by Grand3kpdErorb, 03:38
  2. reservation car service Seattle by Jamesprede, 2025-05-01 10:06
  3. Last day: drone bonus by Danielrug, 2025-04-19 16:55
  4. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  5. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  6. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  7. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  8. Insightful Perspectives on This Subject by davidsycle, 2025-03-04 05:45
  9. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  10. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05

Last-Modified Blogs