2021-05-21 02:07 PM
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?
2021-05-21 02:20 PM
>>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);
2021-05-21 02:25 PM
2021-05-21 02:27 PM
Try googling for instance HAL_GPIO_ReadPin
2021-05-21 02:39 PM
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.