2024-06-17 07:59 AM
How to use in main.c the user button of B-G431B-ESC1 board ?
I want to togle the position each time I press (amd release) the button.
Waiting for target position completed and than I can press the button again.
I have selected the PC10 pin in MXCube that originate this code in main.c:
/*Configure GPIO pin : PC10 */
GPIO_InitStruct.Pin = GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
in main I write this code, but nothing happen.
Where is the problem ?
if ( GPIO_PIN_10 == 0 )
{
while (GPIO_PIN_10 == 0)
{
}
Pos = MC_GetCurrentPosition1();
if ( Pos == 0.0 )
Pos = 314.159;
else
Pos = 0.0;
MC_ProgramPositionCommandMotor1(Pos,1.5);
while ( MC_GetCurrentPosition1() != Pos )
{
}
}
Solved! Go to Solution.
2024-06-17 08:10 AM - edited 2024-06-17 08:13 AM
Please use this button to properly post source code:
if ( GPIO_PIN_10 == 0 )
{
GPIO_PIN_10 is a constant: it just identifies the pin - it does not give you the current state of the pin.
To read the current value of a pin, use HAL_GPIO_ReadPin():
See also AN5315, STM32Cube firmware examples for STM32G4 Series:
https://www.st.com/en/embedded-software/stm32cubeg4.html#documentation
https://www.st.com/en/microcontrollers-microprocessors/stm32g431cb.html#documentation
2024-06-17 08:10 AM - edited 2024-06-17 08:13 AM
Please use this button to properly post source code:
if ( GPIO_PIN_10 == 0 )
{
GPIO_PIN_10 is a constant: it just identifies the pin - it does not give you the current state of the pin.
To read the current value of a pin, use HAL_GPIO_ReadPin():
See also AN5315, STM32Cube firmware examples for STM32G4 Series:
https://www.st.com/en/embedded-software/stm32cubeg4.html#documentation
https://www.st.com/en/microcontrollers-microprocessors/stm32g431cb.html#documentation
2024-06-17 11:16 PM
Perfect now is running.
Thank you.