I'm working on a ultra-low power application and want to enable and access only one pin as output and one pin as input. I'm using the MSP430 microcontroller and CCS for programming. I have two questions.

  • The MSP430 allows accessibility of a whole port. Is it possible to access only the required two pins as input and output (which is possible in PIC)?

  • Doesn't accessing (and enabling) the whole port (8 pins) consume more current compared to accessing (and enabling) a single pin?


2 Answers 2


1) Yes, you can select pins individually. For example, to set pin 4 of port 1 as output and high:

P1DIR |= (1 << 4);
P1OUT |= (1 << 4);

To set the same pin as input, clear the DIR bit:

P1DIR &= ~(1 << 4);

Even though the P1DIR and P1OUT registers describe the whole port 1 as a whole, the individual bits in that register control individual pins: the lowest-order bit controls the first pin for that port, and so on. Same applies to the other ports, each of which has eight pins.

2) Pins are always "enabled" in some mode. There's DIR flag for each pin (which selects whether the pin is in input or output mode) and there's SEL flag as well (selects whether the pin is data or function mode). The default mode (after reboot) for a pin is data+input. Energy consumption depends on what you have connected to the pin; there's no single answer.

  • \$\begingroup\$ Can you explain the answer to the question 1 in detail? \$\endgroup\$ May 7, 2016 at 17:41
  • 1
    \$\begingroup\$ Don't set a non-connected pin to input. CMOS inputs, in general, can consume a lot of current and even be damaged, if left floating. Either set them to outputs or, if left as input, tie them to either ground or Vcc (through a resistor if there's a change of being set to output). \$\endgroup\$
    – DoxyLover
    May 7, 2016 at 18:03
  • 1
    \$\begingroup\$ The recommended state for unused pins is output low. \$\endgroup\$
    – Passerby
    May 7, 2016 at 19:06

The MSP430 organizes the GPIO bits in ports, but when using C statements that set/clear single bits, the compiler will generate bit set/clear commands that affect only single bits (BIS/BIC):

if (P1IN & BIT1) {
    P1OUT |= BIT4;
} else {
    P1OUT &= ~BIT4;

This will not consume current for any bits that are not accessed.

In general, GPIO pins do not consume any current, unless

  • output pins actually sink or source current (due to external circuitry), or
  • input pins actually change (or are floating).

The user's guide tells you how to configure unused pins: as output, or as input with a pull-up/-down. (The default setting is input without pull-up/-down, which does not save current, but is the safest setting while the chip is still in reset.)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.