cancel
Showing results for 
Search instead for 
Did you mean: 

How to light up LED with a switch on the STM32 Board?

Member
Associate III

 while (1)

 {

HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);

if (HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin)) {

HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, SET);

}

 }

}

I am using the STM32 WB55 Nucleoboard, I am wondering why when I press the button on the board it doesn't light up the LED. Is something wrong with my code?

4 REPLIES 4

>>Is something wrong with my code?

Lacks context

Are clocks and pins properly initialized, can you change the register settings in the debugger, and set the button on/off

External or internal pull up on button?

if (HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin)) 
 HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
else
 HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Yes, the clocks and pins are initialized. How do you change the register settings on the debugger to on/off?
It will be an internal pull-up on button since the board has them attached.
LMI2
Lead

Try googling for instance HAL_GPIO_ReadPin

LMI2
Lead

This is not Arduino, you need more than just 4 lines

I recommend starting with a tool called CubeMx. With it you can create settings for pins, that is, what is input and what is output, and then create project, where you can add your own code. After that the code from Tesla DeLorean (Community Member)

should work.