Skip to main content
parth kothiya
Associate III
April 4, 2022
Solved

How to inverse gpio read pin?

  • April 4, 2022
  • 1 reply
  • 1321 views

i am reading GPIO PIN using

bool X[n];

X[1] = (GPIOA->IDR >> 1)&1;

X[2] = (GPIOA->IDR >> 4)&1;

now i want to inverse reading bit because of pull up i am getting inverse output in X[n].

example

X[1] = (GPIOA->IDR >> 1)&1; gives 1 but i want 0

How can i do this ?

X[1] != (GPIOA->IDR >> 1)&1; gives warning

value computed but not used [-Wunused-value}

This topic has been closed for replies.
Best answer by Tesla DeLorean

X[1] = !((GPIOA->IDR >> 1)&1);

X[1] = (~GPIOA->IDR >> 1)&1 // Tilde

1 reply

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
April 4, 2022

X[1] = !((GPIOA->IDR >> 1)&1);

X[1] = (~GPIOA->IDR >> 1)&1 // Tilde

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..