cancel
Showing results for 
Search instead for 
Did you mean: 

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

Aleksey Lysenko
Associate
Posted on May 10, 2017 at 22:22

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.

0 REPLIES 0