cancel
Showing results for 
Search instead for 
Did you mean: 

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

Gnahore
Senior

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

1 ACCEPTED SOLUTION

Accepted Solutions
Gnahore
Senior

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?

View solution in original post

10 REPLIES 10
Stassen.C
ST Employee

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.

Gnahore
Senior

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?

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.

Stassen.C,

Yes, here is my code (attached file)

Thanks

 

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.

Gnahore,

Try using these 2 files instead copy and paste them in your src folder. It should work for the Blue Push button. I let you change the GPIO button to the one in your application.
Hope this resolves your issue

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.

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

Gnahore
Senior

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

thanks