MSP430 GPIO
GPIO Input
Reading a pin’s value is done by reading the PxIN register. The GPIO_getInputValue()
DriverLib function returns this value to a variable in your program.
Input pins are slightly more complicated than output pins. While the PxDIR function selects
whether a pin is used for an input or output, your input pin may need further configuration.
When using a pin as an input, what value does the pin have when it is not being driven by
external hardware? Unfortunately, when not being driven, an input pin ‘floats’ – that is, it can
change state arbitrarily. Not only is this undesirable from a logical point of view, but even worse,
power is consumed every time the pin changes state. The common solution is to tie the pin high
(or low) through a resistor. When driven, the external signal can override the weak pull-up (or
pull-down); otherwise the resistor holds the input to a given value.
To minimize system cost and power, most MSP430 I/O ports provide internal pull-up and pull-
down resistors. You can enable these resistors via the PxREN (Resistor ENable) register bits.
When PxREN is used to enable these resistors, the associated PxOUT bit lets you choose
whether the pull-up or pull-down resistor is enabled.
Of course, the easiest way to configure the pull-up or pull-down resistor is to use one of the two
GPIO DriverLib functions:
GPIO_setAsInputPinWithPullUpresistor()
GPIO_setAsInputPinWithPullDownresistor()
Note: Another feature of input pins is their ability to generate CPU interrupts. We won’t cover
those details in this chapter; rather, we’ll save that discussion until the Interrupts chapter.
MSP430 Workshop - Using GPIO with MSP430ware 3 - 9