cancel
Showing results for 
Search instead for 
Did you mean: 

User button use

UniRob
Associate III

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 )

{

}

}

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Andrew Neil
Evangelist III

Please use this button to properly post source code:

AndrewNeil_0-1718636725648.png

 

 

 

 

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():

https://www.st.com/resource/en/user_manual/um2570-description-of-stm32g4-hal-and-lowlayer-drivers--stmicroelectronics.pdf

 

See also AN5315STM32Cube firmware examples for STM32G4 Series:

https://www.st.com/resource/en/application_note/an5315-stm32cube-firmware-examples-for-stm32g4-series-stmicroelectronics.pdf

https://www.st.com/en/embedded-software/stm32cubeg4.html#documentation

https://www.st.com/en/microcontrollers-microprocessors/stm32g431cb.html#documentation 

 

View solution in original post

2 REPLIES 2
Andrew Neil
Evangelist III

Please use this button to properly post source code:

AndrewNeil_0-1718636725648.png

 

 

 

 

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():

https://www.st.com/resource/en/user_manual/um2570-description-of-stm32g4-hal-and-lowlayer-drivers--stmicroelectronics.pdf

 

See also AN5315STM32Cube firmware examples for STM32G4 Series:

https://www.st.com/resource/en/application_note/an5315-stm32cube-firmware-examples-for-stm32g4-series-stmicroelectronics.pdf

https://www.st.com/en/embedded-software/stm32cubeg4.html#documentation

https://www.st.com/en/microcontrollers-microprocessors/stm32g431cb.html#documentation 

 

UniRob
Associate III

Perfect now is running.

Thank you.