profile picture

Blinking an LED with the MSP430

November 06, 2013 - msp430

I recently bought a MSP430 Launchpad from Texas Instruments. The MSP430 is a family of low power, low cost microcontrollers. To make sure my development environment was setup correctly I wanted to start with one of the simplest things to do, blink a LED.

MSP430

I have a wire connected to P1.0, another connected to GND, a 180 ohm resistor, and an LED 180 Ohm resistor. The code is compiled with GCC.

blink.c

#include <msp430.h>

int main(void) {
  WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
  P1DIR = 0x01; // Set pin to output, 0b00000001

  for (;;) {
    volatile unsigned int i;
    P1OUT ^= 0x01; // toggle LED1 (P1.0) on/off, 0b00000001
    i = 50000;
    do (i--);
    while (i != 0);
  }
}

Makefile

CC=msp430-gcc
CFLAGS=-Os -Wall -g -mmcu=msp430g2553

OBJS=main.o


all: $(OBJS)
        $(CC) $(CFLAGS) -o main.elf $(OBJS)

%.o: %.c
        $(CC) $(CFLAGS) -c $<

clean:
        rm -fr main.elf $(OBJS)

We build, then use mspdebug to load the program onto the chip from the command line.

$ make
$ mspdebug rf2500
(mspdebug) prog main.elf
Erasing...
Programming...
Writing  108 bytes at c000 [section: .text]...
Writing   32 bytes at ffe0 [section: .vectors]...
Done, 140 bytes total
(mspdebug) exit

Now we have a LED blinking.