2021-02-05 04:39 AM
Hello everyone, I am trying to read one pin with the HAL libraries, but i can not. This is my configuration:
1) I want to read the "BUTTON" pin ( PB3/PB4/PB5/PB6 )
2 I am doing this:
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Pin = GPIO_PIN_5;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_5)){
THE PROGRAM NEVER ENTERS HERE, NO MATERS THE STATE OF THE PIN
}
What i am doing wrong??
Thanks a lot!
Solved! Go to Solution.
2021-02-05 04:56 AM
no. LED2 is on GPIOA.
__HAL_RCC_GPIOB_CLK_ENABLE();
To get an idea how HAL works, don't hesitate generating code in STCubeIDE and studying it before rolling your own.
2021-02-05 04:46 AM
Did you enable the GPIOB clock?
2021-02-05 04:51 AM
I just did this :
LED2_GPIO_CLK_ENABLE();
But i dont know if this is for gpioB
2021-02-05 04:56 AM
no. LED2 is on GPIOA.
__HAL_RCC_GPIOB_CLK_ENABLE();
To get an idea how HAL works, don't hesitate generating code in STCubeIDE and studying it before rolling your own.