1

I have the following sample program for the MSP430 and I wish to rearrange it so that the line PM5CTL0 &= ~LOCKLPM5; comes before P2SEL1 |= BIT0 | BIT1;. Would there be a problem if I did so? I. e. would there be a problem if I configure the GPIO pins after disabling the high-impedance mode?

Nothing on my application/circuit side has any issues. I am just curious about any transient currents or other instability that might yield surprises? Or is it just a ritual/convention to disable the high-impedance mode after configuring GPIO?

#include "msp430.h"

int main(void)
{
  WDTCTL = WDTPW | WDTHOLD;                 // Stop Watchdog

  // Configure GPIO
  P2SEL1 |= BIT0 | BIT1;                    // USCI_A0 UART operation
  P2SEL0 &= ~(BIT0 | BIT1);

  // Disable the GPIO power-on default high-impedance mode to activate
  // previously configured port settings
  PM5CTL0 &= ~LOCKLPM5;

  // rest of program
}
necromancer
  • 23,916
  • 22
  • 68
  • 115

2 Answers2

2

I see two things missing from this code

  1. The RX pin is not configured as a input (and TX as an output)
  2. and the pull-up has not been enabled for the RX pin (assuming you don't have an external pull-up)

One of those "thumb" rules one follows with the MSP430s :) Maybe you've handled it somewhere else.

Regarding the LOCKLPM5 take a look at what the User Guide has to say

Upon entry into LPMx.5, LOCKLPM5 residing in PM5CTL0 of the PMM module is set automatically. The I/O pin states are held and locked based on the settings prior to LPMx.5 entry. Note that only the pin conditions are retained. All other port configuration register settings such as PxDIR, PxREN, PxOUT, PxDS, PxIES, and PxIE contents are lost.

There is some logic beind the "ritual"!

Assuming you are handling a wakeup event: Your peripherals are in their default condition after the wakingup from LPMx.5 state. If you were to clear the LOCKLPM5 bit without configuring the peripheral, then your pins would be in their default condition i.e. no pull up, all configured as inputs etc etc. Leaving the door open for an unexpected glitch. Since one likes to avoid such uncertainity, one configures the peripheral first and then clears the LOCKLPM5.

The repercussions of the transiant "default" state, also depends on how you answer the following questions ->

  • Does your circuit handle the condition when the TX pin is an input? (Most likely yes, else you contend with power on issues)
  • RX pin has no internal pull up, so will the RX line drop to '0' i.e. a start condition? will that cause an interrupt somewhere else in the circuit?
ka05
  • 594
  • 1
  • 5
  • 12
1

It seems to me that disabling high impedance after you have pin reconfiguration done is a little bit better than doing it before. This is because being in the high impedance the contact is like disconnected from the outside circuit and this guarantees that no any possible noise, distortion or short peak meander will bounce.

Your outside circuit most likely will not react, but in theory there could be a circuit that changes its behaviour with such a "signal", in other words there could be something sensitive on the other end of the wire that can be affected by such a bounce.

Ruslan Gerasimov
  • 1,752
  • 1
  • 13
  • 20