MSP430 Quick Start

Intro to the development system

Setting up:

  1. Start Code Composer Studio; the icon () should be on the desktop.  Be patient, it takes a while to start up.  If you are working on your own computer and it doesn't have Code Composer Studio (the free version is here), install it (the computers in Hicks should have it).   You only need to install the MSP430 tools.  After Code Composer starts you'll need to pick a workspace - this is a folder where all of your programs and associated files will be stored.
  2. Plug in the LaunchPad - the USB drivers should load automatically.
  3. In CCS, go to File→New→CCS Project (Click >Next).  Enter a project name (I chose "Blinky"), choose the "MSP430" family and set "MSP430G2553" as the processor variant, and choose "Empty Project (with main.c)" as your template.

    Click "Finish" and wait a few seconds.
  4. At the top of the window there should be two buttons at the right that say "CCS Edit" and "CCS Debug"; these are two perspectives on the project.  We use the "Edit" perspective to edit files... and the "Debug" perspective to debug our project as it is running on the MSP430.  Choose the "CCS Edit" perspective.  A folder called "Blinky" should be labeled as the active project in the project explorer pane, and a file called "main.c" should be open in the editor pane (middle of the screen). 

Program 1: Blinking an LED

This section of code will step you through the writing of a simple program that flashes an LED, downloading the code to the MSP430 and running it.

  1. Enter the following code (or cut and paste):
    /*
     * main.c
     */
    
    #include <msp430.h>
    
    void main(void) {
    	volatile int i;
    
    	WDTCTL = WDTPW + WDTHOLD;         // Stop watchdog timer
    	P1DIR = P1DIR | 0x01;             // Set P1.0 to output direction
    	// Note: 0x01 = 0000 0001 binary (the LSB is set).
    
    	while (1) {                       //Do this forever
    		P1OUT = P1OUT ^ 0x01;         // Toggle P1.0 using exclusive-OR
    		for (i=1; i<30000; i=i+1) {}  //Delay
    	}
    }
     
  2. Go to Run →Debug (or hit the "debug" icon ) and make sure there is no error (if there are no errors, the perspective "Debug").
  3. Go to Run→Resume. (or hit the "run" icon).  The red LED on the LaunchPad board should blink.
  4. Connect the E15 I/O board through the adapter, examine the connections between MSP430 and E15 I/O, and change the code so the middle LED blinks.

Things to try:

Program 2:  Lighting an LED on command

The previous program blinked an LED with no user input.  Let's change that so you interact with the program.  First note that there is a pushbutton switch on the LaunchPad connected to P1.3.  When the button is not pushed, the pin is tied to Vcc through a resistor (logic high).  When the button is pushed, the pin is connected directly to ground (logic low).

/*
 * main.c
 */

#include <msp430.h>

void main(void) {
	volatile int i;

	WDTCTL = WDTPW + WDTHOLD;       // Stop watchdog timer
	P1DIR = P1DIR | BIT0;           // Set P1.0 to output direction
	P1DIR = P1DIR & ~BIT3;          // Set P1.3 to input direction

    while(1) {
        if (!(P1IN & BIT3)) {		// If button is pushed (P1.3 is low)
            P1OUT = P1OUT | BIT0;	//   ... turn on LED
            				// or P1OUT |= BIT0;
        } else {
            P1OUT = P1OUT & ~BIT0;	//   ... else turn it off.
            				// or P1OUT &= ~BIT0
        }
    }
}

 

Please contact me if there is a problem with this web page (e.g., errors, or sections that are unclear).