cancel
Showing results for 
Search instead for 
Did you mean: 

Problem READING PIN

NFahi.1
Associate II

Hello everyone, I am trying to read one pin with the HAL libraries, but i can not. This is my configuration: 

0693W000007E72oQAC.jpg 

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!

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

3 REPLIES 3
KnarfB
Principal III

Did you enable the GPIOB clock?

NFahi.1
Associate II

I just did this :

 LED2_GPIO_CLK_ENABLE();

But i dont know if this is for gpioB

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.