Skip to main content
Senior
August 23, 2023
Solved

How to turn on/off the user led by using an external button on a breadboard?

I'm using the nucleo-f302r8 and I want to turn on then turn of the user led (the ones on the stm32 board) thanks to a push-button on my personal breadboard. How to achieve this? 

Hardware : a nucleo-f302r8, a breadboard, a push-button arduino, 2 male-female wires

Sofware : STM32CubeIDE

This topic has been closed for replies.
GnahoreBest answer
Senior
August 23, 2023

I may have solved my issue by doing this : checking if I connected the right pin to the breadboard, enabled the right EXTI lines interrupts in the ioc file then remove the delay from HAL_GPIO_EXTI_Callback() by making a flag like showing in the following post :Interrupt Mode HAL Delay - STMicroelectronics Community

However the delay time is way too long. My led is on for more than 2000ms.. why is that?

10 replies

Stassen.C
ST Employee
August 23, 2023

Hello Gnahore,

Assuming that you connected you push button to your nucleo-f302r8 (you can find a lot of tutorial online if you need), you can use the STM32cubeF3 found here.
In this cube package, you have a dedicated example on how to toggle a led using a push button in interrupt mode.
This should help you !

Regards,
Stassen

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
GnahoreAuthor
Senior
August 23, 2023
Stassen.C
ST Employee
August 23, 2023

Gnahore,

Your link is not working here, could you please attach your code here or give me a working link to your project so that I can help?

Regards,
Stassen

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
GnahoreAuthorBest answer
Senior
August 23, 2023

I may have solved my issue by doing this : checking if I connected the right pin to the breadboard, enabled the right EXTI lines interrupts in the ioc file then remove the delay from HAL_GPIO_EXTI_Callback() by making a flag like showing in the following post :Interrupt Mode HAL Delay - STMicroelectronics Community

However the delay time is way too long. My led is on for more than 2000ms.. why is that?

Stassen.C
ST Employee
August 23, 2023

Gnahore,

You have a working example in STM32Cube_FW_F3_V1.11.4\Projects\STM32F302R8-Nucleo\Examples\GPIO\GPIO_EXTI project. In this example you will see that the green led is toggled through the blue push button on your nucleoF302r8.

You can use this code as a base. You just need to change the push button GPIO to yours and making sure it is correctly configured.

Regards,
Stassen

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
GnahoreAuthor
Senior
August 23, 2023

Stassen.C,

Thank you I didn't realized there were examples. I did something similar as the example however the example doesn't use HAL_Delay(). In my next step I won't use the inbuilt led anymore but a motor (with the x-nucleo-ihm08m1). I would like to turn the motor on by pressing my button (breadboard), let it run for 3s then stop by itself. I will need to use HAL_Delay() associated with EXTI interrupt

GnahoreAuthor
Senior
August 29, 2023

update : I don't need the delay anymore. All problem solved.

thanks

Stassen.C
ST Employee
September 5, 2023

Great to hear Gnahore!

Have a nice day and please if your question is answered, please close this topic by clicking "Accept as Solution".

Regards,
Stassen

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.