FreeRTOS polling button on STM32F11

laskar01 wrote on Sunday, February 07, 2016:

Hi, I have this initialization for a button

/*Configure GPIO pin : B1_Pin */
  GPIO_InitStruct.Pin = B1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;//GPIO_MODE_EVT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);

Why is the button always read as 1, regardless if the button is pushed or not, has an onboard pull-upresistor
if(HAL_GPIO_ReadPin(GPIOx, B1_Pin == 0)){...

heinbali01 wrote on Monday, February 08, 2016:

Hi Lasse,

Don’t you have a typo here?

if(HAL_GPIO_ReadPin(GPIOx, B1_Pin == 0)){...

( look at ‘B1_Pin == 0’ which probably evaluates to 0 )

The parameters of HAL_GPIO_ReadPin() are:

	GPIO_PinState HAL_GPIO_ReadPin(
        GPIO_TypeDef* GPIOx,
        uint16_t GPIO_Pin );

For example:

if( HAL_GPIO_ReadPin( B1_GPIO_Port, B1_Pin ) == 0 )
{
}
else
{
}

Regards.

rtel wrote on Monday, February 08, 2016:

With respect, this is a FreeRTOS forum, not a general programming forum, and to keep this resource valuable to our users it is important this remains the case. Your question does not appear to be related to FreeRTOS in any way, so in future I would appreciate it if you were to post similar such questions to a more appropriate forum - such as a general programming news group, stack overflow, or in this particular case, the ST forum as you appear to be asking a question about their drivers.

laskar01 wrote on Monday, February 08, 2016:

Sorry, it was only I typo, didn’t have it in my code :frowning: