AnsweredAssumed Answered

Incorrect work GPIO_ReadInputPin(GPIOx, GPIO_PIN_X) from examples (IAR ver.2.20).

Question asked by Lysenko.Aleksey on May 10, 2017

Sometimes function returns RESET then Pin state is SET (corresponding bit in IDR register is "1").

Example. The condition - if (GPIO_ReadInputPin(GPIOx, GPIO_PIN_X) == SET) {some code}
else {some code} - not working correctly (returns that Pin is always in RESET state).

Not dependent from Port and Pin. In some cases always work correct, in another cases always not correct.

I addressed directly to IDR register to retrieve the correct Pin value.

I used old school method to read Pin value - (GPIOX->IDR & GPIO_PIN_X).
The condition in that case looks like this - if ((GPIOX->IDR & GPIO_PIN_X) == 0) or if ((GPIOX->IDR & GPIO_PIN_X) != 0).

Only == 0 or != 0 works correctly, not == SET or == RESET.


MCU type - STM8S003F3.