The sixteen registers
| Register | Name | Use |
|---|---|---|
R0 | PC | Program counter. Always even: an instruction is one to three words (four on the MSP430X), starting at an even address. Instructions that write R0 jump. |
R1 | SP | Stack pointer. Always even; the stack grows toward lower addresses (PUSH decrements it by two, then stores). |
R2 | SR, CG1 | Status register, and the first constant generator: in some addressing modes it supplies the constants 4 and 8 or the absolute-address mode instead of its value. |
R3 | CG2 | The second constant generator: it never holds a value, only the constants 0, 1, 2 and −1 (all ones). Writing it has no effect. |
R4 to R15 | General purpose, 16 bits (20 bits on the MSP430X). |
The disassembler writes the registers by number (r0 to r15), as llvm does; TI’s tools write PC, SP, SR and CG for the first four.
The status register
| Bit | Flag | Meaning |
|---|---|---|
| 8 | V | Overflow |
| 7 | SCG1 | System clock generator 1 off (low-power mode) |
| 6 | SCG0 | System clock generator 0 off |
| 5 | OSCOFF | Oscillator off |
| 4 | CPUOFF | CPU off (low-power mode) |
| 3 | GIE | General interrupt enable (EINT sets it, DINT clears it) |
| 2 | N | Negative |
| 1 | Z | Zero |
| 0 | C | Carry |
The viewer lists the flags V, N, Z and C that an instruction changes or reads. BIC and BIS with SR as the destination (the emulated EINT, DINT, CLRC, SETC …) change the others; so does MOV to SR.
Memory
The MSP430 has one address space: peripherals at the bottom (0x0000 to 0x01FF on the 2xx devices), then RAM, then flash at the top, with the interrupt vectors in the last 32 bytes and the
reset vector at 0xFFFE. There is no separate I/O space and no I/O instruction: peripherals are read and written like memory (with .B for the byte-wide ones). Words are stored
little-endian at even addresses; a word access at an odd address ignores the low bit of the address. The 16-bit CPU reaches 64 KB; the MSP430X reaches 1 MB with 20-bit addresses.
Every instruction operates on bytes (.B) or words (the default, written .W in TI’s listings). A byte operation on a register clears the upper byte of the destination.
Interrupts, low-power modes, reset and the vectors
From TI’s user’s guide SLAU367P (the MSP430FR4xx/5xx/6xx family, chapter 1 “System Resets, Interrupts, and Operating Modes”, sections 1.2 to 1.4). Details such as the interrupt sources and their order differ by device and are in each data sheet.
Interrupt acceptance and return
- The instruction that is executing is completed.
- The PC (which points to the next instruction) is pushed onto the stack; on the 20-bit CPU its upper four bits are saved in the same stack word as the status bits, and RETI restores them (SLAU367P 4.6.2.37).
- The SR is pushed onto the stack.
- If several interrupts are pending, the one with the highest priority is selected.
- The request flag is reset automatically for single-source flags; flags with several sources stay set for software to clear.
- All bits of SR are cleared except SCG0, which ends any low-power mode; because GIE is cleared, further maskable interrupts are disabled. (Section 1.4.2 says the CPUOFF, SCG1 and OSCOFF bits are reset on entry; the two statements are TI’s own.)
- The content of the interrupt vector is loaded into the PC and the interrupt routine starts there.
The latency from acceptance to the first instruction of the routine is six cycles. RETI takes five: it pops the SR with all its previous settings (GIE, CPUOFF and so on come back, whatever the routine did) and then the PC. The routine can change the saved SR on the stack to return in a different operating mode. The instruction after EINT always executes before a pending interrupt is taken; TI advises at least one instruction between an interrupt-enable clear and EINT, and a NOP after DINT.
Reset
After a brownout reset the SR is reset, the watchdog starts in watchdog mode, I/O pins become inputs, and the PC is loaded with the boot code address; when the boot code is done the PC is loaded from the reset vector at 0xFFFE. User software must then set up the stack pointer (the top of RAM, or an FRAM location), the watchdog and the peripherals. A blank device (reset vector 0xFFFF) enters LPM4 after a reset. A watchdog reset and an RST/NMI reset take 4 cycles (Table 4-8).
Interrupt vectors
The vectors lie in 0xFFFF down to 0xFF80, up to 64 sources of one word each; the lowest-priority sources have the lowest addresses. SLAU367P gives this example list (the complete list is device specific):
| Address | Source | Kind |
|---|---|---|
0xFFFE | Reset (power up, external reset, watchdog, FRAM password violation) | reset, highest priority |
0xFFFC | System NMI (JTAG mailbox, FRAM errors, vacant memory access) | (non)maskable |
0xFFFA | User NMI (RST/NMI pin, oscillator fault) | (non)maskable |
0xFFF8 and below | device-specific sources, the watchdog timer interval timer, then reserved ones | maskable, lowest priority at the lowest address |
On parts with RAM the vectors can be remapped to the top of RAM by setting the SYSRIVECT bit (cleared by a BOR). Nested interrupts happen when the routine sets GIE.
Operating modes
The mode is set by four bits of the SR (SCG1, SCG0, OSCOFF, CPUOFF); it takes effect as soon as they are written, and the mode is saved on the stack with the SR in an interrupt (SLAU367P Table 1-2):
| SCG1 | SCG0 | OSCOFF | CPUOFF | Mode | CPU and clocks |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | Active | CPU and MCLK active |
| 0 | 0 | 0 | 1 | LPM0 | CPU and MCLK disabled; ACLK active; SMCLK optionally active |
| 0 | 1 | 0 | 1 | LPM1 | CPU and MCLK disabled; ACLK active; SMCLK optionally active (the same text as LPM0) |
| 1 | 0 | 0 | 1 | LPM2 | CPU and MCLK disabled; ACLK active; SMCLK disabled |
| 1 | 1 | 0 | 1 | LPM3 | CPU and MCLK disabled; ACLK active; SMCLK disabled |
| 1 | 1 | 1 | 1 | LPM4 | CPU and all clocks disabled |
| 1 | 1 | 1 | 1 | LPM3.5, LPM4.5 | with PMMREGOFF = 1 the regulator is off and nothing is retained; LPM3.5 keeps the RTC |
An enabled interrupt wakes the device from LPM0 to LPM4. The clock request system can keep a peripheral’s clock on, so the mode actually reached can be a lighter one than the bits ask for (Table 1-3).
Not described
- The memory map of a particular device and its peripheral registers (which differ by family: 2xx, 4xx, 5xx, FRxx), and each device’s full interrupt vector list.
- The 2xx and 4xx families’ own text on interrupts and reset (only the FR/5xx guide was read for this section).