Question
HAL_GPIO_ReadPin is always returning High. Why is it not working?
Posted on November 21, 2014 at 19:59
I'm having problems reading the state of a GPIO pin.
If I use the HAL function to read the pin, it always returns that the pin is high. But if I read it manually, then it works properly and correctly returns the actual value of the pin state. This is the relevant code:// Configure and enable GPIO for PA15
GPIO_InitTypeDef GPIO_InitStructure;
// Enable GPIOA clock
__GPIOA_CLK_ENABLE();
// Configure PA15 pin as input floating. Pull Down because we want to detect a high level.
GPIO_InitStructure.Pin = GPIO_PIN_15;
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
GPIO_InitStructure.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
// Set the orange LED to reflect the status of PA
// This does NOT work. It always returns that PA15 is high.
// if (HAL_GPIO_ReadPin(GPIOA, 15) == GPIO_PIN_SET)
// This DOES work.
if
(GPIOA->IDR & 0x8000)
{
BSP_LED_On(LED3);
}
else
{
BSP_LED_Off(LED3);
}
Any ideas as to what the problem is? For what it's worth, I'm using STM32CubeF4 1.3.0.