Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

MSP430G2553 P1.6 oddness

$
0
0

I have an EXP-430G2 launchpad with a 'G2553.  LEDs are connected (via transistors) to P1.4, P1.5, P1.6 and P1.7.

 

When I ran the following code: 

#include <msp430.h>

int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
  P1DIR |= 0xF0;                        // Set P1.[4567] to output direction

  P1SEL = 0;				// Set all P1's as GPIO

for (;;) {
    volatile unsigned int i;

    P1OUT ^= 0xF0;                      // Toggle P1.[4567] using exclusive-OR

    i = 50000;                          // Delay
    do (i--);
    while (i != 0);
  }
}

I found a fun phenomenon: P1.4, P1.5 and P1.7 when light up, P1.6 goes dark and vice versa.

 

Easy enough to fix: after the P1SEL line, add

  P1OUT = 0;

to initialize the output pins.

 

I noticed this while moving from a 'G2452 to the 'G2553, and thought it was a useful reminder to practice good coding hygiene and always explicitly initialize your outputs so they have a known state! :-)


Viewing all articles
Browse latest Browse all 2077

Trending Articles