I've been trying to get 2 input push-buttons working on my MSP430 FF529.
I've been successful with 1, but not the other, which leads me to think the one not working is broken, since I'm doing the exact same thing for both.
The two push-buttons on this board are attached to ports P1.1
and P2.1
I got P2.1
to work fine by doing:
P2DIR = 0x00; //set as input
P2REN |= 0x02; //enable pullup for p2.1
Now for Port 1, I also need an LED attached to P1.0
as output, so I have done:
P1DIR = 0x01; //set p1.0 as output, and p1.1 as input
P1REN |= 0x02; //enable pullup for p1.1
So P2.1 is working perfectly fine. The default value is HIGH, and I can see it switch to LOW when I press the button. But this is not the case for P1.1. The default value for this is LOW, and pressing the button has no effect. Am I missing something obvious? Or something different about this port than the other port?
The parts I'm referring to are in green boxes.
MSP430 FF529
enter image description here
enter image description here
1 Answer 1
As OP has noted in the comments, issue was due to code changing the state of the Port 1 Output P1OUT
. When PxREN
is enabled for a given port and pin, the corresponding bit for the same port and pin in PxOUT
controls whether the builtin Pull-Up (Logic 1) or Pull-Down (Logic 0) is connected. PxDIR
must also be set to Logic 0 for the port and pin to be an input.
Consequently, Op had set the P1.1 Button Input to pull-down to Gnd, when the button is also tied to Gnd when pressed.
P1
andP2
doing literally the exact same thing just to see if I could get the correct behavior, but ending up with different values. For both I have:PxSEL=0x00
,PxDIR=0x00
,PxREN=0xFF
, andPxOUT=0xFF
, and both are different values. At run-time, port P1 has the value 0x00, and P2 has the value 0xFF. \$\endgroup\$P1OUT = 0x00
when it shouldn't have been, so I guess it was changing P1 to pull-down. Doh \$\endgroup\$