2022-02-08 02:30 PM
Hello,
I'm using STM32 NUCLEO board.
In my application, I want to read GPIO PORT A input register (IDR) & (pins setup as inputs).
With that variable, I want to do something, if specific pins are HIGH, execute the if cycle.
As an example, I want to execute my logic if PIN 0 and PIN1 both of them HIGH, All I do in while cycle is:
read=GPIOA->IDR;
if(read &0b0000000000000011)
{
Do something if PIN 0 and PIN1 are HIGH
}
else
{
Do something if the statement above was FALSE.
}
In debugger mode I can see the status of the pins, and if I changing them between high/low the register see that, but my if cycle doesn't seem to work. Sometimes it executes if, sometimes executes else statement. Is it something wrong with the bitmask?
Solved! Go to Solution.
2022-02-08 02:51 PM
> if(read &0b0000000000000011)
This evaluated true, if either one or both pins are high.
If you want to test for both pins being high, not only one of them, use
if ((read & 0b0000000000000011) == 0b0000000000000011) {
do_something();
}
JW
2022-02-08 02:51 PM
> if(read &0b0000000000000011)
This evaluated true, if either one or both pins are high.
If you want to test for both pins being high, not only one of them, use
if ((read & 0b0000000000000011) == 0b0000000000000011) {
do_something();
}
JW
2022-02-08 02:56 PM
Thanks for a reply! Seems reasonable. Let me try this tomorrow see if it works!