ESE101: MSP430 Introduction

Last week I discussed a bunch of different things to consider when selecting a microcontroller. I chose the MSP430 for us to use in ESE101 primarily because it’s relatively easy to learn.

So: let’s get learning!

We’ll be using the MSP430F5529 LaunchPad development kit. If you’d like to follow along with real hardware (the best way to learn!) then I encourage you to acquire one here: http://www.ti.com/tool/MSP-EXP430F5529LP

Also, the contest to win a free dev kit ends Tuesday, April 5 at 11:59pm Pacific Time. All email must be received by then. The kits were generously donated by Adrian Fernandez from Texas Instruments. See the end of last week’s post for details.

Since you probably don’t have a dev kit in hand yet, I’ll explain the basics of the MSP430 microcontroller this week, and save diving into the dev kit for next week.

How Many Bits?

Originally the MSP430 was a “true” 16-bit microcontroller, meaning all its registers were 16-bits wide. All of its memory addresses were 16-bits wide too, and therefore it it could address 64KB of memory. (The largest 16-bit number is 0xFFFF in hex or 65535 in decimal, which equates to 64KB of memory. I’ll talk more about hex/decimal/bit-width in a later post.)

The original MSP430 was extended to support 20-bit addresses so it could address 1MB of memory. (The largest 20-bit number is 0xFFFFF in hex or 1048575 in decimal, which equates to 1MB of memory.) This extended MSP430 is technically called the “MSP430X,” but the original MSP430 is long gone, so “MSP430” refers to the MSP430X. All MSP430 chips around today can address 1MB of memory.

You’ll see the TI documentation refer to the MSP430 as “CPUX” when it wants to emphasize the fact that it can address 20-bits worth of memory. Don’t let that throw you - CPU and CPUX are the same thing.

Register Overview

The MSP430 has 16 registers. They’re usually used as 16-bit registers, but they can be also be used as 8-bit or 20-bit registers in different situations, which is a bit confusing. [Terrible pun, I know. I’m leaving it in.]

The registers are named R0-R15. R4-R15 are general purpose registers and can be used for anything your program wants. R0-R3, on the other hand, are special purpose registers.

R0 is the Program Counter, and is usually called PC. The PC holds the memory address of the next instruction to execute, just like in our fictional microprocessor. You remember the PC from our fictional multiprocessor, right? The PC is always used as a full 20-bit register so it can point to any* address in the 1MB memory space.

R1 is the Stack Pointer, and is usually called SP. We haven’t talked about what a stack is yet, but for now it’s enough to know that the SP holds a memory address. Like the PC, the SP is always used as a full 20-bit register so it can point to any* address in the 1MB memory space.

R2 is the Status Register, and is usually called SR. This is similar to our fictional microcontroller’s SR.

R3 is the Constant Generator 2 register, and is usually called CG2.

SR and CG2 are a bit strange, but I’ll explain them as we get into the MSP430’s instructions in a future post. (SR is also called CG1, so that's why R3 is CG2 instead of CG1, but that doesn't matter for now.)

* Note: I said the PC and SP could point to “any” address, but that’s not quite true. They’re only allowed to point to even addresses because instructions and the stack are 2-byte aligned: each instruction is either 2, 4, 6, or 8 bytes, and each item on the stack is either 2 or 4 bytes long. Since memory starts at address 0, that means that the PC and SP will never need to point to an odd address since all instructions or items on the stack are at an address that’s a multiple of 2.

Instruction Overview

The MSP430 has 27 instructions. For more information than presented here, check out Wikipedia’s MSP430 article, it has a great summary of the instructions. For even more information, check out section 6.5 of the user’s guide.

The MSP430 instructions are grouped into three categories:

  1. Jump instructions: these instructions change which instruction runs next, just like “JZ” from our fictional microcontroller.

  2. Double operand instructions: these instructions do some operation with two operands, just like “ADD” from our fictional microcontroller.

  3. Single operand instructions: these instructions do some operation with one operand. Our fictional microcontroller didn’t have any instructions like this. One example that the MSP430 has is the RRC instruction, which takes a single input operand and rotates it one bit to the right.

These three categories might seem a bit arbitrary and fuzzy, especially since the jump instructions can have one or two operands, which might make you wonder why the jump instructions aren’t grouped in with the single operand or double operand instructions. I’ll explain it later, but until then, see if you can figure out why the instructions are grouped the way they are from the MSP430 user’s guide or Wikipedia article.

Next Time

Next week we’ll start using the dev kits!

Until then, please download the “MSP430x5xx and MSP430x6xx Family User's Guide”. This document is more than 1000 pages long, which is pretty typical for microcontroller user’s guides. Don’t feel overwhelmed by its length - we’ll pick and choose which parts to use.

As a bit of homework, please go to Chapter 6, “CPUX,” and quickly skim through that chapter yourself, just to get a feeling for what’s there.