I'm connecting a DTMF decoder and trying to access pins 4-7 (that's PORTD 4-7) at the same time to get the value. digitalRead() works just fine and I can read the data correctly one bit at a time, but if I try to access PORTD I get all 0s. Here's the code:
Yep, did "tone = PORTD;" and printed it, same result. PORTD is always 0. Just for grins I tried DDRD, too, and it's always 0, which diesn't seem right because at least one pin on PORTD is the serial output.
DDRD will not work because that is for defining whether each pin is input/output.
PORTD does not work because that is for reading/writing the current output state (HIGH/LOW).
What you want is: PIND, which is the array of input state bits.
DDRD will not work because that is for defining whether each pin is input/output.
Right, I was just trying to read something that was non-zero for a sanity check. I can read DDRD to see what the direction bits are set to, right?
PORTD does not work because that is for reading/writing the current output state (HIGH/LOW).
I'll buy that, but I'm sure I've seen examples that say "PORTD ^= PORTD;" or something along those lines. Of course, the example (or my memory) could be faulty.
What you want is: PIND, which is the array of input state bits.