MSP430 Introduction

The MSP430 series by Texas Instruments is a very popular low-power microcontroller which has many features yet is designed to run with very low power. TI sells individual chips, but the best way to prototype with the MSP430 is to use their launchpads (see below).

Key Specs
  • 16-bit CPU
  • 0.5Kb to 16Kb Flash (Program memory)
  • UART, I2C, SPI, DMA, USB depending on model
  • Various low-power modes, down to 500nA at 1.8V
  • 1.8-3.6V operation
  • Several clock sources, up to 25MHz

Note: This tutorial describes how to use the MSP430 with Code Composer Studio, an ASM/C/C++ based IDE. TI also has Energia, an Arduino-like development environment designed specifically for the launchpads. Please see this page for a tutorial on how to use Energia and the MSP430 launchpads.

Choosing an MSP430 device

TI manufactures MSP430 devices within the following categories:

  • Value Line (MSP430Gxxx): Limited or combined peripherals, low pin count (similar to Atmel ATtiny series)
  • 5xx/6xx : SMT package, many peripherals (similar to Atmel ATmega or Xmega)
  • Other lines designed for LCD, motor control, or other applications
Most likely, you want a board with the MSP430 installed, ready to hook into your system. TI offers a few MSP430 devices on a board, which they call a launchpad. Also, the launchpad has a built-in FET emulator that programs the MSP430.

The launchpads have an onboard FET to program the MSP430. Depending on the launchpad, the board will also create a virtual COM port for serial communication between the PC and UART via serial, and a small "flash-drive like" storage space for files. These separate lines for communication can operate simultaneously.

Robotics club keeps some launchpads that you can use with a small refundable deposit. They are also sold by TI and other distributors for $10-$30.

MSP430 Programming basics

DMA Controller
Flash Memory Controller
Digital I/O
Hardware Multiplier
Universal Serial Interface (USI)
Universal Serial Communication Interface (USCI)
Operational Amplifier
ADC 10bit
ADC 12bit
DAC 12bit

Links to tutorials on specific peripherals

Following are some tutorials common to all MSP430 devices

MSP430 Documentation

There are two important documents to reference: First, the device specific datasheet, found if you search for the device part number (e.g. MSP430F5529) on [[]]. This document lists the peripherals available on the device, but does not explain how to use the peripheral. Second, Family User's Guide, under the User Guide section. The user guide explains peripheral registers and operation for all devices. For example, the MSP430G2553 has a USCI module for UART, I2C, SPI, but the MSP430G2452 has a USI module that also has SPI and I2C, but is more limited. The user guide has sections for both the USCI and USI so make sure to know which peripheral is on your device.

Recommended Code Style

It is generally important to make your code as readable as possible, especially when you need to ask for help. This is particularly important for embedded programming where the code manipulates registers with cryptic names. To disable the watchdog timer, for example, it is possible to do the following:
WDTCTL = 0x5a80;
However, you cannot easily tell what control bits are being set or cleared. Instead, use the macros in "msp430.h" and the device-specific library, e.g. "msp430g2553.h":
In "msp430g2553.h", we see
#define WDTHOLD (0x0080)
#define WDTPW (0x5a00)
Since the binary bit patterns do not overlap, you can use either an addition or OR operator.

The macros account for bit shifting (unlike AVR). Most macros follow the control bit name in the datasheet. Multibit macros are the bit name followed by an underscore and the decimal value of the bit values:
This selects the bit pattern UCSSEL[1:0] = 0b10 = 2

Interrupt vectors are slightly different from the interrupt name. See Interrupts.

For any macro, hovering your cursor over the syntax will usually show the macro definition. Alternatively, look in the header files, msp430.h, and the device specific file.

Header files

At the top of your main.c or main.h file, include the following header files:
For any MSP430 device, include the msp430.h file:
#include <msp430.h>

Also include the device-specific header file, for example the msp430g2553:
#include "msp430g2553.h"

Watchdog Timer

By default, the watchdog timer on the MSP430 is enabled. It is a hardware timer that should be periodically reset in software, so that if the software hangs, the watchdog timer will reach max and reset the chip. You most likely want to disable the watchdog timer:

Clock System

The MSP430 has a complex clock system designed to reduce power consumption. Instead of using a single clock to run the entire device, peripherals can run on slower clocks than the master clock running the CPU, to reduce power consumption. Certain clocks can also be turned off using the Low Power Modes to reduce power consumption. Note that details about the clock module depends highly on family and less on device, so check the user guide and datasheet.

The MSP430 has several options for a clock source
  • LFXT1CLK: Crystal or ceramic resonator at 32.768kHz or 400kHz to 16MHz
  • XT1CLK: Crystals or ceramic resonator at 32.768kHz or 4MHz to 32kHz
  • XT2CLK: Crystals or ceramic resonator at 400kHz to 16MHz
  • DCOCLK: Internal digitally controlled oscillator (DCO)
  • VLOCLK: Internal 10/12kHz oscillator designed for low power
  • REFOCLK: Internal 32.76kHz oscillator
The basic clock module drives three clock lines from the clock source:
  • MCLK: Master Clock used by the CPU
  • ACLK: Auxiliary Clock selected by peripherals
  • SMCLK: Sub-main clock selected by peripherals
    Each clock line can run at a frequency equal, half, quarter, or eight, of the clock source. Note that clock sources and lines differ by device, so check the datasheet and user guide.

The default clock source is the DCO. Select the necessary clock source below, then select the clock line used by each peripheral individually.

Internal Very Low Power Low Frequency Oscillator (VLO)

The VLO uses an internal 12kHz oscillator (Value devices) or 10kHz oscillator (5xx/6xx devices). Select it as follows:
BCSCTL3 = LFXT1S_2;//Set LFXTS = 0b10

LFXT1 Oscillator

The LFXT1 can be driven by an external 32.768kHz crystal (LF mode) or high speed crystal (HF mode). The crystal requires external capacitors on XIN and XOUT, see user guide for details.
If in LF mode, clear XTS:
BSCTL3 = LFXT1S_0 | XCAP_x;//Set LFXT1S = 0b00, select capacitor with XCAP_x
If in HF mode, set XTS:
BSCTL3 = LFXT1S_x | XCAP_0;//Set LFXT1S_x to oscillator range, set XCAP = 0b0

Digitally Controlled Oscillator (DCO)

The DCO uses an internal RC oscillator to generate a clock signal. On some devices, it can also be sourced from an external RC oscillator, crystal, or ceramic resonator. The DCO has been calibrated in factory at 1MHz, 8MHz, 12MHz, and 16MHz. If the device flash has been completely erased, this data will not exist and read as 0xff.
if(CALBC1_16MHZ == 0xff || CALDCO_16MHZ == 0xff); check if calibration data in flash has been erased
See user manual for additional details.

Low Power Modes

The defining feature of the MSP430 is its low power modes. The low power modes shut down parts of the chip to reduce power usage, up to 500nA (In comparison with other brands that operate at a few milliamps). For example, the CPU is shut down until the UART interrupt is set, then the CPU performs some operation and is again shutdown.
Low Power modes (check with datasheet for specific device):
  • Active Mode (AM): All clocks active
  • Low-power mode 0 (LPM0)
    • CPU disabled
    • ACKL, SMCLK active; MCLK disabled
  • Low-power mode 1 (LPM1)
    • CPU disabled
    • ACLK, SMCLK active; MCLK disabled
    • DCO disabled
  • Low-power mode 2 (LPM2)
    • CPU disabled
    • MCLK, SMCLK disabled
    • ACLK active
  • Low-power mode 3 (LPM3)
    • CPU disabled
    • MCLK, SMCLK disabled
    • DCO disabled
    • ACLK active
  • Low-power mode 4(LPM4)
    • CPU disabled
    • ACLK, MCLK, SMCLK disabled
    • DCO disabled
    • Crystal oscillator stopped
      More modes on other devices

Additional Resources

Video Tutorials (9-parts) for G-series launchpad from TI:

lecture1_intro.pdf - TI Class lecture about MSP430: Intro to MSP430 series (982 KB) Nishant Pol, 05/25/2014 01:41 PM

lecture2_msp430Architecture.pdf - TI Class lecture about MSP430: MSP430 CPU Architecture (957 KB) Nishant Pol, 05/25/2014 01:41 PM

lecture3_ASM.pdf - TI Class lecture about MSP430: MSP430 Assembly Language (683 KB) Nishant Pol, 05/25/2014 01:41 PM

lecture4_MSP430x.pdf - TI Class lecture about MSP430: MSP430x CPU Architecture and Assembly (1.57 MB) Nishant Pol, 05/25/2014 01:41 PM

lecture5_deviceSystems.pdf - TI Class lecture about MSP430: system reset, clocks, interrupts, watchdog, supervisory voltage system (627 KB) Nishant Pol, 05/25/2014 01:41 PM

lecture6_GPIO_LCD.pdf - TI Class lecture about MSP430: General Purpose IO pins and LCD controller (559 KB) Nishant Pol, 05/25/2014 01:41 PM

lecture7_Timer.pdf - TI Class about MSP430: Timers (545 KB) Nishant Pol, 05/25/2014 01:42 PM

lecture8_ADC.pdf - TI Class about MSP430: SAR ADC (910 KB) Nishant Pol, 05/25/2014 01:42 PM

lecture9_USCI.pdf - TI Class about MSP430: USCI perpheral for UART, SPI, I2C (750 KB) Nishant Pol, 05/25/2014 01:42 PM

lecture10_DMA.pdf - TI Class about MSP430: Direct Memory Addressing (584 KB) Nishant Pol, 05/25/2014 01:42 PM

lecture11_Communications_USI.pdf - TI Class about MSP430: USI peripheral for SPI, I2C (775 KB) Nishant Pol, 05/25/2014 01:46 PM

lecture13_Multiplier_Flash_TLV.pdf - TI Class about MSP430: Hardware multiplier, flash memory, TLV (645 KB) Nishant Pol, 05/25/2014 01:46 PM

lecture12_USCI.pdf - TI Class about MSP430: USCI peripheral for UART, SPI, I2C (1.12 MB) Nishant Pol, 05/25/2014 01:47 PM

slap113 - MSP430 Timers In-Depth.pdf - TI presentation and examples of MSP430 timers (1.64 MB) Nishant Pol, 05/25/2014 01:47 PM