2017-05-10 01:22 PM
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.