MSP430 Family User Guide
MSP430 Family User Guide
MSP430 Family User Guide
Users Guide
January 2010
MSP430
SLAU056J
Preface
FCC Warning
This equipment is intended for use in a laboratory test environment only. It generates, uses, and can radiate radio frequency energy and has not been tested for compliance with the limits of computing devices pursuant to subpart J of part 15 of FCC rules, which are designed to provide reasonable protection against radio frequency interference. Operation of this equipment in other environments may cause interference with radio communications, in which case the user at his own expense will be required to take whatever measures may be required to correct this interference.
Notational Conventions
Program examples, are shown in a special typeface.
iii
Glossary
Glossary
ACLK ADC BOR BSL CPU DAC DCO dst FLL GIE Auxiliary Clock Analog-to-Digital Converter Brown-Out Reset Bootstrap Loader Central Processing Unit Digital-to-Analog Converter Digitally Controlled Oscillator See FLL+ Module Destination Frequency Locked Loop General Interrupt Enable See RISC 16-Bit CPU See FLL+ Module See System Resets Interrupts and Operating Modes See System Resets, Interrupts, and Operating Modes See www.ti.com/msp430 for application reports See RISC 16-Bit CPU See Basic Clock Module
INT(N/2) Integer portion of N/2 I/O ISR LSB LSD LPM MAB MCLK MDB MSB MSD NMI PC POR PUC RAM SCG SFR SMCLK SP SR src TOS WDT Input/Output Interrupt Service Routine Least-Significant Bit Least-Significant Digit Low-Power Mode Memory Address Bus Master Clock Memory Data Bus Most-Significant Bit Most-Significant Digit (Non)-Maskable Interrupt Program Counter Power-On Reset Power-Up Clear Random Access Memory System Clock Generator Special Function Register Sub-System Master Clock Stack Pointer Status Register Source Top-of-Stack Watchdog Timer See FLL+ Module See RISC 16-Bit CPU See RISC 16-Bit CPU See RISC 16-Bit CPU See RISC 16-Bit CPU See Watchdog Timer See System Resets Interrupts and Operating Modes See System Resets Interrupts and Operating Modes See RISC 16-Bit CPU See System Resets Interrupts and Operating Modes See System Resets Interrupts and Operating Modes See FLL+ Module See System Resets Interrupts and Operating Modes See Digital I/O
iv
vi
Contents
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.1 Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2 Flexible Clock System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.3 Embedded Emulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.4 Address Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.4.1 Flash/ROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.4.2 RAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.4.3 Peripheral Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.4.4 Special Function Registers (SFRs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.4.5 Memory Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . System Resets, Interrupts, and Operating Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1 System Reset and Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.1 Brownout Reset (BOR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.2 Device Initial Conditions After System Reset . . . . . . . . . . . . . . . . . . . . . . . 2.2 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2.1 (Non)-Maskable Interrupts (NMI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2.2 Maskable Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2.3 Interrupt Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2.4 Interrupt Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2.5 Special Function Registers (SFRs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3 Operating Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.1 Entering and Exiting Low-Power Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.4 Principles for Low-Power Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.5 Connection of Unused Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1 1-2 1-2 1-3 1-4 1-4 1-5 1-5 1-5 1-5 2-1 2-2 2-3 2-4 2-5 2-6 2-9 2-10 2-12 2-12 2-13 2-15 2-16 2-16
vii
Contents
RISC 16-Bit CPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.1 CPU Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.2 CPU Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.2.1 Program Counter (PC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.2.2 Stack Pointer (SP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.2.3 Status Register (SR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.2.4 Constant Generator Registers CG1 and CG2 . . . . . . . . . . . . . . . . . . . . . . . 3.2.5 General-Purpose Registers R4 to R15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.3 Addressing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.3.1 Register Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.3.2 Indexed Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.3.3 Symbolic Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.3.4 Absolute Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.3.5 Indirect Register Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.3.6 Indirect Autoincrement Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.3.7 Immediate Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.4 Instruction Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.4.1 Double-Operand (Format I) Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.4.2 Single-Operand (Format II) Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.4.3 Jumps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.4.4 Instruction Cycles and Lengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.4.5 Instruction Set Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3-1 3-2 3-4 3-4 3-5 3-6 3-7 3-8 3-9 3-10 3-11 3-12 3-13 3-14 3-15 3-16 3-17 3-18 3-19 3-20 3-72 3-74
16-Bit MSP430X CPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1 4.1 CPU Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 4.2 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4 4.3 CPU Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5 4.3.1 The Program Counter PC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5 4.3.2 Stack Pointer (SP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7 4.3.3 Status Register (SR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9 4.3.4 The Constant Generator Registers CG1 and CG2 . . . . . . . . . . . . . . . . . . . 4-11 4.3.5 The General Purpose Registers R4 to R15 . . . . . . . . . . . . . . . . . . . . . . . . . 4-12 4.4 Addressing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15 4.4.1 Register Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16 4.4.2 Indexed Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-18 4.4.3 Symbolic Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-24 4.4.4 Absolute Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-29 4.4.5 Indirect Register Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-32 4.4.6 Indirect, Autoincrement Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-33 4.4.7 Immediate Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34 4.5 MSP430 and MSP430X Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-36 4.5.1 MSP430 Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-37 4.5.2 MSP430X Extended Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-44 4.6 Instruction Set Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-58 4.6.1 Extended Instruction Binary Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-59 4.6.2 MSP430 Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-61 4.6.3 Extended Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-113 4.6.4 Address Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-156
viii
Contents
FLL+ Clock Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1 FLL+ Clock Module Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2 FLL+ Clock Module Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.1 FLL+ Clock features for Low-Power Applications . . . . . . . . . . . . . . . . . . . . 5.2.2 Internal Very Low-Power, Low-Frequency Oscillator . . . . . . . . . . . . . . . . . 5.2.3 LFXT1 Oscillator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.4 XT2 Oscillator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.5 Digitally Controlled Oscillator (DCO) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.6 Frequency Locked Loop (FLL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.7 DCO Modulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.8 Disabling the FLL Hardware and Modulator . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.9 FLL Operation from Low-Power Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.10 Buffered Clock Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.11 FLL+ Fail-Safe Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3 FLL+ Clock Module Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Flash Memory Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.1 Flash Memory Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2 Flash Memory Segmentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2.1 SegmentA on MSP430FG47x, MSP430F47x, MSP430F47x3/4, MSP430F471xx Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.3 Flash Memory Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.3.1 Flash Memory Timing Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.3.2 Erasing Flash Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.3.3 Writing Flash Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.3.4 Flash Memory Access During Write or Erase . . . . . . . . . . . . . . . . . . . . . . . 6.3.5 Stopping a Write or Erase Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.3.6 Marginal Read Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.3.7 Configuring and Accessing the Flash Memory Controller . . . . . . . . . . . . . 6.3.8 Flash Memory Controller Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.3.9 Programming Flash Memory Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.4 Flash Memory Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Supply Voltage Supervisor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.1 SVS Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2 SVS Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2.1 Configuring the SVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2.2 SVS Comparator Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2.3 Changing the VLDx Bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2.4 SVS Operating Range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.3 SVS Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-Bit Hardware Multiplier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.1 Hardware Multiplier Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2 Hardware Multiplier Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2.1 Operand Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2.2 Result Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2.3 Software Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2.4 Indirect Addressing of RESLO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2.5 Using Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.3 Hardware Multiplier Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5-1 5-2 5-8 5-8 5-9 5-9 5-10 5-11 5-11 5-12 5-13 5-13 5-13 5-14 5-15 6-1 6-2 6-4 and 6-5 6-6 6-6 6-7 6-11 6-17 6-18 6-18 6-18 6-19 6-19 6-21 7-1 7-2 7-4 7-4 7-4 7-5 7-6 7-7 8-1 8-2 8-3 8-3 8-4 8-5 8-6 8-6 8-7
ix
Contents
32-Bit Hardware Multiplier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.1 32-Bit Hardware Multiplier Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.2 32-Bit Hardware Multiplier Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.2.1 Operand Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.2.2 Result Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.2.3 Software Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.2.4 Fractional Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.2.5 Putting It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.2.6 Indirect Addressing of Result Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.2.7 Using Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.2.8 Using DMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3 32-Bit Hardware Multiplier Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9-1 9-2 9-4 9-5 9-7 9-9 9-10 9-15 9-17 9-18 9-20 9-21
10 DMA Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-1 10.1 DMA Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2 10.2 DMA Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-4 10.2.1 DMA Addressing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-4 10.2.2 DMA Transfer Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-5 10.2.3 Initiating DMA Transfers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-12 10.2.4 Stopping DMA Transfers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-15 10.2.5 DMA Channel Priorities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-15 10.2.6 DMA Transfer Cycle Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-16 10.2.7 Using DMA with System Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-17 10.2.8 DMA Controller Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-17 10.2.9 DMAIV, DMA Interrupt Vector Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-17 10.2.10 Using the USCI_B I2C Module with the DMA Controller . . . . . . . . . . . . . . 10-19 10.2.11 Using ADC12 with the DMA Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-19 10.2.12 Using DAC12 With the DMA Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-19 10.2.13 Using SD16 or SD16_A With the DMA Controller . . . . . . . . . . . . . . . . . . . . 10-20 10.2.14 Writing to Flash With the DMA Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-20 10.3 DMA Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-21 11 Digital I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.1 Digital I/O Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Digital I/O Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2.1 Input Register PxIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2.2 Output Registers PxOUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2.3 Direction Registers PxDIR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2.4 Pullup/Pulldown Resistor Enable Registers PxREN (MSP430F47x3/4 and MSP430F471xx only) . . . . . . . . . . . . . . . . . . . . . . . . 11.2.5 Function Select Registers PxSEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2.6 P1 and P2 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2.7 Configuring Unused Port Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3 Digital I/O Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-1 11-2 11-3 11-3 11-3 11-3 11-4 11-4 11-5 11-6 11-7
Contents
12 Watchdog Timer, Watchdog Timer+ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.1 Watchdog Timer Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.2 Watchdog Timer Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.2.1 Watchdog Timer Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.2.2 Watchdog Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.2.3 Interval Timer Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.2.4 Watchdog Timer Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.2.5 WDT+ Enhancements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.2.6 Operation in Low-Power Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.2.7 Software Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.3 Watchdog Timer Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Basic Timer1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.1 Basic Timer1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.2 Basic Timer1 Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.2.1 Basic Timer1 Counter One . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.2.2 Basic Timer1 Counter Two . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.2.3 16-Bit Counter Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.2.4 Basic Timer1 Operation: Signal fLCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.2.5 Basic Timer1 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13.3 Basic Timer1 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Real Time Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14.1 RTC Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14.2 Real-Time Clock Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14.2.1 Counter Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14.2.2 Calendar Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14.2.3 RTC and Basic Timer1 Interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14.2.4 Real-Time Clock Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14.3 Real-Time Clock Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12-1 12-2 12-4 12-4 12-4 12-4 12-5 12-5 12-6 12-6 12-7 13-1 13-2 13-4 13-4 13-4 13-4 13-5 13-5 13-6 14-1 14-2 14-4 14-4 14-5 14-5 14-6 14-7
15 Timer_A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-1 15.1 Timer_A Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-2 15.2 Timer_A Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-4 15.2.1 16-Bit Timer Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-4 15.2.2 Starting the Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-5 15.2.3 Timer Mode Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-5 15.2.4 Capture/Compare Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-11 15.2.5 Output Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-13 15.2.6 Timer_A Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-17 15.3 Timer_A Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-19
xi
Contents
16 Timer_B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-1 16.1 Timer_B Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-2 16.1.1 Similarities and Differences From Timer_A . . . . . . . . . . . . . . . . . . . . . . . . . 16-2 16.2 Timer_B Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-4 16.2.1 16-Bit Timer Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-4 16.2.2 Starting the Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-5 16.2.3 Timer Mode Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-5 16.2.4 Capture/Compare Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-11 16.2.5 Output Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-14 16.2.6 Timer_B Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-18 16.3 Timer_B Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-20 17 USART Peripheral Interface, UART Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-1 17.1 USART Introduction: UART Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-2 17.2 USART Operation: UART Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-4 17.2.1 USART Initialization and Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-4 17.2.2 Character Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-4 17.2.3 Asynchronous Communication Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-5 17.2.4 USART Receive Enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-9 17.2.5 USART Transmit Enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-10 17.2.6 USART Baud Rate Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-11 17.2.7 USART Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-17 17.3 USART Registers: UART Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-21 18 USART Peripheral Interface, SPI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-1 18.1 USART Introduction: SPI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-2 18.2 USART Operation: SPI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-4 18.2.1 USART Initialization and Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-4 18.2.2 Master Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-5 18.2.3 Slave Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-6 18.2.4 SPI Enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-7 18.2.5 Serial Clock Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-9 18.2.6 SPI Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-11 18.3 USART Registers: SPI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-13
xii
Contents
19 Universal Serial Communication Interface, UART Mode . . . . . . . . . . . . . . . . . . . . . . . . . 19-1 19.1 USCI Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-2 19.2 USCI Introduction: UART Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-3 19.3 USCI Operation: UART Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-5 19.3.1 USCI Initialization and Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-5 19.3.2 Character Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-5 19.3.3 Asynchronous Communication Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-6 19.3.4 Automatic Baud Rate Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-10 19.3.5 IrDA Encoding and Decoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-12 19.3.6 Automatic Error Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-13 19.3.7 USCI Receive Enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-14 19.3.8 Receive Data Glitch Suppression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-14 19.3.9 USCI Transmit Enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-15 19.3.10 UART Baud Rate Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-15 19.3.11 Setting a Baud Rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-18 19.3.12 Transmit Bit Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-19 19.3.13 Receive Bit Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-20 19.3.14 Typical Baud Rates and Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-21 19.3.15 Using the USCI Module in UART Mode with Low-Power Modes . . . . . . . 19-25 19.3.16 USCI Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-25 19.4 USCI Registers: UART Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-27 20 Universal Serial Communication Interface, SPI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-1 20.1 USCI Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-2 20.2 USCI Introduction: SPI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-3 20.3 USCI Operation: SPI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-5 20.3.1 USCI Initialization and Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-6 20.3.2 Character Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-6 20.3.3 Master Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-7 20.3.4 Slave Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-9 20.3.5 SPI Enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-10 20.3.6 Serial Clock Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-11 20.3.7 Using the SPI Mode with Low Power Modes . . . . . . . . . . . . . . . . . . . . . . . . 20-12 20.3.8 SPI Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-12 20.4 USCI Registers: SPI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-14 21 Universal Serial Communication Interface, I2C Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-1 21.1 USCI Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-2 21.2 USCI Introduction: I2C Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-3 21.3 USCI Operation: I2C Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-5 21.3.1 USCI Initialization and Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-6 21.3.2 I2C Serial Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-7 21.3.3 I2C Addressing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-8 21.3.4 I2C Module Operating Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-9 21.3.5 I2C Clock Generation and Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . 21-22 21.3.6 Using the USCI Module in I2C Mode With Low-Power Modes . . . . . . . . . 21-23 21.3.7 USCI Interrupts in I2C Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-24 21.4 USCI Registers: I2C Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-26
xiii
Contents
22 OA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-1 22.1 OA Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-2 22.2 OA Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-4 22.2.1 OA Amplifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-4 22.2.2 OA Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-4 22.2.3 OA Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-4 22.2.4 OA Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-5 22.3 OA Modules in MSP430FG42x0 Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-11 22.3.1 OA Amplifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-12 22.3.2 OA Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-12 22.3.3 OA Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-12 22.3.4 OA Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-12 22.3.5 Switch Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-14 22.3.6 Offset Calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-15 22.4 OA Modules in MSP430FG47x Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-16 22.4.1 OA Amplifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-18 22.4.2 OA Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-18 22.4.3 OA Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-18 22.4.4 OA Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-18 22.4.5 Switch Control of the FG47x devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-22 22.4.6 Offset Calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-23 22.5 OA Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-24 22.6 OA Registers in MSP430FG42x0 Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-27 22.7 OA Registers in MSP430FG47x Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-31 23 Comparator_A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23.1 Comparator_A Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23.2 Comparator_A Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23.2.1 Comparator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23.2.2 Input Analog Switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23.2.3 Output Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23.2.4 Voltage Reference Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23.2.5 Comparator_A, Port Disable Register CAPD . . . . . . . . . . . . . . . . . . . . . . . 23.2.6 Comparator_A Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23.2.7 Comparator_A Used to Measure Resistive Elements . . . . . . . . . . . . . . . . 23.3 Comparator_A Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23-1 23-2 23-4 23-4 23-4 23-5 23-5 23-6 23-6 23-7 23-9
24 Comparator_A+ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-1 24.1 Comparator_A+ Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-2 24.2 Comparator_A+ Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-4 24.2.1 Comparator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-4 24.2.2 Input Analog Switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-4 24.2.3 Input Short Switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-5 24.2.4 Output Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-6 24.2.5 Voltage Reference Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-6 24.2.6 Comparator_A+, Port Disable Register CAPD . . . . . . . . . . . . . . . . . . . . . . 24-7 24.2.7 Comparator_A+ Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-7 24.2.8 Comparator_A+ Used to Measure Resistive Elements . . . . . . . . . . . . . . . 24-8 24.3 Comparator_A+ Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-10
xiv
Contents
25 LCD Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-1 25.1 LCD Controller Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-2 25.2 LCD Controller Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-4 25.2.1 LCD Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-4 25.2.2 Blinking the LCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-4 25.2.3 LCD Timing Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-4 25.2.4 LCD Voltage Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-5 25.2.5 LCD Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-5 25.2.6 Static Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-6 25.2.7 2-Mux Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-9 25.2.8 3-Mux Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-12 25.2.9 4-Mux Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-15 25.3 LCD Controller Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-18 26 LCD_A Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-1 26.1 LCD_A Controller Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-2 26.2 LCD_A Controller Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-4 26.2.1 LCD Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-4 26.2.2 Blinking the LCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-4 26.2.3 LCD_A Voltage And Bias Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-5 26.2.4 LCD Timing Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-8 26.2.5 LCD Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-8 26.2.6 Static Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-9 26.2.7 2-Mux Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-12 26.2.8 3-Mux Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-15 26.2.9 4-Mux Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-18 26.3 LCD Controller Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-21 27 ADC10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-1 27.1 ADC10 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-2 27.2 ADC10 Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-4 27.2.1 10-Bit ADC Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-4 27.2.2 ADC10 Inputs and Multiplexer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-5 27.2.3 Voltage Reference Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-6 27.2.4 Auto Power-Down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-6 27.2.5 Sample and Conversion Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-7 27.2.6 Conversion Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-9 27.2.7 ADC10 Data Transfer Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-15 27.2.8 Using the Integrated Temperature Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . 27-21 27.2.9 ADC10 Grounding and Noise Considerations . . . . . . . . . . . . . . . . . . . . . . . 27-22 27.2.10 ADC10 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-23 27.3 ADC10 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-24
xv
Contents
28 ADC12 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-1 28.1 ADC12 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-2 28.2 ADC12 Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-4 28.2.1 12-Bit ADC Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-4 28.2.2 ADC12 Inputs and Multiplexer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-5 28.2.3 Voltage Reference Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-6 28.2.4 Auto Power-Down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-6 28.2.5 Sample and Conversion Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-7 28.2.6 Conversion Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-10 28.2.7 ADC12 Conversion Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-10 28.2.8 Using the Integrated Temperature Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . 28-16 28.2.9 ADC12 Grounding and Noise Considerations . . . . . . . . . . . . . . . . . . . . . . . 28-17 28.2.10 ADC12 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-18 28.3 ADC12 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-20 29 SD16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-1 29.1 SD16 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-2 29.2 SD16 Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-4 29.2.1 ADC Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-4 29.2.2 Analog Input Range and PGA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-4 29.2.3 Voltage Reference Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-4 29.2.4 Auto Power-Down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-4 29.2.5 Analog Input Pair Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-5 29.2.6 Analog Input Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-6 29.2.7 Digital Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-7 29.2.8 Conversion Memory Registers: SD16MEMx . . . . . . . . . . . . . . . . . . . . . . . . 29-10 29.2.9 Conversion Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-11 29.2.10 Conversion Operation Using Preload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-14 29.2.11 Using the Integrated Temperature Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . 29-16 29.2.12 Interrupt Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-17 29.3 SD16 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-19 30 SD16_A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-1 30.1 SD16_A Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-2 30.2 SD16_A Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-5 30.2.1 ADC Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-5 30.2.2 Analog Input Range and PGA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-5 30.2.3 Voltage Reference Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-5 30.2.4 Auto Power-Down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-5 30.2.5 Analog Input Pair Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-6 30.2.6 Analog Input Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-7 30.2.7 Digital Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-8 30.2.8 Conversion Memory Register: SD16MEMx . . . . . . . . . . . . . . . . . . . . . . . . . 30-12 30.2.9 Conversion Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-14 30.2.10 Conversion Operation Using Preload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-17 30.2.11 Using the Integrated Temperature Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . 30-19 30.2.12 Interrupt Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-20 30.3 SD16_A Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-22
xvi
Contents
31 DAC12 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31-1 31.1 DAC12 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31-2 31.2 DAC12 Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31-6 31.2.1 DAC12 Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31-6 31.2.2 DAC12 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31-7 31.2.3 Updating the DAC12 Voltage Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31-8 31.2.4 DAC12_xDAT Data Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31-9 31.2.5 DAC12 Output Amplifier Offset Calibration . . . . . . . . . . . . . . . . . . . . . . . . . 31-10 31.2.6 Grouping Multiple DAC12 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31-11 31.2.7 DAC12 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31-12 31.3 DAC12 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31-13 32 Scan IF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32-1 32.1 Scan IF Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32-2 32.2 Scan IF Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32-4 32.2.1 Scan IF Analog Front End . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32-4 32.2.2 Scan IF Timing State Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32-14 32.2.3 Scan IF Processing State Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32-20 32.2.4 Scan IF Debug Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32-26 32.2.5 Scan IF Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32-27 32.2.6 Using the Scan IF with LC Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32-28 32.2.7 Using the Scan IF With Resistive Sensors . . . . . . . . . . . . . . . . . . . . . . . . . 32-32 32.2.8 Quadrature Decoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32-33 32.3 Scan IF Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32-35 33 Embedded Emulation Module (EEM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33.1 EEM Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33.2 EEM Building Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33.2.1 Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33.2.2 Trigger Sequencer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33.2.3 State Storage (Internal Trace Buffer) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33.2.4 Clock Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33.3 EEM Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33-1 33-2 33-4 33-4 33-5 33-5 33-5 33-6
xvii
xviii
Chapter 1
Introduction
This chapter describes the architecture of the MSP430.
Topic
1.1 1.2 1.3 1.4
Page
Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Flexible Clock System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Embedded Emulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3 Address Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
Introduction
1-1
Architecture
1.1 Architecture
The MSP430 incorporates a 16-bit RISC CPU, peripherals, and a flexible clock system that interconnect using a von Neumann common memory address bus (MAB) and memory data bus (MDB). Partnering a modern CPU with modular memory-mapped analog and digital peripherals, the MSP430 offers solutions for demanding mixed-signal applications. Key features of the MSP430x4xx family include:
- Ultralow-power architecture extends battery life J J J
0.1-A RAM retention 0.8-A real-time clock mode 250-A / MIPS active
12-bit or 10-bit ADC 200 ksps, temperature sensor, VRef 12-bit dual DAC Comparator-gated timers for measuring resistive elements Supply voltage supervisor
- 16-bit RISC CPU enables new applications at a fraction of the code size. J J J J J
Large register file eliminates working file bottleneck Compact core design reduces power consumption and cost Optimized for modern high-level programming Only 27 core instructions and seven addressing modes Extensive vectored-interrupt capability
1-2
Introduction
Embedded Emulation
Clock System
MCLK
ACLK SMCLK
Flash/ ROM
RAM
Peripheral
Peripheral
Peripheral
JTAG/Debug
MAB 16-Bit
MDB 16-Bit
Bus Conv.
MDB 8-Bit
JTAG
ACLK SMCLK
Watchdog
Peripheral
Peripheral
Peripheral
Peripheral
development and debug with full-speed execution, breakpoints, and single steps in an application are supported.
final application.
- Mixed-signal integrity is preserved and not subject to cabling interference.
Introduction
1-3
Address Space
0200h 01FFh
RAM
Word/Byte
16-Bit Peripheral Modules 0100h 0FFh 010h 0Fh 0h 8-Bit Peripheral Modules Special Function Registers
Word
Byte
Byte
1.4.1
Flash/ROM
The start address of Flash/ROM depends on the amount of Flash/ROM present and varies by device. The end address for Flash/ROM is 0FFFFh for devices with less than 60kB of Flash/ROM; otherwise, it is device dependent. Flash can be used for both code and data. Word or byte tables can be stored and used in Flash/ROM without the need to copy the tables to RAM before using them. The interrupt vector table is mapped into the upper 16 words of Flash/ROM address space, with the highest priority interrupt vector at the highest Flash/ROM word address (0FFFEh).
1-4
Introduction
Address Space
1.4.2
RAM
RAM starts at 0200h. The end address of RAM depends on the amount of RAM present and varies by device. RAM can be used for both code and data.
1.4.3
Peripheral Modules
Peripheral modules are mapped into the address space. The address space from 0100 to 01FFh is reserved for 16-bit peripheral modules. These modules should be accessed with word instructions. If byte instructions are used, only even addresses are permissible, and the high byte of the result is always 0. The address space from 010h to 0FFh is reserved for 8-bit peripheral modules. These modules should be accessed with byte instructions. Read access of byte modules using word instructions results in unpredictable data in the high byte. If word data is written to a byte module only the low byte is written into the peripheral register, ignoring the high byte.
1.4.4
1.4.5
Memory Organization
Bytes are located at even or odd addresses. Words are only located at even addresses as shown in Figure 13. When using word instructions, only even addresses may be used. The low byte of a word is always an even address. The high byte is at the next odd address. For example, if a data word is located at address xxx4h, then the low byte of that data word is located at address xxx4h, and the high byte of that word is located at address xxx5h.
Introduction
1-5
Address Space
xxxAh 15 7 14 6 . . Bits . . . . Bits . . Byte Byte Word (High Byte) Word (Low Byte) 9 1 8 0 xxx9h xxx8h xxx7h xxx6h xxx5h xxx4h xxx3h
1-6
Introduction
Chapter 2
Topic
2.1 2.2 2.3 2.4 2.5
Page
System Reset and Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5 Operating Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-13 Principles for Low-Power Applications . . . . . . . . . . . . . . . . . . . . . . . . . 2-16 Connection of Unused Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16
2-1
S R ~ 50us
POR Latch
POR
Delay
PUC
EQU KEYV (from flash module) From watchdog timer peripheral module
Resetwd2
MCLK
A POR is a device reset. A POR is only generated by the following three events:
- Powering up the device - A low signal on the RST/NMI pin when configured in the reset mode - An SVS low condition when PORON = 1.
A PUC is always generated when a POR is generated, but a POR is not generated by a PUC. The following events trigger a PUC:
- A POR signal - Watchdog timer expiration when in watchdog mode only - Watchdog timer security key violation - A Flash memory security key violation
2-2
2.1.1
(BOR)
As the V(B_IT) level is significantly above the V(MIN) level of the POR circuit, the BOR provides a reset for power failures where VCC does not fall below V(MIN). See the device-specific data sheet for parameters.
2-3
2.1.2
Software Initialization
After a system reset, user software must initialize the MSP430 for the application requirements. The following must occur:
- Initialize the SP, typically to the top of RAM. - Initialize the watchdog to the requirements of the application. - Configure peripheral modules to the requirements of the application.
Additionally, the watchdog timer, oscillator fault, and flash memory flags can be evaluated to determine the source of the reset.
2-4
2.2 Interrupts
The interrupt priorities are fixed and defined by the arrangement of the modules in the connection chain as shown in Figure 23. The nearer a module is to the CPU/NMIRS, the higher the priority. Interrupt priorities determine what interrupt is taken when more than one interrupt is pending simultaneously. There are three types of interrupts:
- System reset - (Non)-maskable NMI - Maskable
Priority
High
Low
GMIRS
PUC
Bus Grant
PUC
OSCfault Flash ACCV Reset/NMI
Circuit
2-5
2.2.1
Reset/NMI Pin
At power-up, the RST/NMI pin is configured in the reset mode. The function of the RST/NMI pins is selected in the watchdog control register WDTCTL. If the RST/NMI pin is set to the reset function, the CPU is held in the reset state as long as the RST/NMI pin is held low. After the input changes to a high state, the CPU starts program execution at the word address stored in the reset vector, 0FFFEh. If the RST/NMI pin is configured by user software to the NMI function, a signal edge selected by the WDTNMIES bit generates an NMI interrupt if the NMIIE bit is set. The RST/NMI flag NMIIFG is also set. Note: Holding RST/NMI Low
When configured in the NMI mode, a signal generating an NMI event should not hold the RST/NMI pin low. If a PUC occurs from a different source while the NMI signal is low, the device will be held in the reset state because a PUC changes the RST/NMI pin to the reset function.
Note:
Modifying WDTNMIES
When NMI mode is selected and the WDTNMIES bit is changed, an NMI can be generated, depending on the actual level at the RST/NMI pin. When the NMI edge select bit is changed before selecting the NMI mode, no NMI is generated.
2-6
POR
PUC
S IFG1.4 Clear
PUC NMIIE IE1.4 Clear PUC Counter OSCFault S IFG1.1 IRQA OFIE IE1.1 Clear NMI_IRQA PUC Watchdog Timer Module PUC IE1.0 Clear WDTTMSEL WDTIE OFIFG POR WDT IFG1.0 Clear S WDTIFG IRQ
2-7
Oscillator Fault
The oscillator fault signal warns of a possible error condition with the crystal oscillator. The oscillator fault can be enabled to generate an NMI interrupt by setting the OFIE bit. The OFIFG flag can then be tested by NMI the interrupt service routine to determine if the NMI was caused by an oscillator fault. A PUC signal can trigger an oscillator fault, because the PUC switches the LFXT1 to LF mode, therefore switching off the HF mode. The PUC signal also switches off the XT2 oscillator.
2-8
no
Optional
Note:
To prevent nested NMI interrupts, the ACCVIE, NMIIE, and OFIE enable bits should not be set inside of an NMI interrupt service routine.
2.2.2
Maskable Interrupts
Maskable interrupts are caused by peripherals with interrupt capability including the watchdog timer overflow in interval-timer mode. Each maskable interrupt source can be disabled individually by an interrupt enable bit, or all maskable interrupts can be disabled by the general interrupt enable (GIE) bit in the status register (SR). Each individual peripheral interrupt is discussed in the associated peripheral module chapter in this manual.
2-9
2.2.3
Interrupt Processing
When an interrupt is requested from a peripheral and the peripheral interrupt enable bit and GIE bit are set, the interrupt service routine is requested. Only the individual enable bit must be set for (non)-maskable interrupts to be requested.
Interrupt Acceptance
The interrupt latency is six cycles, starting with the acceptance of an interrupt request and lasting until the start of execution of the first instruction of the interrupt-service routine, as shown in Figure 26. The interrupt logic executes the following: 1) Any currently executing instruction is completed. 2) The PC, which points to the next instruction, is pushed onto the stack. 3) The SR is pushed onto the stack. 4) The interrupt with the highest priority is selected if multiple interrupts occurred during the last instruction and are pending for service. 5) The interrupt request flag resets automatically on single-source flags. Multiple source flags remain set for servicing by software. 6) The SR is cleared with the exception of SCG0, which is left unchanged. This terminates any low-power mode. Because the GIE bit is cleared, further interrupts are disabled. 7) The content of the interrupt vector is loaded into the PC: the program continues with the interrupt service routine at that address.
2-10
The return from the interrupt takes 5 cycles to execute the following actions and is illustrated in Figure 27. 1) The SR with all previous settings pops from the stack. All previous settings of GIE, CPUOFF, etc. are now in effect, regardless of the settings used during the interrupt service routine. 2) The PC pops from the stack and begins execution at the point where it was interrupted.
Interrupt nesting is enabled if the GIE bit is set inside an interrupt service routine. When interrupt nesting is enabled, any interrupt occurring during an interrupt service routine will interrupt the routine, regardless of the interrupt priorities.
2-11
2.2.4
Interrupt Vectors
The interrupt vectors and the power-up starting address are located in the address range 0FFFFh to 0FFE0h as described in Table 21. A vector is programmed by the user with the 16-bit address of the corresponding interrupt service routine. Some devices may contain more interrupt vectors. See the device-specific data sheet for the complete interrupt vector list.
Power-up, external reset, watchdog, flash password NMI, oscillator fault, flash memory access violation Device-specific Device-specific Device-specific Watchdog timer Device-specific Device-specific Device-specific Device-specific Device-specific Device-specific Device-specific Device-specific Device-specific Device-specific
0FFFEh
15, highest
14 13 12 11 10 9 8 7 6 5 4 3 2 1 0, lowest
WDTIFG
maskable
0FFF4h 0FFF2h 0FFF0h 0FFEEh 0FFECh 0FFEAh 0FFE8h 0FFE6h 0FFE4h 0FFE2h 0FFE0h
2.2.5
2-12
Operating Modes
ICC/ A @ 1 MHz
200
VCC = 3 V VCC = 2.2 V 55 32 17 11 0.9 0.7 LPM3 0.1 0.1 LPM4 LPM2
AM
LPM0
Operating Modes
The low-power modes 0 to 4 are configured with the CPUOFF, OSCOFF, SCG0, and SCG1 bits in the status register. The advantage of including the CPUOFF, OSCOFF, SCG0, and SCG1 mode-control bits in the status register is that the present operating mode is saved onto the stack during an interrupt service routine. Program flow returns to the previous operating mode if the saved SR value is not altered during the interrupt service routine. Program flow can be returned to a different operating mode by manipulating the saved SR value on the stack inside of the interrupt service routine. The mode-control bits and the stack can be accessed with any instruction. When setting any of the mode-control bits, the selected operating mode takes effect immediately. Peripherals operating with any disabled clock are disabled until the clock becomes active. The peripherals may also be disabled with their individual control register settings. All I/O port pins and RAM/registers are unchanged. Wake up is possible through all enabled interrupts.
2-13
Operating Modes
POR WDT Active, Time Expired, Overflow WDTIFG = 1 WDTIFG = 1 WDT Active, Security Key Violation WDTIFG = 0 PUC RST/NMI is Reset Pin WDT is Active RST/NMI NMI Active
CPUOFF = 1 SCG0 = 0 SCG1 = 0 LPM0 CPU Off, FLL+ On, 41x/42x MCLK On, 43x/44x MCLK off, ACLK On CPUOFF = 1 SCG0 = 1 SCG1 = 0 LPM1 CPU Off, FLL+ Off, 41x/42x MCLK On, 43x/44x MCLK off ACLK On
CPUOFF = 1 OSCOFF = 1 SCG0 = 1 SCG1 = 1 LPM4 CPU Off, FLL+ Off, MCLK Off, ACLK Off DC Generator Off
DC Generator Off
SCG1 0 0
SCG0 OSCOFF 0 0 0 0
CPUOFF 0 1
CPU and Clocks Status CPU is active, all enabled clocks are active CPU, MCLK are disabled (41x/42x peripheral MCLK remains on) SMCLK , ACLK are active CPU, MCLK, DCO oscillator are disabled (41x/42x peripheral MCLK remains on) DC generator is disabled if the DCO is not used for MCLK or SMCLK in active mode SMCLK , ACLK are active CPU, MCLK, SMCLK, DCO oscillator are disabled DC generator remains enabled ACLK is active CPU, MCLK, SMCLK, DCO oscillator are disabled DC generator disabled ACLK is active CPU and all clocks disabled
LPM1
LPM2
LPM3
LPM4
2-14
Operating Modes
2.3.1
The PC and SR are stored on the stack The CPUOFF, SCG1, and OSCOFF bits are automatically reset
The original SR is popped from the stack, restoring the previous operating mode. The SR bits stored on the stack can be modified within the interrupt service routine returning to a different operating mode when the RETI instruction is executed.
; Enter LPM0 Example BIS #GIE+CPUOFF,SR ; Enter LPM0 ; ... ; Program stops here ; ; Exit LPM0 Interrupt Service Routine BIC #CPUOFF,0(SP) ; Exit LPM0 on RETI RETI ; Enter LPM3 Example BIS #GIE+CPUOFF+SCG1+SCG0,SR ; Enter LPM3 ; ... ; Program stops here ; ; Exit LPM3 Interrupt Service Routine BIC #CPUOFF+SCG1+SCG0,0(SP) ; Exit LPM3 on RETI RETI
2-15
functions. For example Timer_A and Timer_B can automatically generate PWM and capture external timing, with no CPU resources.
- Calculated branching and fast table look-ups should be used in place of
Potential DVCC DVSS Open DVSS DVSS DVCC Open DVSS Open Open DVCC or VCC DVSS Open Open Open Open
Comment
43x, 44x. and 46x devices 43x, 44x, and 46x devices Switched to port function, output direction 47-k pullup with 10-nF (2.2 nF) pulldown
42x devices
MSP430F41x2 only: The pulldown capacitor should not exceed 2.2 nF when using Spy-Bi-Wire interface in Spy-Bi-Wire mode or in 4-wire JTAG mode with TI tools like FET interfaces or GANG programmers.
2-16
Chapter 3
Topic
3.1 3.2 3.3 3.4
Page
CPU Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 CPU Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4 Addressing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9 Instruction Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17
3-1
CPU Introduction
addressing mode
- Full register access including program counter, status registers, and stack
pointer
- Single-cycle register operations - Large 16-bit register file reduces fetches to memory - 16-bit address bus allows direct access and branching throughout entire
memory range
- 16-bit data bus allows direct manipulation of word-wide arguments - Constant generator provides six most used immediate values and
3-2
CPU Introduction
3-3
CPU Registers
3.2.1
The PC can be addressed with all instructions and addressing modes. A few examples:
MOV MOV MOV #LABEL,PC ; Branch to address LABEL LABEL,PC ; Branch to address contained in LABEL @R14,PC ; Branch indirect to address in R14
3-4
CPU Registers
3.2.2
; ; ; ;
Item I2 > R6 Overwrite TOS with R7 Put 0123h onto TOS R8 = 0123h
The special cases of using the SP as an argument to the PUSH and POP instructions are described and shown in Figure 35.
The stack pointer is not changed after a POP SP instruction. The POP SP instruction places SP1 into the stack pointer SP (SP2=SP1)
3-5
CPU Registers
3.2.3
rw-0
SUB(.B),SUBC(.B),CMP(.B)
System clock generator 1. This bit, when set, turns off the DCO dc generator, if DCOCLK is not used for MCLK or SMCLK. System clock generator 0. This bit, when set, turns off the FLL+ loop control Oscillator Off. This bit, when set, turns off the LFXT1 crystal oscillator, when LFXT1CLK is not use for MCLK or SMCLK CPU off. This bit, when set, turns off the CPU. General interrupt enable. This bit, when set, enables maskable interrupts. When reset, all maskable interrupts are disabled. Negative bit. This bit is set when the result of a byte or word operation is negative and cleared when the result is not negative. Word operation: N is set to the value of bit 15 of the result Byte operation: N is set to the value of bit 7 of the result Zero bit. This bit is set when the result of a byte or word operation is 0 and cleared when the result is not 0. Carry bit. This bit is set when the result of a byte or word operation produced a carry and cleared when no carry occurred.
Z C
3-6
CPU Registers
3.2.4
The assembler uses the constant generator automatically if one of the six constants is used as an immediate source operand. Registers R2 and R3, used in the constant mode, cannot be addressed explicitly; they act as source-only registers.
is emulated by the double-operand instruction with the same length: MOV R3,dst
where the #0 is replaced by the assembler, and R3 is used with As = 00. INC is replaced by: ADD 0(R3),dst dst
3-7
CPU Registers
3.2.5
Byte
Memory
0h
Register
Example Register-Byte Operation R5 = 0A28Fh R6 = 0203h Mem(0203h) = 012h ADD.B R5,0(R6) 08Fh + 012h 0A1h Mem (0203h) = 0A1h C = 0, Z = 0, N = 1 (Low byte of register) + (Addressed byte) >(Addressed byte)
Example Byte-Register Operation R5 = 01202h R6 = 0223h Mem(0223h) = 05Fh ADD.B 05Fh + 002h 00061h R5 = 00061h C = 0, Z = 0, N = 0 (Addressed byte) + (Low byte of register) >(Low byte of register, zero to High byte) @R6,R5
3-8
Addressing Modes
01/1
Absolute mode
&ADDR
10/ 11/
@Rn @Rn+
11/
Immediate mode
#N
The seven addressing modes are explained in detail in the following sections. Most of the examples show the same addressing mode for the source and destination, but any valid combination of source and destination addressing modes is possible in an instruction. Note: Use of Labels EDE, TONI, TOM, and LEO
Throughout MSP430 documentation, EDE, TONI, TOM, and LEO are used as generic labels. They are only labels. They have no special meaning.
3-9
Addressing Modes
3.3.1
Register Mode
The register mode is described in Table 34.
One or two words Move the content of R10 to R11. R10 is not affected. Valid for source and destination MOV R10,R11
After: R10 0A023h
R11
0FA15h
R11
0A023h
PC
PCold
PC
PCold + 2
Note:
Data in Registers
The data in the register can be accessed using word or byte instructions. If byte instructions are used, the high byte is always 0 in the result. The status bits are handled according to the result of the byte instruction.
3-10
Addressing Modes
3.3.2
Indexed Mode
The indexed mode is described in Table 35.
Length: Operation:
Two or three words Move the contents of the source address (contents of R5 + 2) to the destination address (contents of R6 + 6). The source and destination registers (R5 and R6) are not affected. In indexed mode, the program counter is incremented automatically so that program execution continues with the next instruction. Valid for source and destination MOV 2(R5),6(R6);
Register After: Address Space 0xxxxh 0FF16h 00006h 0FF14h 0FF12h 00002h 04596h Register PC R5 01080h R6 0108Ch
Comment: Example:
Before: Address Space
R5 R6
01080h 0108Ch
3-11
Addressing Modes
3.3.3
Symbolic Mode
The symbolic mode is described in Table 36.
X = EDE PC Y = TONI PC
Length: Operation:
Two or three words Move the contents of the source address EDE (contents of PC + X) to the destination address TONI (contents of PC + Y). The words after the instruction contain the differences between the PC and the source or destination addresses. The assembler computes and inserts offsets X and Y automatically. With symbolic mode, the program counter (PC) is incremented automatically so that program execution continues with the next instruction. Valid for source and destination MOV EDE,TONI ;Source address EDE = 0F016h ;Dest. address TONI=01114h
Register After: Address Space 0xxxxh 011FEh 0F102h 04090h Register PC
Comment: Example:
Before:
3-12
Addressing Modes
3.3.4
Absolute Mode
The absolute mode is described in Table 37.
Length: Operation:
Two or three words Move the contents of the source address EDE to the destination address TONI. The words after the instruction contain the absolute address of the source and destination addresses. With absolute mode, the PC is incremented automatically so that program execution continues with the next instruction. Valid for source and destination MOV &EDE,&TONI ;Source address EDE=0F016h, ;dest. address TONI=01114h
Register After: Address Space 0xxxxh 01114h 0F016h 04292h Register PC
Comment: Example:
Before:
This address mode is mainly for hardware peripheral modules that are located at an absolute, fixed address. These are addressed with absolute mode to ensure software transportability (for example, position-independent code).
3-13
Addressing Modes
3.3.5
Length: Operation:
One or two words Move the contents of the source address (contents of R10) to the destination address (contents of R11). The registers are not modified. Valid only for source operand. The substitute for destination operand is 0(Rd). MOV.B @R10,0(R11)
Register After: Address Space 0xxxxh 0FF16h 0000h 0FF14h 0FF12h 04AEBh 0xxxxh Register PC R10 0FA33h R11 002A7h
Comment:
Example:
Before: Address Space 0xxxxh 0000h 04AEBh 0xxxxh
R10 PC R11
0FA33h 002A7h
3-14
Addressing Modes
3.3.6
Length: Operation:
One or two words Move the contents of the source address (contents of R10) to the destination address (contents of R11). Register R10 is incremented by 1 for a byte operation, or 2 for a word operation after the fetch; it points to the next address without any overhead. This is useful for table processing. Valid only for source operand. The substitute for destination operand is 0(Rd) plus second instruction INCD Rd. MOV @R10+,0(R11)
Register After: Address Space 0xxxxh 00000h 04ABBh 0xxxxh PC R10 0FA34h R11 010A8h Register
Comment:
Example:
Before:
0FA32h 010A8h
0FF14h 04ABBh
The autoincrementing of the register contents occurs after the operand is fetched. This is shown in Figure 38.
3-15
Addressing Modes
3.3.7
Immediate Mode
The immediate mode is described in Table 310.
Length:
Two or three words It is one word less if a constant of CG1 or CG2 can be used. Move the immediate constant 45h, which is contained in the word following the instruction, to destination address TONI. When fetching the source, the program counter points to the word following the instruction and moves the contents to the destination. Valid only for a source operand. MOV
Address Space 01192h 00045h 040B0h PC
Operation:
Comment: Example:
Before:
#45h,TONI
Register After: Address Space 0xxxxh 01192h 00045h 040B0h Register PC
3-16
Instruction Set
All single-operand and dual-operand instructions can be byte or word instructions by using .B or .W extensions. Byte instructions are used to access byte data or byte peripherals. Word instructions are used to access word data or word peripherals. If no extension is used, the instruction is a word instruction. The source and destination of an instruction are defined by the following fields: src dst As S-reg Ad D-reg B/W The source operand defined by As and S-reg The destination operand defined by Ad and D-reg The addressing bits responsible for the addressing mode used for the source (src) The working register used for the source (src) The addressing bits responsible for the addressing mode used for the destination (dst) The working register used for the destination (dst) Byte or word operation: 0: word operation 1: byte operation Destination Address
Note:
Destination addresses are valid anywhere in the memory map. However, when using an instruction that modifies the contents of the destination, the user must ensure the destination address is writable. For example, a masked-ROM location would be a valid destination address, but the contents are not modifiable, so the results of the instruction would be lost.
3-17
Instruction Set
3.4.1
Op-code
S-Reg
D-Reg
MOV(.B) ADD(.B) ADDC(.B) SUB(.B) SUBC(.B) CMP(.B) DADD(.B) BIT(.B) BIC(.B) BIS(.B) XOR(.B) AND(.B)
* 0 1
The status bit is affected The status bit is not affected The status bit is cleared The status bit is set Instructions CMP and SUB
Note:
The instructions CMP and SUB are identical except for the storage of the result. The same is true for the BIT and AND instructions.
3-18
Instruction Set
3.4.2
D/S-Reg
* 0 1
The status bit is affected The status bit is not affected The status bit is cleared The status bit is set
All addressing modes are possible for the CALL instruction. If the symbolic mode (ADDRESS), the immediate mode (#N), the absolute mode (&EDE), or the indexed mode x(RN) is used, the word that follows contains the address information.
3-19
Instruction Set
3.4.3
Jumps
Figure 311 shows the conditional-jump instruction format.
Op-code
10-Bit PC Offset
Conditional jumps support program branching relative to the PC and do not affect the status bits. The possible jump range is from 511 to +512 words relative to the PC value at the jump instruction. The 10-bit program-counter offset is treated as a signed 10-bit value that is doubled and added to the program counter: PCnew = PCold + 2 + PCoffset 2
3-20
Instruction Set
Add carry to destination Add carry to destination ADC ADC.B dst dst or ADC.W dst
Operation Emulation
Description
The carry bit (C) is added to the destination operand. The previous contents of the destination are lost. N: Set if result is negative, reset if positive Z: Set if result is zero, reset otherwise C: Set if dst was incremented from 0FFFFh to 0000, reset otherwise Set if dst was incremented from 0FFh to 00, reset otherwise V: Set if an arithmetic overflow occurs, otherwise reset OSCOFF, CPUOFF, and GIE are not affected. The 16-bit counter pointed to by R13 is added to a 32-bit counter pointed to by R12. ADD @R13,0(R12) ; Add LSDs ADC 2(R12) ; Add carry to MSD The 8-bit counter pointed to by R13 is added to a 16-bit counter pointed to by R12. ADD.B @R13,0(R12) ; Add LSDs ADC.B 1(R12) ; Add carry to MSD
Status Bits
Example
3-21
Instruction Set
Add source to destination Add source to destination ADD ADD.B src,dst src,dst or ADD.W src,dst
Operation Description
src + dst > dst The source operand is added to the destination operand. The source operand is not affected. The previous contents of the destination are lost. N: Z: C: V: Set if result is negative, reset if positive Set if result is zero, reset otherwise Set if there is a carry from the result, cleared if not Set if an arithmetic overflow occurs, otherwise reset
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. R5 is increased by 10. The jump to TONI is performed on a carry. ADD JC ...... #10,R5 TONI
Example
R5 is increased by 10. The jump to TONI is performed on a carry. ADD.B JC ...... #10,R5 TONI ; Add 10 to Lowbyte of R5 ; Carry occurred, if (R5) 246 [0Ah+0F6h] ; No carry
3-22
Instruction Set
Add source and carry to destination Add source and carry to destination ADDC ADDC.B src,dst src,dst or ADDC.W src,dst
Operation Description
src + dst + C > dst The source operand and the carry bit (C) are added to the destination operand. The source operand is not affected. The previous contents of the destination are lost. N: Z: C: V: Set if result is negative, reset if positive Set if result is zero, reset otherwise Set if there is a carry from the MSB of the result, reset otherwise Set if an arithmetic overflow occurs, otherwise reset
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. The 32-bit counter pointed to by R13 is added to a 32-bit counter, eleven words (20/2 + 2/2) above the pointer in R13. ADD ADDC ... @R13+,20(R13) @R13+,20(R13) ; ADD LSDs with no carry in ; ADD MSDs with carry ; resulting from the LSDs
Example
The 24-bit counter pointed to by R13 is added to a 24-bit counter, eleven words above the pointer in R13. ADD.B ADDC.B ADDC.B ... @R13+,10(R13) @R13+,10(R13) @R13+,10(R13) ; ADD LSDs with no carry in ; ADD medium Bits with carry ; ADD MSDs with carry ; resulting from the LSDs
3-23
Instruction Set
Source AND destination Source AND destination AND AND.B src,dst src,dst or AND.W src,dst
Operation Description
src .AND. dst > dst The source operand and the destination operand are logically ANDed. The result is placed into the destination. N: Z: C: V: Set if result MSB is set, reset if not set Set if result is zero, reset otherwise Set if result is not zero, reset otherwise ( = .NOT. Zero) Reset
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. The bits set in R5 are used as a mask (#0AA55h) for the word addressed by TOM. If the result is zero, a branch is taken to label TONI. MOV AND JZ ...... ; ; ; ; ; AND JZ #0AA55h,R5 R5,TOM TONI ; Load mask into register R5 ; mask word addressed by TOM with R5 ; ; Result is not zero
or
#0AA55h,TOM TONI
Example
The bits of mask #0A5h are logically ANDed with the low byte TOM. If the result is zero, a branch is taken to label TONI. AND.B JZ ...... #0A5h,TOM TONI ; mask Lowbyte TOM with 0A5h ; ; Result is not zero
3-24
Instruction Set
Clear bits in destination Clear bits in destination BIC BIC.B src,dst src,dst or BIC.W src,dst
Operation Description
.NOT.src .AND. dst > dst The inverted source operand and the destination operand are logically ANDed. The result is placed into the destination. The source operand is not affected. Status bits are not affected. OSCOFF, CPUOFF, and GIE are not affected. The six MSBs of the RAM word LEO are cleared. BIC #0FC00h,LEO ; Clear 6 MSBs in MEM(LEO)
Example
The five MSBs of the RAM byte LEO are cleared. BIC.B #0F8h,LEO ; Clear 5 MSBs in Ram location LEO
3-25
Instruction Set
Set bits in destination Set bits in destination BIS BIS.B src,dst src,dst or BIS.W src,dst
Operation Description
src .OR. dst > dst The source operand and the destination operand are logically ORed. The result is placed into the destination. The source operand is not affected. Status bits are not affected. OSCOFF, CPUOFF, and GIE are not affected. The six LSBs of the RAM word TOM are set. BIS #003Fh,TOM; set the six LSBs in RAM location TOM
Example
The three MSBs of RAM byte TOM are set. BIS.B #0E0h,TOM ; set the three MSBs in RAM location TOM
3-26
Instruction Set
Test bits in destination Test bits in destination BIT src .AND. dst The source and destination operands are logically ANDed. The result affects only the status bits. The source and destination operands are not affected. N: Z: C: V: Set if MSB of result is set, reset otherwise Set if result is zero, reset otherwise Set if result is not zero, reset otherwise (.NOT. zero) Reset src,dst or BIT.W src,dst
OSCOFF, CPUOFF, and GIE are not affected. If bit 9 of R8 is set, a branch is taken to label TOM. BIT JNZ ... #0200h,R8 TOM ; bit 9 of R8 set? ; Yes, branch to TOM ; No, proceed
Example
Example
A serial communication receive bit (RCV) is tested. Because the carry bit is equal to the state of the tested bit while using the BIT instruction to test a single bit, the carry bit is used by the subsequent instruction; the read information is shifted into register RECBUF. ; ; Serial communication with LSB is shifted first: ; xxxx xxxx xxxx xxxx BIT.B #RCV,RCCTL ; Bit info into carry RRC RECBUF ; Carry > MSB of RECBUF ; cxxx xxxx ...... ; repeat previous two instructions ...... ; 8 times ; cccc cccc ; ^ ^ ; MSB LSB ; Serial communication with MSB shifted first: BIT.B #RCV,RCCTL ; Bit info into carry RLC.B RECBUF ; Carry > LSB of RECBUF ; xxxx xxxc ...... ; repeat previous two instructions ...... ; 8 times ; cccc cccc ;| LSB ; MSB
3-27
Instruction Set
An unconditional branch is taken to an address anywhere in the 64K address space. All source addressing modes can be used. The branch instruction is a word instruction. Status bits are not affected. Examples for all addressing modes are given. BR #EXEC ;Branch to label EXEC or direct branch (e.g. #0A4h) ; Core instruction MOV @PC+,PC ; Branch to the address contained in EXEC ; Core instruction MOV X(PC),PC ; Indirect address ; Branch to the address contained in absolute ; address EXEC ; Core instruction MOV X(0),PC ; Indirect address ; Branch to the address contained in R5 ; Core instruction MOV R5,PC ; Indirect R5 ; Branch to the address contained in the word ; pointed to by R5. ; Core instruction MOV @R5,PC ; Indirect, indirect R5 ; Branch to the address contained in the word pointed ; to by R5 and increment pointer in R5 afterwards. ; The next timeS/W flow uses R5 pointerit can ; alter program execution due to access to ; next address in a table pointed to by R5 ; Core instruction MOV @R5,PC ; Indirect, indirect R5 with autoincrement ; Branch to the address contained in the address ; pointed to by R5 + X (e.g. table with address ; starting at X). X can be an address or a label ; Core instruction MOV X(R5),PC ; Indirect, indirect R5 + X
BR
EXEC
BR
&EXEC
BR
R5
BR
@R5
BR
@R5+
BR
X(R5)
3-28
Instruction Set
Subroutine CALL dst SP 2 PC tmp dst > tmp > SP > @SP > PC dst is evaluated and stored PC updated to TOS dst saved to PC
Description
A subroutine call is made to an address anywhere in the 64K address space. All addressing modes can be used. The return address (the address of the following instruction) is stored on the stack. The call instruction is a word instruction. Status bits are not affected. Examples for all addressing modes are given. CALL #EXEC ; Call on label EXEC or immediate address (e.g. #0A4h) ; SP2 SP, PC+2 @SP, @PC+ PC ; Call on the address contained in EXEC ; SP2 SP, PC+2 @SP, X(PC) PC ; Indirect address ; Call on the address contained in absolute address ; EXEC ; SP2 SP, PC+2 @SP, X(0) PC ; Indirect address ; Call on the address contained in R5 ; SP2 SP, PC+2 @SP, R5 PC ; Indirect R5 ; Call on the address contained in the word ; pointed to by R5 ; SP2 SP, PC+2 @SP, @R5 PC ; Indirect, indirect R5 ; Call on the address contained in the word ; pointed to by R5 and increment pointer in R5. ; The next timeS/W flow uses R5 pointer ; it can alter the program execution due to ; access to next address in a table pointed to by R5 ; SP2 SP, PC+2 @SP, @R5 PC ; Indirect, indirect R5 with autoincrement ; Call on the address contained in the address pointed ; to by R5 + X (e.g. table with address starting at X) ; X can be an address or a label ; SP2 SP, PC+2 @SP, X(R5) PC ; Indirect, indirect R5 + X
CALL
EXEC
CALL
&EXEC
CALL
R5
CALL
@R5
CALL
@R5+
CALL
X(R5)
3-29
Instruction Set
Clear destination Clear destination CLR CLR.B 0 > dst MOV MOV.B #0,dst #0,dst dst dst or CLR.W dst
Operation Emulation
The destination operand is cleared. Status bits are not affected. RAM word TONI is cleared. CLR TONI ; 0 > TONI
Example
Example
3-30
Instruction Set
The carry bit (C) is cleared. The clear carry instruction is a word instruction. N: Z: C: V: Not affected Not affected Cleared Not affected
OSCOFF, CPUOFF, and GIE are not affected. The 16-bit decimal counter pointed to by R13 is added to a 32-bit counter pointed to by R12. CLRC DADD DADC ; C = 0: defines start @R13,0(R12) ; add 16-bit counter to low word of 32-bit counter 2(R12) ; add carry to high word of 32-bit counter
3-31
Instruction Set
Clear negative bit CLRN 0N or (.NOT.src .AND. dst > dst) BIC #4,SR
Emulation Description
The constant 04h is inverted (0FFFBh) and is logically ANDed with the destination operand. The result is placed into the destination. The clear negative bit instruction is a word instruction. N: Z: C: V: Reset to 0 Not affected Not affected Not affected
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. The Negative bit in the status register is cleared. This avoids special treatment with negative numbers of the subroutine called. CLRN CALL ...... ...... JN ...... ...... ...... RET
SUBR
SUBR
SUBRET
SUBRET
3-32
Instruction Set
Clear zero bit CLRZ 0Z or (.NOT.src .AND. dst > dst) BIC #2,SR
Emulation Description
The constant 02h is inverted (0FFFDh) and logically ANDed with the destination operand. The result is placed into the destination. The clear zero bit instruction is a word instruction. N: Z: C: V: Not affected Reset to 0 Not affected Not affected
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. The zero bit in the status register is cleared. CLRZ
3-33
Instruction Set
Compare source and destination Compare source and destination CMP CMP.B src,dst src,dst or CMP.W src,dst
Operation
dst + .NOT.src + 1 or (dst src) The source operand is subtracted from the destination operand. This is accomplished by adding the 1s complement of the source operand plus 1. The two operands are not affected and the result is not stored; only the status bits are affected. N: Z: C: V: Set if result is negative, reset if positive (src >= dst) Set if result is zero, reset otherwise (src = dst) Set if there is a carry from the MSB of the result, reset otherwise Set if an arithmetic overflow occurs, otherwise reset
Description
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. R5 and R6 are compared. If they are equal, the program continues at the label EQUAL. CMP JEQ R5,R6 EQUAL ; R5 = R6? ; YES, JUMP
Example
Two RAM blocks are compared. If they are not equal, the program branches to the label ERROR. MOV MOV MOV CMP JNZ INCD DEC JNZ #NUM,R5 #BLOCK1,R6 #BLOCK2,R7 @R6+,0(R7) ERROR R7 R5 L$1 ; number of words to be compared ; BLOCK1 start address in R6 ; BLOCK2 start address in R7 ; Are Words equal? R6 increments ; No, branch to ERROR ; Increment R7 pointer ; Are all words compared? ; No, another compare
L$1
Example
The RAM bytes addressed by EDE and TONI are compared. If they are equal, the program continues at the label EQUAL. CMP.B EDE,TONI JEQ EQUAL ; MEM(EDE) = MEM(TONI)? ; YES, JUMP
3-34
Instruction Set
Add carry decimally to destination Add carry decimally to destination DADC DADC.B dst dst or DADC.W src,dst
Operation Emulation
The carry bit (C) is added decimally to the destination. N: Set if MSB is 1 Z: Set if dst is 0, reset otherwise C: Set if destination increments from 9999 to 0000, reset otherwise Set if destination increments from 99 to 00, reset otherwise V: Undefined OSCOFF, CPUOFF, and GIE are not affected. The four-digit decimal number contained in R5 is added to an eight-digit decimal number pointed to by R8. CLRC DADD DADC R5,0(R8) 2(R8) ; Reset carry ; next instructions start condition is defined ; Add LSDs + C ; Add carry to MSD
Example
The two-digit decimal number contained in R5 is added to a four-digit decimal number pointed to by R8. CLRC DADD.B DADC R5,0(R8) 1(R8) ; Reset carry ; next instructions start condition is defined ; Add LSDs + C ; Add carry to MSDs
3-35
Instruction Set
Source and carry added decimally to destination Source and carry added decimally to destination DADD DADD.B src,dst src,dst or DADD.W src,dst
Operation Description
src + dst + C > dst (decimally) The source operand and the destination operand are treated as four binary coded decimals (BCD) with positive signs. The source operand and the carry bit (C) are added decimally to the destination operand. The source operand is not affected. The previous contents of the destination are lost. The result is not defined for non-BCD numbers. N: Set if the MSB is 1, reset otherwise Z: Set if result is zero, reset otherwise C: Set if the result is greater than 9999 Set if the result is greater than 99 V: Undefined OSCOFF, CPUOFF, and GIE are not affected. The eight-digit BCD number contained in R5 and R6 is added decimally to an eight-digit BCD number contained in R3 and R4 (R6 and R4 contain the MSDs). CLRC DADD DADD JC ; clear carry R5,R3 ; add LSDs R6,R4 ; add MSDs with carry OVERFLOW ; If carry occurs go to error handling routine
Status Bits
Example
The two-digit decimal counter in the RAM byte CNT is incremented by one. CLRC DADD.B or SETC DADD.B ; DADC.B ; clear carry ; increment decimal counter
#1,CNT
#0,CNT
CNT
3-36
Instruction Set
Decrement destination Decrement destination DEC DEC.B dst dst or DEC.W dst
The destination operand is decremented by one. The original contents are lost. N: Z: C: V: Set if result is negative, reset if positive Set if dst contained 1, reset otherwise Reset if dst contained 0, set otherwise Set if an arithmetic overflow occurs, otherwise reset. Set if initial value of destination was 08000h, otherwise reset. Set if initial value of destination was 080h, otherwise reset.
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. R10 is decremented by 1 DEC R10 ; Decrement R10
; Move a block of 255 bytes from memory location starting with EDE to memory location starting with ;TONI. Tables should not overlap: start of destination address TONI must not be within the range EDE ; to EDE+0FEh ; MOV #EDE,R6 MOV #255,R10 L$1 MOV.B @R6+,TONIEDE1(R6) DEC R10 JNZ L$1 ; Do not transfer tables using the routine above with the overlap shown in Figure 312.
TONI EDE+254
TONI+254
3-37
Instruction Set
Double-decrement destination Double-decrement destination DECD DECD.B dst dst or DECD.W dst
The destination operand is decremented by two. The original contents are lost. N: Z: C: V: Set if result is negative, reset if positive Set if dst contained 2, reset otherwise Reset if dst contained 0 or 1, set otherwise Set if an arithmetic overflow occurs, otherwise reset. Set if initial value of destination was 08001 or 08000h, otherwise reset. Set if initial value of destination was 081 or 080h, otherwise reset.
OSCOFF, CPUOFF, and GIE are not affected. R10 is decremented by 2. DECD R10 ; Decrement R10 by two
; Move a block of 255 words from memory location starting with EDE to memory location ; starting with TONI ; Tables should not overlap: start of destination address TONI must not be within the ; range EDE to EDE+0FEh ; MOV #EDE,R6 MOV #510,R10 L$1 MOV @R6+,TONIEDE2(R6) DECD R10 JNZ L$1 Example Memory at location LEO is decremented by two. DECD.B LEO ; Decrement MEM(LEO)
3-38
Instruction Set
Emulation Description
All interrupts are disabled. The constant 08h is inverted and logically ANDed with the status register (SR). The result is placed into the SR. Status bits are not affected. GIE is reset. OSCOFF and CPUOFF are not affected. The general interrupt enable (GIE) bit in the status register is cleared to allow a nondisrupted move of a 32-bit counter. This ensures that the counter is not modified during the move by any interrupt. DINT NOP MOV MOV EINT Note: ; All interrupt events using the GIE bit are disabled COUNTHI,R5 ; Copy counter COUNTLO,R6 ; All interrupt events using the GIE bit are enabled Disable Interrupt
If any code sequence needs to be protected from interruption, the DINT should be executed at least one instruction before the beginning of the uninterruptible sequence, or should be followed by a NOP instruction.
3-39
Instruction Set
Enable (general) interrupts EINT 1 GIE or (0008h .OR. SR > SR / .src .OR. dst > dst) BIS #8,SR
Emulation Description
All interrupts are enabled. The constant #08h and the status register SR are logically ORed. The result is placed into the SR. Status bits are not affected. GIE is set. OSCOFF and CPUOFF are not affected. The general interrupt enable (GIE) bit in the status register is set.
; Interrupt routine of ports P1.2 to P1.7 ; P1IN is the address of the register where all port bits are read. P1IFG is the address of ; the register where all interrupt events are latched. ; PUSH.B &P1IN BIC.B @SP,&P1IFG ; Reset only accepted flags EINT ; Preset port 1 interrupt flags stored on stack ; other interrupts are allowed BIT #Mask,@SP JEQ MaskOK ; Flags are present identically to mask: jump ...... MaskOK BIC #Mask,@SP ...... INCD SP ; Housekeeping: inverse to PUSH instruction ; at the start of interrupt subroutine. Corrects ; the stack pointer. RETI Note: Enable Interrupt
The instruction following the enable interrupt instruction (EINT) is always executed, even if an interrupt service request is pending when the interrupts are enable.
3-40
Instruction Set
Increment destination Increment destination INC INC.B dst dst or INC.W dst
The destination operand is incremented by one. The original contents are lost. N: Set if result is negative, reset if positive Z: Set if dst contained 0FFFFh, reset otherwise Set if dst contained 0FFh, reset otherwise C: Set if dst contained 0FFFFh, reset otherwise Set if dst contained 0FFh, reset otherwise V: Set if dst contained 07FFFh, reset otherwise Set if dst contained 07Fh, reset otherwise OSCOFF, CPUOFF, and GIE are not affected. The status byte, STATUS, of a process is incremented. When it is equal to 11, a branch to OVFL is taken. INC.B CMP.B JEQ STATUS #11,STATUS OVFL
3-41
Instruction Set
Double-increment destination Double-increment destination INCD INCD.B dst dst or INCD.W dst
The destination operand is incremented by two. The original contents are lost. N: Set if result is negative, reset if positive Z: Set if dst contained 0FFFEh, reset otherwise Set if dst contained 0FEh, reset otherwise C: Set if dst contained 0FFFEh or 0FFFFh, reset otherwise Set if dst contained 0FEh or 0FFh, reset otherwise V: Set if dst contained 07FFEh or 07FFFh, reset otherwise Set if dst contained 07Eh or 07Fh, reset otherwise OSCOFF, CPUOFF, and GIE are not affected. The item on the top of the stack (TOS) is removed without using a register. ....... PUSH INCD
R5 SP
; R5 is the result of a calculation, which is stored ; in the system stack ; Remove TOS by double-increment from stack ; Do not use INCD.B, SP is a word-aligned ; register
RET Example The byte on the top of the stack is incremented by two. INCD.B 0(SP) ; Byte on TOS is increment by two
3-42
Instruction Set
The destination operand is inverted. The original contents are lost. N: Set if result is negative, reset if positive Z: Set if dst contained 0FFFFh, reset otherwise Set if dst contained 0FFh, reset otherwise C: Set if result is not zero, reset otherwise ( = .NOT. Zero) Set if result is not zero, reset otherwise ( = .NOT. Zero) V: Set if initial destination operand was negative, otherwise reset OSCOFF, CPUOFF, and GIE are not affected. Content of R5 is negated (twos complement). MOV #00AEh,R5 ; INV R5 ; Invert R5, INC R5 ; R5 is now negated, Content of memory byte LEO is negated. MOV.B INV.B INC.B #0AEh,LEO ; MEM(LEO) = 0AEh LEO ; Invert LEO, MEM(LEO) = 051h LEO ; MEM(LEO) is negated,MEM(LEO) = 052h
Example
3-43
Instruction Set
JC JHS Syntax
Operation
If C = 1: PC + 2 offset > PC If C = 0: execute following instruction The status register carry bit (C) is tested. If it is set, the 10-bit signed offset contained in the instruction LSBs is added to the program counter. If C is reset, the next instruction following the jump is executed. JC (jump if carry/higher or same) is used for the comparison of unsigned numbers (0 to 65536). Status bits are not affected. The P1IN.1 signal is used to define or control the program flow. BIT JC ...... #01h,&P1IN PROGA ; State of signal > Carry ; If carry=1 then execute program routine A ; Carry=0, execute program here
Description
Example
R5 is compared to 15. If the content is higher or the same, branch to LABEL. CMP JHS ...... #15,R5 LABEL ; Jump is taken if R5 15 ; Continue here if R5 < 15
3-44
Instruction Set
If Z = 1: PC + 2 offset > PC If Z = 0: execute following instruction The status register zero bit (Z) is tested. If it is set, the 10-bit signed offset contained in the instruction LSBs is added to the program counter. If Z is not set, the instruction following the jump is executed. Status bits are not affected. Jump to address TONI if R7 contains zero. TST JZ R7 TONI ; Test R7 ; if zero: JUMP
Description
Example
Jump to address LEO if R6 is equal to the table contents. CMP JEQ ...... R6,Table(R5) LEO ; Compare content of R6 with content of ; MEM (table address + content of R5) ; Jump if both data are equal ; No, data are not equal, continue here
Example
3-45
Instruction Set
If (N .XOR. V) = 0 then jump to label: PC + 2 offset > PC If (N .XOR. V) = 1 then execute the following instruction The status register negative bit (N) and overflow bit (V) are tested. If both N and V are set or reset, the 10-bit signed offset contained in the instruction LSBs is added to the program counter. If only one is set, the instruction following the jump is executed. This allows comparison of signed integers.
Description
Status bits are not affected. When the content of R6 is greater or equal to the memory pointed to by R7, the program continues at label EDE. CMP JGE ...... ...... ...... @R7,R6 EDE ; R6 (R7)?, compare on signed numbers ; Yes, R6 (R7) ; No, proceed
3-46
Instruction Set
JL Syntax Operation
If (N .XOR. V) = 1 then jump to label: PC + 2 offset > PC If (N .XOR. V) = 0 then execute following instruction The status register negative bit (N) and overflow bit (V) are tested. If only one is set, the 10-bit signed offset contained in the instruction LSBs is added to the program counter. If both N and V are set or reset, the instruction following the jump is executed. This allows comparison of signed integers.
Description
Status bits are not affected. When the content of R6 is less than the memory pointed to by R7, the program continues at label EDE. CMP JL ...... ...... ...... @R7,R6 EDE ; R6 < (R7)?, compare on signed numbers ; Yes, R6 < (R7) ; No, proceed
3-47
Instruction Set
PC + 2 offset > PC The 10-bit signed offset contained in the instruction LSBs is added to the program counter. Status bits are not affected. This one-word instruction replaces the BRANCH instruction in the range of 511 to +512 words relative to the current program counter.
3-48
Instruction Set
JN Syntax Operation
if N = 1: PC + 2 offset > PC if N = 0: execute following instruction The negative bit (N) of the status register is tested. If it is set, the 10-bit signed offset contained in the instruction LSBs is added to the program counter. If N is reset, the next instruction following the jump is executed. Status bits are not affected. The result of a computation in R5 is to be subtracted from COUNT. If the result is negative, COUNT is to be cleared and the program continues execution in another path. SUB JN ...... ...... ...... ...... CLR ...... ...... ...... R5,COUNT L$1 ; COUNT R5 > COUNT ; If negative continue with COUNT=0 at PC=L$1 ; Continue with COUNT0
Description
L$1
COUNT
3-49
Instruction Set
Jump if carry not set Jump if lower JNC JLO label label
Operation
if C = 0: PC + 2 offset > PC if C = 1: execute following instruction The status register carry bit (C) is tested. If it is reset, the 10-bit signed offset contained in the instruction LSBs is added to the program counter. If C is set, the next instruction following the jump is executed. JNC (jump if no carry/lower) is used for the comparison of unsigned numbers (0 to 65536). Status bits are not affected. The result in R6 is added in BUFFER. If an overflow occurs, an error handling routine at address ERROR is used. ADD JNC ...... ...... ...... ...... ...... ...... ...... R6,BUFFER CONT ; BUFFER + R6 > BUFFER ; No carry, jump to CONT ; Error handler start
Description
ERROR
CONT
Example
Branch to STL2 if byte STATUS contains 1 or 0. CMP.B JLO ...... #2,STATUS STL 2
3-50
Instruction Set
Jump if not equal Jump if not zero JNE JNZ label label
Operation
If Z = 0: PC + 2 offset > PC If Z = 1: execute following instruction The status register zero bit (Z) is tested. If it is reset, the 10-bit signed offset contained in the instruction LSBs is added to the program counter. If Z is set, the next instruction following the jump is executed. Status bits are not affected. Jump to address TONI if R7 and R8 have different contents. CMP JNE ...... R7,R8 TONI ; COMPARE R7 WITH R8 ; if different: jump ; if equal, continue
Description
3-51
Instruction Set
Move source to destination Move source to destination MOV MOV.B src > dst The source operand is moved to the destination. The source operand is not affected. The previous contents of the destination are lost. Status bits are not affected. OSCOFF, CPUOFF, and GIE are not affected. The contents of table EDE (word data) are copied to table TOM. The length of the tables must be 020h locations. MOV MOV MOV DEC JNZ ...... ...... ...... #EDE,R10 #020h,R9 @R10+,TOMEDE2(R10) R9 Loop ; Prepare pointer ; Prepare counter ; Use pointer in R10 for both tables ; Decrement counter ; Counter 0, continue copying ; Copying completed src,dst src,dst or MOV.W src,dst
Operation Description
Loop
Example
The contents of table EDE (byte data) are copied to table TOM. The length of the tables should be 020h locations MOV #EDE,R10 ; Prepare pointer MOV #020h,R9 ; Prepare counter MOV.B @R10+,TOMEDE1(R10) ; Use pointer in R10 for ; both tables DEC R9 ; Decrement counter JNZ Loop ; Counter 0, continue ; copying ...... ; Copying completed ...... ......
Loop
3-52
Instruction Set
No operation is performed. The instruction may be used for the elimination of instructions during the software check or for defined waiting times. Status bits are not affected. The NOP instruction is mainly used for two purposes:
- To fill one, two, or three memory words - To adjust software timing
Status Bits
Note:
Other instructions can emulate the NOP function while providing different numbers of instruction cycles and code words. Some examples are: Examples: MOV MOV MOV BIC JMP BIC #0,R3 0(R4),0(R4) @R4,0(R4) #0,EDE(R4) $+2 #0,R5 ; 1 cycle, 1 word ; 6 cycles, 3 words ; 5 cycles, 2 words ; 4 cycles, 2 words ; 2 cycles, 1 word ; 1 cycle, 1 word
However, care should be taken when using these examples to prevent unintended results. For example, if MOV 0(R4), 0(R4) is used and the value in R4 is 120h, then a security violation will occur with the watchdog timer (address 120h) because the security key was not used.
3-53
Instruction Set
Pop word from stack to destination Pop byte from stack to destination POP POP.B dst dst
Operation
@SP > temp SP + 2 > SP temp > dst MOV MOV.B @SP+,dst @SP+,dst or MOV.W @SP+,dst
The stack location pointed to by the stack pointer (TOS) is moved to the destination. The stack pointer is incremented by two afterwards. Status bits are not affected. The contents of R7 and the status register are restored from the stack. POP POP R7 SR ; Restore R7 ; Restore status register
Example
The contents of RAM byte LEO is restored from the stack. POP.B LEO ; The low byte of the stack is moved to LEO.
Example
The contents of R7 is restored from the stack. POP.B R7 ; The low byte of the stack is moved to R7, ; the high byte of R7 is 00h
Example
The contents of the memory pointed to by R7 and the status register are restored from the stack. POP.B 0(R7) ; The low byte of the stack is moved to the ; the byte which is pointed to by R7 : Example: R7 = 203h ; Mem(R7) = low byte of system stack : Example: R7 = 20Ah ; Mem(R7) = low byte of system stack ; Last word on stack moved to the SR
POP Note:
SR
The system stack pointer (SP) is always incremented by two, independent of the byte suffix.
3-54
Instruction Set
Push word onto stack Push byte onto stack PUSH PUSH.B SP 2 SP src @SP The stack pointer is decremented by two, then the source operand is moved to the RAM word addressed by the stack pointer (TOS). Status bits are not affected. OSCOFF, CPUOFF, and GIE are not affected. The contents of the status register and R8 are saved on the stack. PUSH PUSH SR R8 ; save status register ; save R8 src src or PUSH.W src
Operation
Description
Example
The contents of the peripheral TCDAT is saved on the stack. PUSH.B &TCDAT ; save data from 8-bit peripheral module, ; address TCDAT, onto stack
Note:
The system stack pointer (SP) is always decremented by two, independent of the byte suffix.
3-55
Instruction Set
Emulation Description
The return address pushed onto the stack by a CALL instruction is moved to the program counter. The program continues at the code address following the subroutine call. Status bits are not affected.
Status Bits
3-56
Instruction Set
Description
The status register is restored to the value at the beginning of the interrupt service routine by replacing the present SR contents with the TOS contents. The stack pointer (SP) is incremented by two. The program counter is restored to the value at the beginning of interrupt service. This is the consecutive step after the interrupted program flow. Restoration is performed by replacing the present PC contents with the TOS memory contents. The stack pointer (SP) is incremented.
Status Bits
N: Z: C: V:
OSCOFF, CPUOFF, and GIE are restored from system stack. Figure 313 illustrates the main program interrupt.
PC 6 PC 4 PC 2 PC PC +2 PC +4 PC +6 PC +8 Interrupt Accepted PC+2 is Stored Onto Stack PC = PCi PCi +2 PCi +4 Interrupt Request
3-57
Instruction Set
Rotate left arithmetically Rotate left arithmetically RLA RLA.B dst dst or RLA.W dst
Operation Emulation
C < MSB < MSB1 .... LSB+1 < LSB < 0 ADD ADD.B dst,dst dst,dst
Description
The destination operand is shifted left one position as shown in Figure 314. The MSB is shifted into the carry bit (C) and the LSB is filled with 0. The RLA instruction acts as a signed multiplication by 2. An overflow occurs if dst 04000h and dst < 0C000h before operation is performed: the result has changed sign.
An overflow occurs if dst 040h and dst < 0C0h before the operation is performed: the result has changed sign. Status Bits N: Z: C: V: Set if result is negative, reset if positive Set if result is zero, reset otherwise Loaded from the MSB Set if an arithmetic overflow occurs: the initial value is 04000h dst < 0C000h; reset otherwise Set if an arithmetic overflow occurs: the initial value is 040h dst < 0C0h; reset otherwise
OSCOFF, CPUOFF, and GIE are not affected. R7 is multiplied by 2. RLA R7 ; Shift left R7 ( 2)
Example
The low byte of R7 is multiplied by 4. RLA.B RLA.B Note: RLA R7 R7 ; Shift left low byte of R7 ( 2) ; Shift left low byte of R7 ( 4)
The assembler does not recognize the instruction: It must be substituted by: ADD @R5+,2(R5) ADD.B @R5+,1(R5) or
3-58
Instruction Set
Rotate left through carry Rotate left through carry RLC RLC.B dst dst or RLC.W dst
C < MSB < MSB1 .... LSB+1 < LSB < C ADDC dst,dst
The destination operand is shifted left one position as shown in Figure 315. The carry bit (C) is shifted into the LSB and the MSB is shifted into the carry bit (C).
Status Bits
N: Z: C: V:
Set if result is negative, reset if positive Set if result is zero, reset otherwise Loaded from the MSB Set if an arithmetic overflow occurs the initial value is 04000h dst < 0C000h; reset otherwise Set if an arithmetic overflow occurs: the initial value is 040h dst < 0C0h; reset otherwise
OSCOFF, CPUOFF, and GIE are not affected. R5 is shifted left one position. RLC R5 ; (R5 x 2) + C > R5
Example
The input P1IN.1 information is shifted into the LSB of R5. BIT.B RLC #2,&P1IN R5 ; Information > Carry ; Carry=P0in.1 > LSB of R5
Example
The MEM(LEO) content is shifted left one position. RLC.B Note: LEO ; Mem(LEO) x 2 + C > Mem(LEO)
The assembler does not recognize the instruction: RLC @R5+, It must be substituted by: ADDC @R5+,2(R5) ADDC.B @R5+,1(R5) or ADDC(.B) @R5
3-59
Instruction Set
Rotate right arithmetically Rotate right arithmetically RRA RRA.B dst dst or RRA.W dst
Operation Description
MSB > MSB, MSB > MSB1, ... LSB+1 > LSB,
LSB > C
The destination operand is shifted right one position as shown in Figure 316. The MSB is shifted into the MSB, the MSB is shifted into the MSB1, and the LSB+1 is shifted into the LSB.
Status Bits
N: Z: C: V:
Set if result is negative, reset if positive Set if result is zero, reset otherwise Loaded from the LSB Reset
OSCOFF, CPUOFF, and GIE are not affected. R5 is shifted right one position. The MSB retains the old value. It operates equal to an arithmetic division by 2. RRA R5 ; R5/2 > R5
; ;
The value in R5 is multiplied by 0.75 (0.5 + 0.25). PUSH RRA ADD RRA ...... R5 R5 @SP+,R5 R5 ; Hold R5 temporarily using stack ; R5 0.5 > R5 ; R5 0.5 + R5 = 1.5 R5 > R5 ; (1.5 R5) 0.5 = 0.75 R5 > R5
Example
The low byte of R5 is shifted right one position. The MSB retains the old value. It operates equal to an arithmetic division by 2. RRA.B PUSH.B RRA.B ADD.B ...... R5 R5 @SP @SP+,R5 ; R5/2 > R5: operation is on low byte only ; High byte of R5 is reset ; R5 0.5 > TOS ; TOS 0.5 = 0.5 R5 0.5 = 0.25 R5 > TOS ; R5 0.5 + R5 0.25 = 0.75 R5 > R5
3-60
Instruction Set
Rotate right through carry Rotate right through carry RRC RRC dst dst or RRC.W dst
Operation Description
C > MSB > MSB1 .... LSB+1 > LSB > C The destination operand is shifted right one position as shown in Figure 317. The carry bit (C) is shifted into the MSB, the LSB is shifted into the carry bit (C).
Status Bits
N: Z: C: V:
Set if result is negative, reset if positive Set if result is zero, reset otherwise Loaded from the LSB Reset
OSCOFF, CPUOFF, and GIE are not affected. R5 is shifted right one position. The MSB is loaded with 1. SETC RRC ; Prepare carry for MSB ; R5/2 + 8000h > R5
R5
Example
R5 is shifted right one position. The MSB is loaded with 1. SETC RRC.B ; Prepare carry for MSB ; R5/2 + 80h > R5; low byte of R5 is used
R5
3-61
Instruction Set
Subtract source and borrow/.NOT. carry from destination Subtract source and borrow/.NOT. carry from destination SBC SBC.B dst dst or SBC.W dst
Operation
dst + 0FFFFh + C > dst dst + 0FFh + C > dst SUBC SUBC.B #0,dst #0,dst
Emulation
Description
The carry bit (C) is added to the destination operand minus one. The previous contents of the destination are lost. N: Set if result is negative, reset if positive Z: Set if result is zero, reset otherwise C: Set if there is a carry from the MSB of the result, reset otherwise. Set to 1 if no borrow, reset if borrow. V: Set if an arithmetic overflow occurs, reset otherwise. OSCOFF, CPUOFF, and GIE are not affected. The 16-bit counter pointed to by R13 is subtracted from a 32-bit counter pointed to by R12. SUB SBC @R13,0(R12) 2(R12) ; Subtract LSDs ; Subtract carry from MSD
Status Bits
Example
The 8-bit counter pointed to by R13 is subtracted from a 16-bit counter pointed to by R12. SUB.B SBC.B Note: @R13,0(R12) 1(R12) Borrow Implementation . Borrow Yes No Carry bit 0 1 ; Subtract LSDs ; Subtract carry from MSD
3-62
Instruction Set
The carry bit (C) is set. N: Z: C: V: Not affected Not affected Set Not affected
OSCOFF, CPUOFF, and GIE are not affected. Emulation of the decimal subtraction: Subtract R5 from R6 decimally Assume that R5 = 03987h and R6 = 04137h ADD INV SETC DADD #06666h,R5 R5 ; Move content R5 from 09 to 60Fh ; R5 = 03987h + 06666h = 09FEDh ; Invert this (result back to 09) ; R5 = .NOT. R5 = 06012h ; Prepare carry = 1 ; Emulate subtraction by addition of: ; (010000h R5 1) ; R6 = R6 + R5 + 1 ; R6 = 0150h
DSUB
R5,R6
3-63
Instruction Set
The negative bit (N) is set. N: Z: C: V: Set Not affected Not affected Not affected
Mode Bits
3-64
Instruction Set
The zero bit (Z) is set. N: Z: C: V: Not affected Set Not affected Not affected
Mode Bits
3-65
Instruction Set
Subtract source from destination Subtract source from destination SUB SUB.B src,dst src,dst or SUB.W src,dst
Operation
dst + .NOT.src + 1 > dst or [(dst src > dst)] The source operand is subtracted from the destination operand by adding the source operands 1s complement and the constant 1. The source operand is not affected. The previous contents of the destination are lost. N: Set if result is negative, reset if positive Z: Set if result is zero, reset otherwise C: Set if there is a carry from the MSB of the result, reset otherwise. Set to 1 if no borrow, reset if borrow. V: Set if an arithmetic overflow occurs, otherwise reset OSCOFF, CPUOFF, and GIE are not affected. See example at the SBC instruction. See example at the SBC.B instruction. Note: Borrow Is Treated as a .NOT. Borrow Yes No Carry bit 0 1
Description
Status Bits
3-66
Instruction Set
Subtract source and borrow/.NOT. carry from destination Subtract source and borrow/.NOT. carry from destination SUBC SBB SUBC.B src,dst src,dst src,dst or or or SUBC.W SBB.W SBB.B src,dst src,dst src,dst or
Operation
dst + .NOT.src + C > dst or (dst src 1 + C > dst) The source operand is subtracted from the destination operand by adding the source operands 1s complement and the carry bit (C). The source operand is not affected. The previous contents of the destination are lost. N: Set if result is negative, reset if positive. Z: Set if result is zero, reset otherwise. C: Set if there is a carry from the MSB of the result, reset otherwise. Set to 1 if no borrow, reset if borrow. V: Set if an arithmetic overflow occurs, reset otherwise. OSCOFF, CPUOFF, and GIE are not affected. Two floating point mantissas (24 bits) are subtracted. LSBs are in R13 and R10, MSBs are in R12 and R9. SUB.W SUBC.B R13,R10 ; 16-bit part, LSBs R12,R9 ; 8-bit part, MSBs
Description
Status Bits
Example
The 16-bit counter pointed to by R13 is subtracted from a 16-bit counter in R10 and R11(MSD). SUB.B SUBC.B ... Note: @R13+,R10 @R13,R11 ; Subtract LSDs without carry ; Subtract MSDs with carry ; resulting from the LSDs
3-67
Instruction Set
Bits 15 to 8 <> bits 7 to 0 The destination operand high and low bytes are exchanged as shown in Figure 318. Status bits are not affected. OSCOFF, CPUOFF, and GIE are not affected.
The value in R5 is multiplied by 256. The result is stored in R5,R4. SWPB MOV BIC BIC R5 R5,R4 #0FF00h,R5 #00FFh,R4 ; ;Copy the swapped value to R4 ;Correct the result ;Correct the result
3-68
Instruction Set
Bit 7 > Bit 8 ......... Bit 15 The sign of the low byte is extended into the high byte as shown in Figure 319. N: Z: C: V: Set if result is negative, reset if positive Set if result is zero, reset otherwise Set if result is not zero, reset otherwise (.NOT. Zero) Reset
Mode Bits
Example
R7 is loaded with the P1IN value. The operation of the sign-extend instruction expands bit 8 to bit 15 with the value of bit 7. R7 is then added to R6. MOV.B SXT &P1IN,R7 R7 ; P1IN = 080h: ; R7 = 0FF80h: . . . . . . . . 1000 0000 1111 1111 1000 0000
3-69
Instruction Set
Test destination Test destination TST TST.B dst dst or TST.W dst
Operation
Emulation
Description
The destination operand is compared with zero. The status bits are set according to the result. The destination is not affected. N: Z: C: V: Set if destination is negative, reset if positive Set if destination contains zero, reset otherwise Set Reset
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. R7 is tested. If it is negative, continue at R7NEG; if it is positive but not zero, continue at R7POS. TST JN JZ ...... ...... ...... R7 R7NEG R7ZERO ; Test R7 ; R7 is negative ; R7 is zero ; R7 is positive but not zero ; R7 is negative ; R7 is zero
The low byte of R7 is tested. If it is negative, continue at R7NEG; if it is positive but not zero, continue at R7POS. TST.B JN JZ ...... ..... ...... R7 R7NEG R7ZERO ; Test low byte of R7 ; Low byte of R7 is negative ; Low byte of R7 is zero ; Low byte of R7 is positive but not zero ; Low byte of R7 is negative ; Low byte of R7 is zero
3-70
Instruction Set
Exclusive OR of source with destination Exclusive OR of source with destination XOR XOR.B src,dst src,dst or XOR.W src,dst
Operation Description
src .XOR. dst > dst The source and destination operands are exclusive ORed. The result is placed into the destination. The source operand is not affected. N: Z: C: V: Set if result MSB is set, reset if not set Set if result is zero, reset otherwise Set if result is not zero, reset otherwise ( = .NOT. Zero) Set if both operands are negative
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. The bits set in R6 toggle the bits in the RAM word TONI. XOR R6,TONI ; Toggle bits of word TONI on the bits set in R6
Example
The bits set in R6 toggle the bits in the RAM byte TONI. XOR.B R6,TONI ; Toggle bits of byte TONI on the bits set in ; low byte of R6
Example
Reset to 0 those bits in low byte of R7 that are different from bits in RAM byte EDE. XOR.B INV.B EDE,R7 R7 ; Set different bit to 1s ; Invert Lowbyte, Highbyte is 0h
3-71
Instruction Set
3.4.4
Note:
Do not use instructions RRA, RRC, SWPB, and SXT with the immediate mode in the destination field. Use of these in the immediate mode results in an unpredictable program operation.
3-72
Instruction Set
Example R5,R8 R9 R5,4(R6) R8,EDE R5,&EDE @R4,R5 @R8 @R5,8(R6) @R5,EDE @R5,&EDE @R5+,R6 @R9+ @R5,8(R6) @R9+,EDE @R9+,&EDE #20,R9 #2AEh #0300h,0(SP) #33,EDE #33,&EDE 2(R5),R7 2(R6) 4(R7),TONI 4(R4),6(R9) 2(R4),&TONI EDE,R6 EDE EDE,TONI EDE,0(SP) EDE,&TONI &EDE,R8 &EDE &EDE,TONI &EDE,0(SP) &EDE,&TONI
3-73
Instruction Set
3.4.5
RRA
RRA.B
SXT
PUSH
PUSH.B
CALL
RETI
JNE/JNZ JEQ/JZ JNC JC JN JGE JL JMP MOV, MOV.B ADD, ADD.B ADDC, ADDC.B SUBC, SUBC.B SUB, SUB.B CMP, CMP.B DADD, DADD.B BIT, BIT.B BIC, BIC.B BIS, BIS.B XOR, XOR.B AND, AND.B
3-74
Instruction Set
Description dst src,dst src,dst src,dst src,dst src,dst src,dst dst dst dst Add C to destination Add source to destination Add source and C to destination AND source and destination Clear bits in destination Set bits in destination Test bits in destination Branch to destination Call destination Clear destination Clear C Clear N Clear Z src,dst dst src,dst dst dst Compare source and destination Add C decimally to destination Add source and C decimally to dst. Decrement destination Double-decrement destination Disable interrupts Enable interrupts dst dst dst label label label label label label label label src,dst Increment destination Double-increment destination Invert destination Jump if C set/Jump if higher or same Jump if equal/Jump if Z set Jump if greater or equal Jump if less Jump Jump if N set Jump if C not set/Jump if lower Jump if not equal/Jump if Z not set Move source to destination No operation dst src Pop item from stack to destination Push source onto stack Return from subroutine Return from interrupt dst dst dst dst dst Rotate left arithmetically Rotate left through C Rotate right arithmetically Rotate right through C Subtract not(C) from destination Set C Set N Set Z src,dst src,dst dst dst dst src,dst Subtract source from destination Subtract source and not(C) from dst. Swap bytes Extend sign Test destination Exclusive OR source and destination dst + 0FFFFh + 1 src .xor. dst dst dst + 0FFFFh + C dst 1C 1N 1C dst + .not.src + 1 dst dst + .not.src + C dst @SP dst, SP+2 SP SP 2 SP, src @SP @SP PC, SP + 2 SP src dst PC + 2 x offset PC dst + C dst src + dst dst src + dst + C dst src .and. dst dst .not.src .and. dst dst src .or. dst dst src .and. dst dst PC PC+2 stack, dst PC 0 dst 0C 0N 0Z dst src dst + C dst (decimally) src + dst + C dst (decimally) dst 1 dst dst 2 dst 0 GIE 1 GIE dst +1 dst dst+2 dst .not.dst dst
V * * * 0 0 * * * * * * * * * * * 0 * * * * 0 0 *
N * * * * * 0 * * * * * * * * * * * * * * 1 * * * * *
Z * * * * * 0 * * * * * * * * * * * * * * 1 * * * * *
C * * * * * 0 * * * * * * * * * * * * * * 1 * * * 1 *
Emulated Instruction
3-75
3-76
Chapter 4
16-Bit
MSP430X CPU
This chapter describes the extended MSP430X 16-bit RISC CPU with 1-MB memory access, its addressing modes, and instruction set. The MSP430X CPU is implemented in all MSP430 devices that exceed 64-KB of address space.
Topic
4.1 4.2 4.3 4.4 4.5 4.6
Page
CPU Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4 CPU Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5 Addressing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15 MSP430 and MSP430X Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-36 Instruction Set Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-58
4-1
CPU Introduction
pointer.
- Single-cycle register operations. - Large register file reduces fetches to memory. - 20-bit address bus allows direct access and branching throughout the
4-2
CPU Introduction
R0/PC Program Counter R1/SP Pointer Stack R2/SR Status Register R3/CG2 Constant Generator R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 16 Zero, Z Carry, C Overflow,V Negative,N dst 16/20bit ALU src General Purpose General Purpose General Purpose General Purpose General Purpose General Purpose General Purpose General Purpose General Purpose General Purpose General Purpose General Purpose
20
MCLK
4-3
Interrupts
4.2 Interrupts
The MSP430X uses the same interrupt structure as the MSP430:
- Vectored interrupts with no polling necessary - Interrupt vectors are located downward from address 0FFFEh
Interrupt operation for both MSP430 and MSP430X CPUs is described in Chapter 2 System Resets, Interrupts, and Operating modes, Section 2 Interrupts. The interrupt vectors contain 16-bit addresses that point into the lower 64-KB memory. This means all interrupt handlers must start in the lower 64-KB memory even in MSP430X devices. During an interrupt, the program counter and the status register are pushed onto the stack as shown in Figure 42. The MSP430X architecture efficiently stores the complete 20-bit PC value by automatically appending the PC bits 19:16 to the stored SR value on the stack. When the RETI instruction is executed, the full 20-bit PC is restored making return from interrupt to any address in the memory range possible.
4-4
CPU Registers
4.3.1
The PC can be addressed with all instructions and addressing modes. A few examples:
MOV.W #LABEL,PC ; Branch to address LABEL (lower 64 KB) MOVA #LABEL,PC ; Branch to address LABEL (1MB memory)
MOV.W LABEL,PC ; Branch to address in word LABEL ; (lower 64 KB) MOV.W @R14,PC ADDA #4,PC ; Branch indirect to address in ; R14 (lower 64 KB) ; Skip two words (1 MB memory)
The BR and CALL instructions reset the upper four PC bits to 0. Only addresses in the lower 64-KB address range can be reached with the BR or CALL instruction. When branching or calling, addresses beyond the lower 64-KB range can only be reached using the BRA or CALLA instructions. Also, any instruction to directly modify the PC does so according to the used addressing mode. For example, MOV.W #value,PC will clear the upper four bits of the PC because it is a .W instruction.
4-5
CPU Registers
The program counter is automatically stored on the stack with CALL, or CALLA instructions, and during an interrupt service routine. Figure 44 shows the storage of the program counter with the return address after a CALLA instruction. A CALL instruction stores only bits 15:0 of the PC.
The RETA instruction restores bits 19:0 of the program counter and adds 4 to the stack pointer. The RET instruction restores bits 15:0 to the program counter and adds 2 to the stack pointer.
4-6
CPU Registers
4.3.2
4-7
CPU Registers
The special cases of using the SP as an argument to the PUSH and POP instructions are described and shown in Figure 48.
The stack pointer is not changed after a POP SP instruction. The POP SP instruction places SP1 into the stack pointer SP (SP2=SP1)
4-8
CPU Registers
4.3.3
rw-0
System clock generator 1. This bit, when set, turns off the DCO dc generator if DCOCLK is not used for MCLK or SMCLK. System clock generator 0. This bit, when set, turns off the FLL+ loop control. Oscillator Off. This bit, when set, turns off the LFXT1 crystal oscillator when LFXT1CLK is not used for MCLK or SMCLK. CPU off. This bit, when set, turns off the CPU. General interrupt enable. This bit, when set, enables maskable interrupts. When reset, all maskable interrupts are disabled. Negative bit. This bit is set when the result of an operation is negative and cleared when the result is positive.
SCG0
OSCOFF
CPUOFF GIE
4-9
CPU Registers Bit Z Description Zero bit. This bit is set when the result of an operation is zero and cleared when the result is not zero. Carry bit. This bit is set when the result of an operation produced a carry and cleared when no carry occurred.
4-10
CPU Registers
4.3.4
The assembler uses the constant generator automatically if one of the six constants is used as an immediate source operand. Registers R2 and R3, used in the constant mode, cannot be addressed explicitly; they act as source-only registers.
is emulated by the double-operand instruction with the same length: MOV R3,dst
where the #0 is replaced by the assembler, and R3 is used with As=00. INC is replaced by: ADD 0(R3),dst dst
4-11
CPU Registers
4.3.5
Memory
19 16 15 87 UnUnused used
0 Register
Operation
Operation
Memory
Register
4-12
CPU Registers
Figure 411 and Figure 412 show 16-bit word handling (.W suffix). The handling is shown for a source register and a destination memory word and for a source memory word and a destination register.
Memory
Operation
Memory
19 16 15 Unused
87
0 Register
Operation
Register
4-13
CPU Registers
Figure 413 and Figure 414 show 20-bit address-word handling (.A suffix). The handling is shown for a source register and a destination memory address-word and for a source memory address-word and a destination register.
Memory +2
Unused
Memory
Operation
Memory +2
Memory
Register
Operation
Register
4-14
CPU Registers
01/1
Symbolic mode
ADDR
01/1
Absolute mode
&ADDR
10/ 11/
@Rn @Rn+
11/
Immediate mode
#N
The seven addressing modes are explained in detail in the following sections. Most of the examples show the same addressing mode for the source and destination, but any valid combination of source and destination addressing modes is possible in an instruction. Note: Use of Labels EDE, TONI, TOM, and LEO
Throughout MSP430 documentation EDE, TONI, TOM, and LEO are used as generic labels. They are only labels. They have no special meaning.
4-15
CPU Registers
4.4.1
Register Mode
Operation: The operand is the 8-, 16-, or 20-bit content of the used CPU register. Length: Comment: One, two, or three words Valid for source and destination
Byte operation: Byte operation reads only the 8 LSBs of the source register Rsrc and writes the result to the 8 LSBs of the destination register Rdst. The bits Rdst.19:8 are cleared. The register Rsrc is not modified. Word operation:Word operation reads the 16 LSBs of the source register Rsrc and writes the result to the 16 LSBs of the destination register Rdst. The bits Rdst.19:16 are cleared. The register Rsrc is not modified. Address-Word operation: Address-word operation reads the 20 bits of the source register Rsrc and writes the result to the 20 bits of the destination register Rdst. The register Rsrc is not modified SXT Exception: The SXT instruction is the only exception for register operation. The sign of the low byte in bit 7 is extended to the bits Rdst.19:8. Example: BIS.W R5,R6 ;
This instruction logically ORs the 16-bit data contained in R5 with the 16-bit contents of R6. R6.19:16 is cleared.
Before: Address Space 21036h 21034h xxxxh D506h PC Register After: Address Space 21036h 21034h xxxxh D506h PC Register
R5 R6
AA550h 11111h
R5 R6
AA550h 0B551h
A550h.or.1111h = B551h
4-16
CPU Registers
Example:
BISX.A
R5,R6 ;
This instruction logically ORs the 20-bit data contained in R5 with the 20-bit contents of R6. The extension word contains the A/L-bit for 20-bit data. The instruction word uses byte mode with bits A/L:B/W = 01. The result of the instruction is:
Before: Address Space 21036h 21034h 21032h xxxxh D546h 1800h PC Register After: Address Space 21036h 21034h 21032h xxxxh D546h 1800h PC Register
R5 R6
AA550h 11111h
R5 R6
AA550h BB551h
AA550h.or.11111h = BB551h
4-17
CPU Registers
4.4.2
Indexed Mode
The Indexed mode calculates the address of the operand by adding the signed index to a CPU register. The Indexed mode has three addressing possibilities:
- Indexed mode in lower 64-KB memory - MSP430 instruction with Indexed mode addressing memory above the
10000 0FFFF
Rn.19:0
00000
Lower 64KB
Memory address
Length: Operation:
Two or three words The signed 16-bit index is located in the next word after the instruction and is added to the CPU register Rn. The resulting bits 19:16 are cleared giving a truncated 16-bit memory address, which points to an operand address in the range 00000h to 0FFFFh. The operand is the content of the addressed memory location. Valid for source and destination. The assembler calculates the register index and inserts it.
Comment:
4-18
CPU Registers
Example:
ADD.B
1000h(R5),0F000h(R6);
The previous instruction adds the 8-bit data contained in source byte 1000h(R5) and the destination byte 0F000h(R6) and places the result into the destination byte. Source and destination bytes are both located in the lower 64 KB due to the cleared bits 19:16 of registers R5 and R6. Source: The byte pointed to by R5 + 1000h results in address 0479Ch + 1000h = 0579Ch after truncation to a 16-bit address. The byte pointed to by R6 + F000h results in address 01778h + F000h = 00778h after truncation to a 16-bit address.
After: Address Space 1103Ah 11038h 11036h 11034h xxxxh F000h 1000h 55D6h PC Register Address Space 1103Ah 11038h 11036h 11034h xxxxh F000h 1000h 55D6h PC R5 R6 Register
Destination:
Before:
R5 R6
0479Ch 01778h
0479Ch 01778h
0077Ah 00778h
xxxxh xx45h
0077Ah 00778h
xxxxh xx77h
0579Eh 0579Ch
xxxxh xx32h
0579Eh 0579Ch
xxxxh xx32h
4-19
CPU Registers
00000
Memory address
Rn.19:0
10000 0,FFFF
Rn.19:0
0000C
32KB
32KB
Rn.19:0
4-20
Lower 64 KB
CPU Registers
Length: Operation:
Two or three words The sign-extended 16-bit index in the next word after the instruction is added to the 20 bits of the CPU register Rn. This delivers a 20-bit address, which points to an address in the range 0 to FFFFFh. The operand is the content of the addressed memory location. Valid for source and destination. The assembler calculates the register index and inserts it. ADD.W 8346h(R5),2100h(R6);
Comment:
Example:
This instruction adds the 16-bit data contained in the source and the destination addresses and places the 16-bit result into the destination. Source and destination operand can be located in the entire address range. Source: The word pointed to by R5 + 8346h. The negative index 8346h is sign-extended, which results in address 23456h + F8346h = 1B79Ch. The word pointed to by R6 + 2100h results in address 15678h + 2100h = 17778h.
Destination:
R5 R6
23456h 15678h
23456h 15678h
1777Ah 17778h
xxxxh 2345h
1777Ah 17778h
xxxxh 7777h
1B79Eh 1B79Ch
xxxxh 5432h
1B79Eh 1B79Ch
xxxxh 5432h
4-21
CPU Registers
Comment:
Example:
This instruction adds the 20-bit data contained in the source and the destination addresses and places the result into the destination. Source: Two words pointed to by R5 + 12346h which results in address 23456h + 12346h = 3579Ch. Two words pointed to by R6 + 32100h which results in address 45678h + 32100h = 77778h.
Destination:
4-22
CPU Registers
The extension word contains the MSBs of the source index and of the destination index and the A/L-bit for 20-bit data. The instruction word uses byte mode due to the 20-bit data length with bits A/L:B/W = 01.
Before: Address Space 2103Ah 21038h 21036h 21034h 21032h xxxxh 2100h 2346h 55D6h 1883h PC Register After: Address Space 2103Ah 21038h 21036h 21034h 21032h xxxxh 2100h 2346h 55D6h 1883h PC R5 R6 Register
R5 R6
23456h 45678h
23456h 45678h
7777Ah 77778h
0001h 2345h
7777Ah 77778h
0007h 7777h
3579Eh 3579Ch
0006h 5432h
3579Eh 3579Ch
0006h 5432h
4-23
CPU Registers
4.4.3
Symbolic Mode
The Symbolic mode calculates the address of the operand by adding the signed index to the program counter. The Symbolic mode has three addressing possibilities:
- Symbolic mode in lower 64-KB memory - MSP430 instruction with symbolic mode addressing memory above the
S 10000 0FFFF
PC.19:0
00000
Lower 64 KB
Memory address
Operation: The signed 16-bit index in the next word after the instruction is added temporarily to the PC. The resulting bits 19:16 are cleared giving a truncated 16-bit memory address, which points to an operand address in the range 00000h, to 0FFFFh. The operand is the content of the addressed memory location. Length: Comment: Two or three words Valid for source and destination. The assembler calculates the PC index and inserts it. ADD.B EDE,TONI ;
Example:
4-24
CPU Registers
The previous instruction adds the 8-bit data contained in source byte EDE and destination byte TONI and places the result into the destination byte TONI. Bytes EDE and TONI and the program are located in the lower 64 KB. Source: Byte EDE located at address 0,579Ch, pointed to by PC + 4766h where the PC index 4766h is the result of 0579Ch 01036h = 04766h. Address 01036h is the location of the index for this example. Byte TONI located at address 00778h, pointed to by PC + F740h, is the truncated 16-bit result of 00778h 1038h = FF740h. Address 01038h is the location of the index for this example.
After: Address Space 0103Ah 01038h 01036h 01034h xxxxh F740h 4766h 05D0h PC 0103Ah 01038h 01036h 01034h Address Space xxxxh F740h 4766h 50D0h PC
Destination:
Before:
0077Ah 00778h
xxxxh xx45h
0077Ah 00778h
xxxxh xx77h
0579Eh 0579Ch
xxxxh xx32h
0579Eh 0579Ch
xxxxh xx32h
4-25
CPU Registers
00000
Memory address
PC.19:0
PC.19:0
10000 0FFFF
PC.19:0
0000C
32KB
32KB
PC.19:0 Lower 64 KB
4-26
CPU Registers
Length: Operation:
Two or three words The sign-extended 16-bit index in the next word after the instruction is added to the 20 bits of the PC. This delivers a 20-bit address, which points to an address in the range 0 to FFFFFh. The operand is the content of the addressed memory location. Valid for source and destination. The assembler calculates the PC index and inserts it ADD.W EDE,&TONI ;
Comment:
Example:
This instruction adds the 16-bit data contained in source word EDE and destination word TONI and places the 16-bit result into the destination word TONI. For this example, the instruction is located at address 2,F034h. Source: Word EDE at address 3379Ch, pointed to by PC + 4766h which is the 16-bit result of 3379Ch 2F036h = 04766h. Address 2F036h is the location of the index for this example. Word TONI located at address 00778h pointed to by the absolute address 00778h.
After: Address Space 2F03Ah 2F038h 2F036h 2F034h xxxxh 0778h 4766h 5092h PC 2F03Ah 2F038h 2F036h 2F034h Address Space xxxxh 0778h 4766h 5092h PC
Destination:
Before:
3379Eh 3379Ch
xxxxh 5432h
3379Eh 3379Ch
xxxxh 5432h
0077Ah 00778h
xxxxh 2345h
0077Ah 00778h
xxxxh 7777h
4-27
CPU Registers
Comment: Example:
The instruction adds the 8-bit data contained in source byte EDE and destination byte TONI and places the result into the destination byte TONI. Source: Byte EDE located at address 3579Ch, pointed to by PC + 14766h, is the 20-bit result of 3579Ch - 21036h = 14766h. Address 21036h is the address of the index in this example. Byte TONI located at address 77778h, pointed to by PC + 56740h, is the 20-bit result of 77778h - 21038h = 56740h. Address 21038h is the address of the index in this example..
After: Address Space
Destination:
Before:
Address Space
PC
7777Ah 77778h
xxxxh xx45h
7777Ah 77778h
xxxxh xx77h
3579Eh 3579Ch
xxxxh xx32h
3579Eh 3579Ch
xxxxh xx32h
4-28
CPU Registers
4.4.4
Absolute Mode
The Absolute mode uses the contents of the word following the instruction as the address of the operand. The Absolute mode has two addressing possibilities:
- Absolute mode in lower 64-KB memory - MSP430X instruction with Absolute mode
4-29
CPU Registers
Comment:
Example:
This instruction adds the 16-bit data contained in the absolute source and destination addresses and places the result into the destination. Source: Destination: Word at address EDE Word at address TONI
After: Address Space
PC
0777Ah 07778h
xxxxh 2345h
0777Ah 07778h
xxxxh 7777h
0579Eh 0579Ch
xxxxh 5432h
0579Eh 0579Ch
xxxxh 5432h
4-30
CPU Registers
Comment:
Example:
This instruction adds the 20-bit data contained in the absolute source and destination addresses and places the result into the destination. Source: Destination:
Before: Address Space 2103Ah 21038h 21036h 21034h 21032h xxxxh 7778h 579Ch 52D2h 1987h PC 2103Ah 21038h 21036h 21034h 21032h
Two words beginning with address EDE Two words beginning with address TONI
After: Address Space xxxxh 7778h 579Ch 52D2h 1987h PC
7777Ah 77778h
0001h 2345h
7777Ah 77778h
0007h 7777h
3579Eh 3579Ch
0006h 5432h
3579Eh 3579Ch
0006h 5432h
4-31
CPU Registers
4.4.5
Comment:
Example:
This instruction adds the two 16-bit operands contained in the source and the destination addresses and places the result into the destination. Source: Word pointed to by R5. R5 contains address 3,579Ch for this example. Word pointed to by R6 + 2100h which results in address 45678h + 2100h = 7778h.
After: Address Space 21038h 21036h 21034h xxxxh 2100h 55A6h PC Register Address Space 21038h 21036h 21034h xxxxh 2100h 55A6h PC R5 R6 Register
Destination:
Before:
R5 R6
3579Ch 45678h
3579Ch 45678h
4777Ah 47778h
xxxxh 2345h
4777Ah 47778h
xxxxh 7777h
3579Eh 3579Ch
xxxxh 5432h R5
3579Eh 3579Ch
xxxxh 5432h R5
4-32
CPU Registers
4.4.6
Comment: Example:
This instruction adds the 8-bit data contained in the source and the destination addresses and places the result into the destination. Source: Byte pointed to by R5. R5 contains address 3,579Ch for this example. Byte pointed to by R6 + 0h which results in address 0778h for this example.
After: Address Space 21038h 21036h 21034h xxxxh 0000h 55F6h PC Register Address Space 21038h 21036h 21034h xxxxh 0000h 55F6h PC R5 R6 Register
Destination:
Before:
R5 R6
3579Ch 00778h
3579Dh 00778h
0077Ah 00778h
xxxxh xx45h
0077Ah 00778h
xxxxh xx77h
3579Dh 3579Ch
xxh 32h R5
3579Dh 3579Ch
xxh xx32h
R5
4-33
CPU Registers
4.4.7
Immediate Mode
The Immediate mode allows accessing constants as operands by including the constant in the memory location following the instruction. The program counter PC is used with the Indirect Autoincrement mode. The PC points to the immediate value contained in the next word. After the fetching of the immediate operand, the PC is incremented by 2 for byte, word, or address-word instructions. The Immediate mode has two addressing possibilities:
- 8- or 16-bit constants with MSP430 instructions - 20-bit constants with MSP430X instruction
Operation:
Comment: Example:
This instruction adds the 16-bit immediate operand 3456h to the data in the destination address TONI. Source: Destination:
Before: Address Space 2103Ah 21038h 21036h 21034h xxxxh 0778h 3456h 50B2h PC 2103Ah 21038h 21036h 21034h
0077Ah 00778h
xxxxh 2345h
0077Ah 00778h
xxxxh 579Bh
4-34
CPU Registers
Operation:
Comment: Example:
This instruction adds the 20-bit immediate operand 23456h to the data in the destination address TONI. Source: Destination:
Before: Address Space 2103Ah 21038h 21036h 21034h 21032h xxxxh 7778h 3456h 50F2h 1907h PC 2103Ah 21038h 21036h 21034h 21032h
20-bit immediate value 23456h. Two words beginning with address TONI.
After: Address Space xxxxh 7778h 3456h 50F2h 1907h PC
7777Ah 77778h
0001h 2345h
7777Ah 77778h
0003h 579Bh
4-35
and the RETA instruction. This can be done if a few, simple rules are met:
J
Placement of all constants, variables, arrays, tables, and data in the lower 64 KB. This allows the use of MSP430 instructions with 16-bit addressing for all data accesses. No pointers with 20-bit addresses are needed. J Placement of subroutine constants immediately after the subroutine code. This allows the use of the symbolic addressing mode with its 16-bit index to reach addresses within the range of PC 32 KB.
- To use only MSP430X instructions: The disadvantages of this method are
the reduced speed due to the additional CPU cycles and the increased program space due to the necessary extension word for any double operand instruction.
- Use the best fitting instruction where needed
The following sections list and describe the MSP430 and MSP430X instructions.
4-36
4.5.1
MSP430 Instructions
The MSP430 instructions can be used, regardless if the program resides in the lower 64 KB or beyond it. The only exceptions are the instructions CALL and RET which are limited to the lower 64 KB address range. CALLA and RETA instructions have been added to the MSP430X CPU to handle subroutines in the entire address range with no code size overhead.
MOV(.B) ADD(.B) ADDC(.B) SUB(.B) SUBC(.B) CMP(.B) DADD(.B) BIT(.B) BIC(.B) BIS(.B) XOR(.B) AND(.B)
* 0 1
The status bit is affected The status bit is not affected The status bit is cleared The status bit is set
4-37
* 0 1
The status bit is affected The status bit is not affected The status bit is cleared The status bit is set
4-38
Jumps
Figure 424 shows the format for MSP430 and MSP430X jump instructions. The signed 10-bit word offset of the jump instruction is multiplied by two, sign-extended to a 20-bit address, and added to the 20-bit program counter. This allows jumps in a range of -511 to +512 words relative to the program counter in the full 20-bit address space Jumps do not affect the status bits. Table 46 lists and describes the eight jump instructions.
Condition
4-39
Emulated Instructions
In addition to the MSP430 and MSP430X instructions, emulated instructions are instructions that make code easier to write and read, but do not have op-codes themselves. Instead, they are replaced automatically by the assembler with a core instruction. There is no code or performance penalty for using emulated instructions. The emulated instructions are listed in Table 47.
4-40
4 4
The cycle count in MSP430 CPU is 5. The cycle count in MSP430 CPU is 6.
4-41
Format-II (Single Operand) Instruction Cycles and Lengths Table 49 lists the length and the CPU cycles for all addressing modes of the MSP430 single operand instructions.
Example Example SWPB R5 RRC @R9 SWPB @R10+ CALL #LABEL CALL 2(R7) PUSH EDE SXT &EDE
PUSH 3 3 3 3 4 4 4
The cycle count in MSP430 CPU is 4. The cycle count in MSP430 CPU is 5. Also, the cycle count is 5 for X(Rn) addressing mode, when Rn = SP.
Jump Instructions. Cycles and Lengths All jump instructions require one code word, and take two CPU cycles to execute, regardless of whether the jump is taken or not.
4-42
Format-I (Double Operand) Instruction Cycles and Lengths Table 410 lists the length and CPU cycles for all addressing modes of the MSP430 format-I instructions.
Dst Rm
No. of Cycles 1 2 4 4 4 2 3 5 5 5 2 3 5 5 5 2 3 5 5 5 3 3 6 6 6 3 3 6 6 6 3 3 6 6 6
Length g of Instruction 1 1 2 2 2 1 1 2 2 2 1 1 2 2 2 2 2 3 3 3 2 2 3 3 3 2 2 3 3 3 2 2 3 3 3 MOV BR ADD XOR MOV AND BR XOR MOV XOR ADD BR XOR MOV MOV MOV BR MOV ADD ADD MOV BR MOV ADD MOV AND BR CMP MOV MOV MOV BR MOV MOV MOV
Example R5,R8 R9 R5,4(R6) R8,EDE R5,&EDE @R4,R5 @R8 @R5,8(R6) @R5,EDE @R5,&EDE @R5+,R6 @R9+ @R5,8(R6) @R9+,EDE @R9+,&EDE #20,R9 #2AEh #0300h,0(SP) #33,EDE #33,&EDE 2(R5),R7 2(R6) 4(R7),TONI 4(R4),6(R9) 2(R4),&TONI EDE,R6 EDE EDE,TONI EDE,0(SP) EDE,&TONI &EDE,R8 &EDE &EDE,TONI &EDE,0(SP) &EDE,&TONI
4-43
4.5.2
Format-II instructions.
- Extension word for all other address mode combinations.
4-44
10:9 ZC
Repetition bit. 0: 1: The number of instruction repetitions is set by extension-word bits 3:0. The number of instructions repetitions is defined by the value of the four LSBs of Rn. See description for bits 3:0.
A/L
Data length extension bit. Together with the B/W-bits of the following MSP430 instruction, the AL bit defines the used data length of the instruction. A/L 0 0 1 1 B/W 0 1 0 1 Comment Reserved 20-bit address-word 16-bit word 8-bit byte
5:4 3:0
Reserved Repetition Count. # = 0: # = 1: These four bits set the repetition count n. These bits contain n - 1. These four bits define the CPU register whose bits 3:0 set the number of repetitions. Rn.3:0 contain n - 1.
4-45
Reserved The four MSBs of the 20-bit destination. Depending on the destination addressing mode, these four MSBs may belong to an index or to an absolute address.
Note: B/W and A/L Bit Settings for SWPBX and SXTX The B/W and A/L bit settings for SWPBX and SXTX are: A/L 0 0 1 1 B/W 0 1 0 1 SWPBX.A, SXTX.A n.a. SWPB.W, SXTX.W n.a.
4-46
Rsvd As
(n1)/Rn Rdst
0 9 Source R9
0 0
0 1
0 0
0 8(R8) Destination R8
Rsvd As
Op-code
X(Rn) 01: Address word 18xx extension word 0 0 0 1 1 0 (PC) 12345h 1 1 0 1 0 3 4 15 (R15) @PC+
14 (XOR)
4-47
DADDX(.B,.A) src,dst BITX(.B,.A) BICX(.B,.A) BISX(.B,.A) XORX(.B,.A) ANDX(.B,.A) src,dst src,dst src,dst src,dst src,dst
* 0 1
The status bit is affected The status bit is not affected The status bit is cleared The status bit is set
4-48
The four possible addressing combinations for the extension word for format-I instructions are shown in Figure 429.
Op-code
A/L B/W
0 As
0 dst
Op-code
0 src
0 Ad
A/L B/W
0 As
dst.19:16 dst
Op-code
dst.15:0
A/L B/W
0 As
dst.19:16 dst
Op-code
If the 20-bit address of a source or destination operand is located in memory, not in a CPU register, then two words are used for this operand as shown in Figure 430.
19:16
4-49
PUSHX(.B,.A) src RRCM(.A) RRUM(.A) RRAM(.A) RLAM(.A) RRCX(.B,.A) RRUX(.B,.A) RRAX(.B,.A) SWPBX(.A) SXTX(.A) SXTX(.A) #n,Rdst #n,Rdst #n,Rdst #n,Rdst dst dst dst dst Rdst dst
4-50
The three possible addressing mode combinations for format-II instructions are shown in Figure 431.
1 Op-code
A/L B/W
0 1
0 x
0 dst
1 Op-code
A/L B/W
0 x
0 1
dst.19:16 dst
dst.15:0
Extended Format II Instruction Format Exceptions Exceptions for the Format II instruction formats are shown below.
n1
4-51
#imm/abs19:16
Op-code
0(PC)
#imm15:0 / &abs15:0
Rsrc index15:0
Op-code
0(PC)
Op-code index15:0
Rdst
#imm/ix/abs19:16
4-52
4-53
4-54
Rn n/1 n/1 n/1 n/1 2+n/1 2+2n/1 2+n/1 2+2n/1 4/1 1+n/2 1+n/2 1+n/2 1+n/2 4/2 5/2 3/2 4/2
X(Rn) 6/2 5/3 7/3 5/3 7/3 5/3 7/3 5/3 7/3
EDE 6/2 5/3 7/3 5/3 7/3 5/3 7/3 5/3 7/3
&EDE 6/2 5/3 7/3 5/3 7/3 5/3 7/3 5/3 7/3
MSP430X Format-I (Double-Operand) Instruction Cycles and Lengths Table 418 lists the length and CPU cycles for all addressing modes of the MSP430X extended format-I instructions.
4-55
Examples BITX.B R5,R8 ADDX R9,PC ANDX.A R5,4(R6) XORX R8,EDE BITX.W R5,&EDE BITX @R5,R8 ADDX @R9,PC ANDX.A @R5,4(R6) XORX @R8,EDE BITX.B @R5,&EDE BITX @R5+,R8 ADDX.A @R9+,PC ANDX @R5+,4(R6) XORX.B @R8+,EDE BITX @R5+,&EDE BITX #20,R8 ADDX.A #FE000h,PC ANDX #1234,4(R6) XORX #A5A5h,EDE BITX.B #12,&EDE BITX 2(R5),R8 SUBX.A 2(R6),PC ANDX 4(R7),4(R6) XORX.B 2(R6),EDE BITX 8(SP),&EDE BITX.B EDE,R8 ADDX.A EDE,PC ANDX EDE,4(R6) ANDX EDE,TONI BITX EDE,&TONI BITX &EDE,R8 ADDX.A &EDE,PC ANDX.B &EDE,4(R6) XORX &EDE,TONI BITX &EDE,&TONI
Repeat instructions require n+1 cycles where n is the number of times the instruction is executed. Reduce the cycle count by one for MOV, BIT, and CMP instructions. Reduce the cycle count by two for MOV, BIT, and CMP instructions. Reduce the cycle count by one for MOV, ADD, and SUB instructions.
4-56
MSP430X Address Instruction Cycles and Lengths Table 419 lists the length and the CPU cycles for all addressing modes of the MSP430X address instructions.
Addressing Mode
Source Rn
MOVA 1 1 2 2 2 1 1 1 1 2 2 2 2 2 2 2 2
Example CMPA R5,R8 SUBA R9,PC MOVA R5,4(R6) MOVA R8,EDE MOVA R5,&EDE MOVA @R5,R8 MOVA @R9,PC MOVA @R5+,R8 MOVA @R9+,PC CMPA #20,R8 SUBA #FE000h,PC MOVA 2(R5),R8 MOVA 2(R6),PC MOVA EDE,R8 MOVA EDE,PC MOVA &EDE,R8 MOVA &EDE,PC
Rm PC Rm PC Rm PC Rm PC Rm PC Rm PC
4-57
140
180
1C0
200
240
280
2C0
300
340
380
3C0
MOVA, CMPA, ADDA, SUBA, RRCM, RRAM, RLAM, RRUM RRC RRC.B SWPB RRA.B SXT PUSH PUSH.B CALL PUSHM.A, POPM.A, PUSHM.W, POPM.W RETI CALLA
JNE/JNZ JEQ/JZ JNC JC JN JGE JL JMP MOV, MOV.B ADD, ADD.B ADDC, ADDC.B SUBC, SUBC.B SUB, SUB.B CMP, CMP.B DADD, DADD.B BIT, BIT.B BIC, BIC.B BIS, BIS.B XOR, XOR.B AND, AND.B
4-58
4.6.1
12 11 0 0 0
&abs.15:0 0 0 0 0 src 0 x.15:0 0 0 0 0 src 0 &abs.15:0 0 0 0 0 src 0 x.15:0 0 0 0 0 imm.19:16 1 0 0 0 dst 1 1 1 dst MOVA Rsrc,X(Rdst) 15-bit index x MOVA #imm20,Rdst 1 1 0 &abs.19:16 0 1 1 dst MOVA x(Rsrc),Rdst 15-bit index x MOVA Rsrc,&abs20
imm.15:0 MOVA CMPA ADDA SUBA 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 src src src src 1 1 1 1 1 1 1 1 0 0 1 1 0 1 0 1 dst dst dst dst MOVA Rsrc,Rdst CMPA Rsrc,Rdst ADDA Rsrc,Rdst SUBA Rsrc,Rdst
Instruction Group Instruction RRCM.A RRAM.A RLAM.A RRUM.A RRCM.W RRAM.W RLAM.W RRUM.W 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit loc.
Inst. ID 8 0 1 0 1 0 1 0 1
Instruction Identifier 7 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 4 0 0 0 0 1 1 1 1 3
dst 0 dst dst dst dst dst dst dst dst RRCM.A #n,Rdst RRAM.A #n,Rdst RLAM.A #n,Rdst RRUM.A #n,Rdst RRCM.W #n,Rdst RRAM.W #n,Rdst RLAM.W #n,Rdst RRUM.W #n,Rdst
12 11 10 9 0 0 0 0 0 0 0 0 n1 n1 n1 n1 n1 n1 n1 n1 0 0 1 1 0 0 1 1
4-59
dst dst
x.15:0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 1 1 1 0 1 1 0 0 1 0 dst dst &abs.19:16 CALLA @Rdst CALLA @Rdst+ CALLA &abs20
x.15:0 0 0 0 1 0 0 1 1 1
imm.15:0 Reserved Reserved PUSHM.A PUSHM.W POPM.A POPM.W 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 1 1 1 1 0 1 0 1 1 1 0 1 1 x 0 x x x x x x x x x PUSHM.A #n,Rdst PUSHM.W #n,Rdst POPM.A #n,Rdst POPM.W #n,Rdst
n1 n1 n1 n1
4-60
MSP430 Instructions
4.6.2
MSP430 Instructions
The MSP430 instructions are listed and described on the following pages.
4-61
MSP430 Instructions
Add carry to destination Add carry to destination ADC ADC.B dst dst or ADC.W dst
Operation Emulation
Description
The carry bit (C) is added to the destination operand. The previous contents of the destination are lost. N: Set if result is negative, reset if positive Z: Set if result is zero, reset otherwise C: Set if dst was incremented from 0FFFFh to 0000, reset otherwise Set if dst was incremented from 0FFh to 00, reset otherwise V: Set if an arithmetic overflow occurs, otherwise reset OSCOFF, CPUOFF, and GIE are not affected. The 16-bit counter pointed to by R13 is added to a 32-bit counter pointed to by R12. ADD @R13,0(R12) ; Add LSDs ADC 2(R12) ; Add carry to MSD The 8-bit counter pointed to by R13 is added to a 16-bit counter pointed to by R12. ADD.B @R13,0(R12) ; Add LSDs ADC.B 1(R12) ; Add carry to MSD
Status Bits
Example
4-62
MSP430 Instructions
Add source word to destination word Add source byte to destination byte ADD ADD.B src,dst or ADD.W src,dst src,dst
Operation Description
src + dst dst The source operand is added to the destination operand. The previous content of the destination is lost. N: Z: C: V: Set if result is negative (MSB = 1), reset if positive (MSB = 0) Set if result is zero, reset otherwise Set if there is a carry from the MSB of the result, reset otherwise Set if the result of two positive operands is negative, or if the result of two negative numbers is positive, reset otherwise.
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Ten is added to the 16-bit counter CNTR located in lower 64 K.
ADD.W Example
#10,&CNTR
A table word pointed to by R5 (20-bit address in R5) is added to R6. The jump to label TONI is performed on a carry.
@R5,R6 TONI
A table byte pointed to by R5 (20-bit address) is added to R6. The jump to label TONI is performed if no carry occurs. The table pointer is auto-incremented by 1. R6.19:8 = 0
@R5+,R6 TONI
4-63
MSP430 Instructions
Add source word and carry to destination word Add source byte and carry to destination byte ADDC ADDC.B src,dst or ADDC.W src,dst src,dst
Operation Description
src + dst + C dst The source operand and the carry bit C are added to the destination operand. The previous content of the destination is lost. N: Z: C: V: Set if result is negative (MSB = 1), reset if positive (MSB = 0) Set if result is zero, reset otherwise Set if there is a carry from the MSB of the result, reset otherwise Set if the result of two positive operands is negative, or if the result of two negative numbers is positive, reset otherwise.
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Constant value 15 and the carry of the previous instruction are added to the 16-bit counter CNTR located in lower 64 K.
ADDC.W Example
#15,&CNTR
A table word pointed to by R5 (20-bit address) and the carry C are added to R6. The jump to label TONI is performed on a carry. R6.19:16 = 0
@R5,R6 TONI
A table byte pointed to by R5 (20-bit address) and the carry bit C are added to R6. The jump to label TONI is performed if no carry occurs. The table pointer is auto-incremented by 1. R6.19:8 = 0
@R5+,R6 TONI
4-64
MSP430 Instructions
Logical AND of source word with destination word Logical AND of source byte with destination byte AND AND.B src,dst or AND.W src,dst src,dst
Operation Description
src .and. dst dst The source operand and the destination operand are logically ANDed. The result is placed into the destination. The source operand is not affected. N: Z: C: V: Set if result is negative (MSB = 1), reset if positive (MSB = 0) Set if result is zero, reset otherwise Set if the result is not zero, reset otherwise. C = (.not. Z) Reset
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. The bits set in R5 (16-bit data) are used as a mask (AA55h) for the word TOM located in the lower 64 K. If the result is zero, a branch is taken to label TONI. R5.19:16 = 0 MOV AND JZ ... or shorter: #AA55h,R5 R5,&TOM TONI ; Load 16-bit mask to R5 ; TOM .and. R5 -> TOM ; Jump if result 0 ; Result > 0
AND JZ Example
#AA55h,&TOM TONI
A table byte pointed to by R5 (20-bit address) is logically ANDed with R6. R5 is incremented by 1 after the fetching of the byte. R6.19:8 = 0
AND.B @R5+,R6
4-65
MSP430 Instructions
Clear bits set in source word in destination word Clear bits set in source byte in destination byte BIC BIC.B src,dst or BIC.W src,dst src,dst
Operation Description
(.not. src) .and. dst dst The inverted source operand and the destination operand are logically ANDed. The result is placed into the destination. The source operand is not affected. N: Z: C: V: Not affected Not affected Not affected Not affected
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. The bits 15:14 of R5 (16-bit data) are cleared. R5.19:16 = 0
BIC Example
#0C000h,R5
A table word pointed to by R5 (20-bit address) is used to clear bits in R7. R7.19:16 = 0
BIC.B @R5,&P1OUT
4-66
MSP430 Instructions
Set bits set in source word in destination word Set bits set in source byte in destination byte BIS BIS.B src,dst or BIS.W src,dst src,dst
Operation Description
src .or. dst dst The source operand and the destination operand are logically ORed. The result is placed into the destination. The source operand is not affected. N: Z: C: V: Not affected Not affected Not affected Not affected
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Bits 15 and 13 of R5 (16-bit data) are set to one. R5.19:16 = 0
BIS Example
#A000h,R5
; Set R5 bits
A table word pointed to by R5 (20-bit address) is used to set bits in R7. R7.19:16 = 0
; Set bits in R7
A table byte pointed to by R5 (20-bit address) is used to set bits in Port1. R5 is incremented by 1 afterwards.
BIS.B
@R5+,&P1OUT
4-67
MSP430 Instructions
Test bits set in source word in destination word Test bits set in source byte in destination byte BIT BIT.B src,dst or BIT.W src,dst src,dst
Operation Description
src .and. dst The source operand and the destination operand are logically ANDed. The result affects only the status bits in SR. Register Mode: the register bits Rdst.19:16 (.W) resp. Rdst. 19:8 (.B) are not cleared!
Status Bits
N: Z: C: V:
Set if result is negative (MSB = 1), reset if positive (MSB = 0) Set if result is zero, reset otherwise Set if the result is not zero, reset otherwise. C = (.not. Z) Reset
OSCOFF, CPUOFF, and GIE are not affected. Test if one or both of bits 15 and 14 of R5 (16-bit data) is set. Jump to label TONI if this is the case. R5.19:16 are not affected.
#C000h,R5 TONI
; Test R5.15:14 bits ; At least one bit is set in R5 ; Both bits are reset
A table word pointed to by R5 (20-bit address) is used to test bits in R7. Jump to label TONI if at least one bit is set. R7.19:16 are not affected.
A table byte pointed to by R5 (20-bit address) is used to test bits in output Port1. Jump to label TONI if no bit is set. The next table byte is addressed.
@R5+,&P1OUT TONI
; Test I/O port P1 bits. R5 + 1 ; No corresponding bit is set ; At least one bit is set
4-68
MSP430 Instructions
Branch to destination in lower 64K address space BR dst > PC MOV dst,PC dst
An unconditional branch is taken to an address anywhere in the lower 64K address space. All source addressing modes can be used. The branch instruction is a word instruction. Status bits are not affected. Examples for all addressing modes are given. BR #EXEC ;Branch to label EXEC or direct branch (e.g. #0A4h) ; Core instruction MOV @PC+,PC ; Branch to the address contained in EXEC ; Core instruction MOV X(PC),PC ; Indirect address ; Branch to the address contained in absolute ; address EXEC ; Core instruction MOV X(0),PC ; Indirect address ; Branch to the address contained in R5 ; Core instruction MOV R5,PC ; Indirect R5 ; Branch to the address contained in the word ; pointed to by R5. ; Core instruction MOV @R5,PC ; Indirect, indirect R5 ; Branch to the address contained in the word pointed ; to by R5 and increment pointer in R5 afterwards. ; The next timeS/W flow uses R5 pointerit can ; alter program execution due to access to ; next address in a table pointed to by R5 ; Core instruction MOV @R5,PC ; Indirect, indirect R5 with autoincrement ; Branch to the address contained in the address ; pointed to by R5 + X (e.g. table with address ; starting at X). X can be an address or a label ; Core instruction MOV X(R5),PC ; Indirect, indirect R5 + X
BR
EXEC
BR
&EXEC
BR
R5
BR
@R5
BR
@R5+
BR
X(R5)
4-69
MSP430 Instructions
Call a Subroutine in lower 64 K CALL dst 16-bit dst is evaluated and stored updated PC with return address to TOS saved 16-bit dst to PC
Description
A subroutine call is made from an address in the lower 64 K to a subroutine address in the lower 64 K. All seven source addressing modes can be used. The call instruction is a word instruction. The return is made with the RET instruction. Not affected PC.19:16:
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Examples for all addressing modes are given. Immediate Mode: Call a subroutine at label EXEC (lower 64 K) or call directly to address.
CALL CALL
#EXEC #0AA04h
Symbolic Mode: Call a subroutine at the 16-bit address contained in address EXEC. EXEC is located at the address (PC + X) where X is within PC32 K.
CALL
EXEC
Absolute Mode: Call a subroutine at the 16-bit address contained in absolute address EXEC in the lower 64 K.
CALL
&EXEC
Register Mode: Call a subroutine at the 16-bit address contained in register R5.15:0.
CALL
R5
; Start address at R5
Indirect Mode: Call a subroutine at the 16-bit address contained in the word pointed to by register R5 (20-bit address).
CALL
@R5
4-70
MSP430 Instructions
Clear destination Clear destination CLR CLR.B 0 > dst MOV MOV.B #0,dst #0,dst dst dst or CLR.W dst
Operation Emulation
The destination operand is cleared. Status bits are not affected. RAM word TONI is cleared. CLR TONI ; 0 > TONI
Example
Example
4-71
MSP430 Instructions
The carry bit (C) is cleared. The clear carry instruction is a word instruction. N: Z: C: V: Not affected Not affected Cleared Not affected
OSCOFF, CPUOFF, and GIE are not affected. The 16-bit decimal counter pointed to by R13 is added to a 32-bit counter pointed to by R12. CLRC DADD DADC ; C=0: defines start @R13,0(R12) ; add 16-bit counter to low word of 32-bit counter 2(R12) ; add carry to high word of 32-bit counter
4-72
MSP430 Instructions
Clear negative bit CLRN 0N or (.NOT.src .AND. dst > dst) BIC #4,SR
Emulation Description
The constant 04h is inverted (0FFFBh) and is logically ANDed with the destination operand. The result is placed into the destination. The clear negative bit instruction is a word instruction. N: Z: C: V: Reset to 0 Not affected Not affected Not affected
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. The Negative bit in the status register is cleared. This avoids special treatment with negative numbers of the subroutine called. CLRN CALL ...... ...... JN ...... ...... ...... RET
SUBR
SUBR
SUBRET
SUBRET
4-73
MSP430 Instructions
Clear zero bit CLRZ 0Z or (.NOT.src .AND. dst > dst) BIC #2,SR
Emulation Description
The constant 02h is inverted (0FFFDh) and logically ANDed with the destination operand. The result is placed into the destination. The clear zero bit instruction is a word instruction. N: Z: C: V: Not affected Reset to 0 Not affected Not affected
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. The zero bit in the status register is cleared. CLRZ Indirect, Auto-Increment mode: Call a subroutine at the 16-bit address contained in the word pointed to by register R5 (20-bit address) and increment the 16-bit address in R5 afterwards by 2. The next time the software uses R5 as a pointer, it can alter the program execution due to access to the next word address in the table pointed to by R5.
CALL
@R5+
Indexed mode: Call a subroutine at the 16-bit address contained in the 20-bit address pointed to by register (R5 + X), e.g. a table with addresses starting at X. The address is within the lower 64 KB. X is within 32 KB.
CALL
X(R5)
4-74
MSP430 Instructions
Compare source word and destination word Compare source byte and destination byte CMP CMP.B src,dst or CMP.W src,dst src,dst
Operation Description
(.not.src) + 1 + dst or dst src The source operand is subtracted from the destination operand. This is made by adding the 1s complement of the source + 1 to the destination. The result affects only the status bits in SR. Register Mode: the register bits Rdst.19:16 (.W) resp. Rdst. 19:8 (.B) are not cleared.
Status Bits
N: Z: C: V:
Set if result is negative (src > dst), reset if positive (src = dst) Set if result is zero (src = dst), reset otherwise (src dst) Set if there is a carry from the MSB, reset otherwise Set if the subtraction of a negative source operand from a positive destination operand delivers a negative result, or if the subtraction of a positive source operand from a negative destination operand delivers a positive result, reset otherwise (no overflow).
OSCOFF, CPUOFF, and GIE are not affected. Compare word EDE with a 16-bit constant 1800h. Jump to label TONI if EDE equals the constant. The address of EDE is within PC 32 K.
#01800h,EDE TONI
; Compare word EDE with 1800h ; EDE contains 1800h ; Not equal
A table word pointed to by (R5 + 10) is compared with R7. Jump to label TONI if R7 contains a lower, signed 16-bit number. R7.19:16 is not cleared. The address of the source operand is a 20-bit address in full memory range.
A table byte pointed to by R5 (20-bit address) is compared to the value in output Port1. Jump to label TONI if values are equal. The next table byte is addressed.
4-75
MSP430 Instructions
Add carry decimally to destination Add carry decimally to destination DADC DADC.B dst dst or DADC.W src,dst
Operation Emulation
The carry bit (C) is added decimally to the destination. N: Set if MSB is 1 Z: Set if dst is 0, reset otherwise C: Set if destination increments from 9999 to 0000, reset otherwise Set if destination increments from 99 to 00, reset otherwise V: Undefined OSCOFF, CPUOFF, and GIE are not affected. The four-digit decimal number contained in R5 is added to an eight-digit decimal number pointed to by R8. CLRC DADD DADC R5,0(R8) 2(R8) ; Reset carry ; next instructions start condition is defined ; Add LSDs + C ; Add carry to MSD
Example
The two-digit decimal number contained in R5 is added to a four-digit decimal number pointed to by R8. CLRC DADD.B DADC R5,0(R8) 1(R8) ; Reset carry ; next instructions start condition is defined ; Add LSDs + C ; Add carry to MSDs
4-76
MSP430 Instructions
Add source word and carry decimally to destination word Add source byte and carry decimally to destination byte DADD DADD.B src,dst or DADD.W src,dst src,dst
Operation Description
src + dst + C dst (decimally) The source operand and the destination operand are treated as two (.B) or four (.W) binary coded decimals (BCD) with positive signs. The source operand and the carry bit C are added decimally to the destination operand. The source operand is not affected. The previous content of the destination is lost. The result is not defined for non-BCD numbers. N: Z: C: V: Set if MSB of result is 1 (word > 7999h, byte > 79h), reset if MSB is 0. Set if result is zero, reset otherwise Set if the BCD result is too large (word > 9999h, byte > 99h), reset otherwise Undefined
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Decimal 10 is added to the 16-bit BCD counter DECCNTR.
DADD #10h,&DECCNTR ; Add 10 to 4-digit BCD counter Example The eight-digit BCD number contained in 16-bit RAM addresses BCD and BCD+2 is added decimally to an eight-digit BCD number contained in R4 and R5 (BCD+2 and R5 contain the MSDs). The carry C is added, and cleared.
; Clear carry ; Add LSDs. R4.19:16 = 0 ; Add MSDs with carry. R5.19:16 = 0 ; Result >9999,9999: go to error routine ; Result ok
OVERFLOW
The two-digit BCD number contained in word BCD (16-bit address) is added decimally to a two-digit BCD number contained in R4. The carry C is added, also. R4.19:8 = 0
4-77
MSP430 Instructions
Decrement destination Decrement destination DEC DEC.B dst dst or DEC.W dst
The destination operand is decremented by one. The original contents are lost. N: Z: C: V: Set if result is negative, reset if positive Set if dst contained 1, reset otherwise Reset if dst contained 0, set otherwise Set if an arithmetic overflow occurs, otherwise reset. Set if initial value of destination was 08000h, otherwise reset. Set if initial value of destination was 080h, otherwise reset.
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. R10 is decremented by 1 DEC R10 ; Decrement R10
; Move a block of 255 bytes from memory location starting with EDE to memory location starting with ;TONI. Tables should not overlap: start of destination address TONI must not be within the range EDE ; to EDE+0FEh ; MOV #EDE,R6 MOV #255,R10 L$1 MOV.B @R6+,TONIEDE1(R6) DEC R10 JNZ L$1 ; Do not transfer tables using the routine above with the overlap shown in Figure 436.
TONI EDE+254
TONI+254
4-78
MSP430 Instructions
Double-decrement destination Double-decrement destination DECD DECD.B dst dst or DECD.W dst
The destination operand is decremented by two. The original contents are lost. N: Z: C: V: Set if result is negative, reset if positive Set if dst contained 2, reset otherwise Reset if dst contained 0 or 1, set otherwise Set if an arithmetic overflow occurs, otherwise reset. Set if initial value of destination was 08001 or 08000h, otherwise reset. Set if initial value of destination was 081 or 080h, otherwise reset.
OSCOFF, CPUOFF, and GIE are not affected. R10 is decremented by 2. DECD R10 ; Decrement R10 by two
; Move a block of 255 words from memory location starting with EDE to memory location ; starting with TONI ; Tables should not overlap: start of destination address TONI must not be within the ; range EDE to EDE+0FEh ; MOV #EDE,R6 MOV #510,R10 L$1 MOV @R6+,TONIEDE2(R6) DECD R10 JNZ L$1 Example Memory at location LEO is decremented by two. DECD.B LEO ; Decrement MEM(LEO)
4-79
MSP430 Instructions
Emulation Description
All interrupts are disabled. The constant 08h is inverted and logically ANDed with the status register (SR). The result is placed into the SR. Status bits are not affected. GIE is reset. OSCOFF and CPUOFF are not affected. The general interrupt enable (GIE) bit in the status register is cleared to allow a nondisrupted move of a 32-bit counter. This ensures that the counter is not modified during the move by any interrupt. DINT NOP MOV MOV EINT Note: ; All interrupt events using the GIE bit are disabled COUNTHI,R5 ; Copy counter COUNTLO,R6 ; All interrupt events using the GIE bit are enabled Disable Interrupt
If any code sequence needs to be protected from interruption, the DINT should be executed at least one instruction before the beginning of the uninterruptible sequence, or should be followed by a NOP instruction.
4-80
MSP430 Instructions
Enable (general) interrupts EINT 1 GIE or (0008h .OR. SR > SR / .src .OR. dst > dst) BIS #8,SR
Emulation Description
All interrupts are enabled. The constant #08h and the status register SR are logically ORed. The result is placed into the SR. Status bits are not affected. GIE is set. OSCOFF and CPUOFF are not affected. The general interrupt enable (GIE) bit in the status register is set.
; Interrupt routine of ports P1.2 to P1.7 ; P1IN is the address of the register where all port bits are read. P1IFG is the address of ; the register where all interrupt events are latched. ; PUSH.B &P1IN BIC.B @SP,&P1IFG ; Reset only accepted flags EINT ; Preset port 1 interrupt flags stored on stack ; other interrupts are allowed BIT #Mask,@SP JEQ MaskOK ; Flags are present identically to mask: jump ...... MaskOK BIC #Mask,@SP ...... INCD SP ; Housekeeping: inverse to PUSH instruction ; at the start of interrupt subroutine. Corrects ; the stack pointer. RETI Note: Enable Interrupt
The instruction following the enable interrupt instruction (EINT) is always executed, even if an interrupt service request is pending when the interrupts are enable.
4-81
MSP430 Instructions
Increment destination Increment destination INC INC.B dst dst or INC.W dst
The destination operand is incremented by one. The original contents are lost. N: Set if result is negative, reset if positive Z: Set if dst contained 0FFFFh, reset otherwise Set if dst contained 0FFh, reset otherwise C: Set if dst contained 0FFFFh, reset otherwise Set if dst contained 0FFh, reset otherwise V: Set if dst contained 07FFFh, reset otherwise Set if dst contained 07Fh, reset otherwise OSCOFF, CPUOFF, and GIE are not affected. The status byte, STATUS, of a process is incremented. When it is equal to 11, a branch to OVFL is taken. INC.B CMP.B JEQ STATUS #11,STATUS OVFL
4-82
MSP430 Instructions
Double-increment destination Double-increment destination INCD INCD.B dst dst or INCD.W dst
The destination operand is incremented by two. The original contents are lost. N: Set if result is negative, reset if positive Z: Set if dst contained 0FFFEh, reset otherwise Set if dst contained 0FEh, reset otherwise C: Set if dst contained 0FFFEh or 0FFFFh, reset otherwise Set if dst contained 0FEh or 0FFh, reset otherwise V: Set if dst contained 07FFEh or 07FFFh, reset otherwise Set if dst contained 07Eh or 07Fh, reset otherwise OSCOFF, CPUOFF, and GIE are not affected. The item on the top of the stack (TOS) is removed without using a register. ....... PUSH INCD
R5 SP
; R5 is the result of a calculation, which is stored ; in the system stack ; Remove TOS by double-increment from stack ; Do not use INCD.B, SP is a word-aligned ; register
RET Example The byte on the top of the stack is incremented by two. INCD.B 0(SP) ; Byte on TOS is increment by two
4-83
MSP430 Instructions
The destination operand is inverted. The original contents are lost. N: Set if result is negative, reset if positive Z: Set if dst contained 0FFFFh, reset otherwise Set if dst contained 0FFh, reset otherwise C: Set if result is not zero, reset otherwise ( = .NOT. Zero) Set if result is not zero, reset otherwise ( = .NOT. Zero) V: Set if initial destination operand was negative, otherwise reset OSCOFF, CPUOFF, and GIE are not affected. Content of R5 is negated (twos complement). MOV #00AEh,R5 ; INV R5 ; Invert R5, INC R5 ; R5 is now negated, Content of memory byte LEO is negated. MOV.B INV.B INC.B #0AEh,LEO ; MEM(LEO) = 0AEh LEO ; Invert LEO, MEM(LEO) = 051h LEO ; MEM(LEO) is negated,MEM(LEO) = 052h
Example
4-84
MSP430 Instructions
JC JHS Syntax
Jump if carry Jump if Higher or Same (unsigned) JC JHS label label PC + (2 Offset) PC execute the following instruction
Operation
If C = 1: If C = 0:
Description
The carry bit C in the status register is tested. If it is set, the signed 10-bit word offset contained in the instruction is multiplied by two, sign extended, and added to the 20-bit program counter PC. This means a jump in the range -511 to +512 words relative to the PC in the full memory range. If C is reset, the instruction after the jump is executed. JC is used for the test of the carry bit C JHS is used for the comparison of unsigned numbers
Status bits are not affected OSCOFF, CPUOFF, and GIE are not affected The state of the port 1 pin P1IN.1 bit defines the program flow.
#2,&P1IN Label1
; Port 1, bit 1 set? Bit -> C ; Yes, proceed at Label1 ; No, continue
If R5 R6 (unsigned) the program continues at Label2 ; Is R5 R6? Info to C ; Yes, C = 1 ; No, R5 < R6. Continue
R6,R5 Label2
If R5 12345h (unsigned operands) the program continues at Label2 ; Is R5 12345h? Info to C ; Yes, 12344h < R5 <= F,FFFFh. C = 1 ; No, R5 < 12345h. Continue
4-85
MSP430 Instructions
JEQ,JZ Syntax
Jump if equal,Jump if zero JZ JEQ label label PC + (2 Offset) PC execute following instruction
Operation
If Z = 1: If Z = 0:
Description
The Zero bit Z in the status register is tested. If it is set, the signed 10-bit word offset contained in the instruction is multiplied by two, sign extended, and added to the 20-bit program counter PC. This means a jump in the range -511 to +512 words relative to the PC in the full memory range. If Z is reset, the instruction after the jump is executed. JZ is used for the test of the Zero bit Z JEQ is used for the comparison of operands
Status bits are not affected OSCOFF, CPUOFF, and GIE are not affected The state of the P2IN.0 bit defines the program flow
#1,&P2IN Label1
R7 (20-bit counter) is incremented. If its content is zero, the program continues at Label4.
4-86
MSP430 Instructions
Jump if Greater or Equal (signed) JGE label PC + (2 Offset) PC execute following instruction
If (N .xor. V) = 0: If (N .xor. V) = 1:
Description
The negative bit N and the overflow bit V in the status register are tested. If both bits are set or both are reset, the signed 10-bit word offset contained in the instruction is multiplied by two, sign extended, and added to the 20-bit program counter PC. This means a jump in the range -511 to +512 words relative to the PC in full Memory range. If only one bit is set, the instruction after the jump is executed. JGE is used for the comparison of signed operands: also for incorrect results due to overflow, the decision made by the JGE instruction is correct. Note: JGE emulates the non-implemented JP (jump if positive) instruction if used after the instructions AND, BIT, RRA, SXTX and TST. These instructions clear the V-bit.
Status bits are not affected OSCOFF, CPUOFF, and GIE are not affected If byte EDE (lower 64 K) contains positive data, go to Label1. Software can run in the full memory range.
&EDE Label1
; Is EDE positive? V <- 0 ; Yes, JGE emulates JP ; No, 80h <= EDE <= FFh
If the content of R6 is greater than or equal to the memory pointed to by R7, the program continues a Label5. Signed data. Data and program in full memory range. ; Is R6 @R7? ; Yes, go to Label5 ; No, continue here.
@R7,R6 Label5
If R5 12345h (signed operands) the program continues at Label2. Program in full memory range. ; Is R5 12345h? ; Yes, 12344h < R5 <= 7FFFFh. ; No, 80000h <= R5 < 12345h.
#12345h,R5 Label2
4-87
MSP430 Instructions
JL Syntax Operation
If (N .xor. V) = 1: If (N .xor. V) = 0:
Description
The negative bit N and the overflow bit V in the status register are tested. If only one is set, the signed 10-bit word offset contained in the instruction is multiplied by two, sign extended, and added to the 20-bit program counter PC. This means a jump in the range -511 to +512 words relative to the PC in full memory range. If both bits N and V are set or both are reset, the instruction after the jump is executed. JL is used for the comparison of signed operands: also for incorrect results due to overflow, the decision made by the JL instruction is correct.
Status bits are not affected OSCOFF, CPUOFF, and GIE are not affected If byte EDE contains a smaller, signed operand than byte TONI, continue at Label1. The address EDE is within PC 32 K.
&TONI,EDE Label1
If the signed content of R6 is less than the memory pointed to by R7 (20-bit address) the program continues at Label Label5. Data and program in full memory range.
@R7,R6 Label5
If R5 < 12345h (signed operands) the program continues at Label2. Data and program in full memory range.
CMPA JL ...
#12345h,R5 Label2
; Is R5 < 12345h? ; Yes, 80000h =< R5 < 12345h. ; No, 12344h < R5 =< 7FFFFh.
4-88
MSP430 Instructions
PC + (2 Offset) PC The signed 10-bit word offset contained in the instruction is multiplied by two, sign extended, and added to the 20-bit program counter PC. This means an unconditional jump in the range -511 to +512 words relative to the PC in the full memory. The JMP instruction may be used as a BR or BRA instruction within its limited range relative to the program counter. Status bits are not affected OSCOFF, CPUOFF, and GIE are not affected The byte STATUS is set to 10. Then a jump to label MAINLOOP is made. Data in lower 64 K, program in full memory range.
The interrupt vector TAIV of Timer_A3 is read and used for the program flow. Program in full memory range, but interrupt handlers always starts in lower 64K.
; Add Timer_A interrupt vector to PC ; No Timer_A interrupt pending ; Timer block 1 caused interrupt ; Timer block 2 caused interrupt ; No legal interrupt, return
4-89
MSP430 Instructions
JN Syntax Operation
Description
The negative bit N in the status register is tested. If it is set, the signed 10-bit word offset contained in the instruction is multiplied by two, sign extended, and added to the 20-bit program counter PC. This means a jump in the range -511 to +512 words relative to the PC in the full memory range. If N is reset, the instruction after the jump is executed. Status bits are not affected OSCOFF, CPUOFF, and GIE are not affected The byte COUNT is tested. If it is negative, program execution continues at Label0. Data in lower 64 K, program in full memory range.
&COUNT Label0
R6 is subtracted from R5. If the result is negative, program continues at Label2. Program in full memory range.
R6,R5 Label2
R7 (20-bit counter) is decremented. If its content is below zero, the program continues at Label4. Program in full memory range.
SUBA JN ...
#1,R7 Label4
4-90
MSP430 Instructions
Jump if No carry Jump if lower (unsigned) JNC JLO If C = 0: If C = 1: label label PC + (2 Offset) PC execute following instruction
Operation
Description
The carry bit C in the status register is tested. If it is reset, the signed 10-bit word offset contained in the instruction is multiplied by two, sign extended, and added to the 20-bit program counter PC. This means a jump in the range -511 to +512 words relative to the PC in the full memory range. If C is set, the instruction after the jump is executed. JNC is used for the test of the carry bit C JLO is used for the comparison of unsigned numbers .
Status bits are not affected OSCOFF, CPUOFF, and GIE are not affected If byte EDE < 15 the program continues at Label2. Unsigned data. Data in lower 64 K, program in full memory range.
#15,&EDE Label2
; Is EDE < 15? Info to C ; Yes, EDE < 15. C = 0 ; No, EDE 15. Continue
The word TONI is added to R5. If no carry occurs, continue at Label0. The address of TONI is within PC 32 K.
TONI,R5 Label0
4-91
MSP430 Instructions
Jump if Not Zero Jump if Not Equal JNZ JNE If Z = 0: If Z = 1: label label PC + (2 Offset) PC execute following instruction
Operation
Description
The zero bit Z in the status register is tested. If it is reset, the signed 10-bit word offset contained in the instruction is multiplied by two, sign extended, and added to the 20-bit program counter PC. This means a jump in the range -511 to +512 words relative to the PC in the full memory range. If Z is set, the instruction after the jump is executed. JNZ is used for the test of the Zero bit Z JNE is used for the comparison of operands
Status bits are not affected OSCOFF, CPUOFF, and GIE are not affected The byte STATUS is tested. If it is not zero, the program continues at Label3. The address of STATUS is within PC 32 K.
STATUS Label3
If word EDE 1500 the program continues at Label2. Data in lower 64 K, program in full memory range.
#1500,&EDE Label2
R7 (20-bit counter) is decremented. If its content is not zero, the program continues at Label4. Program in full memory range.
#1,R7 Label4
4-92
MSP430 Instructions
Move source word to destination word Move source byte to destination byte MOV MOV.B src dst The source operand is copied to the destination. The source operand is not affected. N: Z: C: V: Not affected Not affected Not affected Not affected src,dst or MOV.W src,dst src,dst
Operation Description
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Move a 16-bit constant 1800h to absolute address-word EDE (lower 64 K).
MOV Example
#01800h,&EDE
The contents of table EDE (word data, 16-bit addresses) are copied to table TOM. The length of the tables is 030h words. Both tables reside in the lower 64K.
#EDE,R10
@R10+,TOM-EDE-2(R10) ; R10 points to both tables. R10+2 #EDE+60h,R10 Loop ; End of table reached? ; Not yet ; Copy completed
The contents of table EDE (byte data, 16-bit addresses) are copied to table TOM. The length of the tables is 020h bytes. Both tables may reside in full memory range, but must be within R10 32 K.
#EDE,R10 #20h,R9
@R10+,TOM-EDE-1(R10) ; R10 points to both tables. ; R10+1 R9 Loop ; Decrement counter ; Not yet done ; Copy completed
4-93
MSP430 Instructions
No operation is performed. The instruction may be used for the elimination of instructions during the software check or for defined waiting times. Status bits are not affected.
Status Bits
4-94
MSP430 Instructions
Pop word from stack to destination Pop byte from stack to destination POP POP.B dst dst
Operation
@SP > temp SP + 2 > SP temp > dst MOV MOV.B @SP+,dst @SP+,dst or MOV.W @SP+,dst
The stack location pointed to by the stack pointer (TOS) is moved to the destination. The stack pointer is incremented by two afterwards. Status bits are not affected. The contents of R7 and the status register are restored from the stack. POP POP R7 SR ; Restore R7 ; Restore status register
Example
The contents of RAM byte LEO is restored from the stack. POP.B LEO ; The low byte of the stack is moved to LEO.
Example
The contents of R7 is restored from the stack. POP.B R7 ; The low byte of the stack is moved to R7, ; the high byte of R7 is 00h
Example
The contents of the memory pointed to by R7 and the status register are restored from the stack. POP.B 0(R7) ; The low byte of the stack is moved to the ; the byte which is pointed to by R7 : Example: R7 = 203h ; Mem(R7) = low byte of system stack : Example: R7 = 20Ah ; Mem(R7) = low byte of system stack ; Last word on stack moved to the SR
POP Note:
SR
The system stack pointer (SP) is always incremented by two, independent of the byte suffix.
4-95
MSP430 Instructions
Save a word on the stack Save a byte on the stack PUSH PUSH.B dst or PUSH.W dst dst
Operation
SP 2 SP dst @SP The 20-bit stack pointer SP is decremented by two. The operand is then copied to the RAM word addressed by the SP. A pushed byte is stored in the low byte, the high byte is not affected. Not affected. OSCOFF, CPUOFF, and GIE are not affected. Save the two 16-bit registers R9 and R10 on the stack.
Description
R9 R10
Save the two bytes EDE and TONI on the stack. The addresses EDE and TONI are within PC 32 K.
PUSH.B PUSH.B
EDE TONI
4-96
MSP430 Instructions
Description
The 16-bit return address (lower 64 K), pushed onto the stack by a CALL instruction is restored to the PC. The program continues at the address following the subroutine call. The four MSBs of the program counter PC.19:16 are cleared. Not affected PC.19:16:
Status Bits
Cleared
OSCOFF, CPUOFF, and GIE are not affected. Call a subroutine SUBR in the lower 64 K and return to the address in the lower 64K after the CALL
; Call subroutine starting at SUBR ; Return by RET to here ; Save R14 (16 bit data) ; Subroutine code ; Restore R14 ; Return to lower 64 K
Item n SP PCReturn
SP
Item n
4-97
MSP430 Instructions
Return from interrupt RETI @SP SP + 2 @SP SP + 2 SR.15:0 Restore saved status register SR with PC.19:16 SP PC.15:0 Restore saved program counter PC.15:0 SP House keeping
Description
The status register is restored to the value at the beginning of the interrupt service routine. This includes the four MSBs of the program counter PC.19:16. The stack pointer is incremented by two afterwards. The 20-bit PC is restored from PC.19:16 (from same stack location as the status bits) and PC.15:0. The 20-bit program counter is restored to the value at the beginning of the interrupt service routine. The program continues at the address following the last executed instruction when the interrupt was granted. The stack pointer is incremented by two afterwards.
Status Bits
N: Z: C: V:
OSCOFF, CPUOFF, and GIE are restored from stack Interrupt handler in the lower 64 K. A 20-bit return address is stored on the stack.
#2,R14 #2,R14
; Save R14 and R13 (20-bit data) ; Interrupt handler code ; Restore R13 and R14 (20-bit data) ; Return to 20-bit address in full memory range
4-98
MSP430 Instructions
Rotate left arithmetically Rotate left arithmetically RLA RLA.B dst dst or RLA.W dst
Operation Emulation
C < MSB < MSB1 .... LSB+1 < LSB < 0 ADD ADD.B dst,dst dst,dst
Description
The destination operand is shifted left one position as shown in Figure 438. The MSB is shifted into the carry bit (C) and the LSB is filled with 0. The RLA instruction acts as a signed multiplication by 2. An overflow occurs if dst 04000h and dst < 0C000h before operation is performed: the result has changed sign.
An overflow occurs if dst 040h and dst < 0C0h before the operation is performed: the result has changed sign. Status Bits N: Z: C: V: Set if result is negative, reset if positive Set if result is zero, reset otherwise Loaded from the MSB Set if an arithmetic overflow occurs: the initial value is 04000h dst < 0C000h; reset otherwise Set if an arithmetic overflow occurs: the initial value is 040h dst < 0C0h; reset otherwise
OSCOFF, CPUOFF, and GIE are not affected. R7 is multiplied by 2. RLA R7 ; Shift left R7 ( 2)
Example
The low byte of R7 is multiplied by 4. RLA.B RLA.B Note: RLA R7 R7 ; Shift left low byte of R7 ( 2) ; Shift left low byte of R7 ( 4)
The assembler does not recognize the instruction: It must be substituted by: ADD @R5+,2(R5) ADD.B @R5+,1(R5) or
4-99
MSP430 Instructions
Rotate left through carry Rotate left through carry RLC RLC.B dst dst or RLC.W dst
C < MSB < MSB1 .... LSB+1 < LSB < C ADDC dst,dst
The destination operand is shifted left one position as shown in Figure 439. The carry bit (C) is shifted into the LSB and the MSB is shifted into the carry bit (C).
Status Bits
N: Z: C: V:
Set if result is negative, reset if positive Set if result is zero, reset otherwise Loaded from the MSB Set if an arithmetic overflow occurs the initial value is 04000h dst < 0C000h; reset otherwise Set if an arithmetic overflow occurs: the initial value is 040h dst < 0C0h; reset otherwise
OSCOFF, CPUOFF, and GIE are not affected. R5 is shifted left one position. RLC R5 ; (R5 x 2) + C > R5
Example
The input P1IN.1 information is shifted into the LSB of R5. BIT.B RLC #2,&P1IN R5 ; Information > Carry ; Carry=P0in.1 > LSB of R5
Example
The MEM(LEO) content is shifted left one position. RLC.B Note: LEO ; Mem(LEO) x 2 + C > Mem(LEO)
The assembler does not recognize the instruction: RLC @R5+, It must be substituted by: ADDC @R5+,2(R5) ADDC.B @R5+,1(R5) or ADDC(.B) @R5
4-100
MSP430 Instructions
Rotate Right Arithmetically destination word Rotate Right Arithmetically destination byte RRA.B dst or RRA.W dst ... LSB+1 LSB C
The destination operand is shifted right arithmetically by one bit position as shown in Figure 440. The MSB retains its value (sign). RRA operates equal to a signed division by 2. The MSB is retained and shifted into the MSB-1. The LSB+1 is shifted into the LSB. The previous LSB is shifted into the carry bit C. N: Z: C: V: Set if result is negative (MSB = 1), reset otherwise (MSB = 0) Set if result is zero, reset otherwise Loaded from the LSB Reset
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. The signed 16-bit number in R5 is shifted arithmetically right one position.
RRA Example
R5
; R5/2 -> R5
The signed RAM byte EDE is shifted arithmetically right one position.
RRA.B
EDE
19 C 0 0 0 0
15 MSB
0 LSB
4-101
MSP430 Instructions
Rotate Right through carry destination word Rotate Right through carry destination byte RRC RRC.B dst or RRC.W dst dst
Operation Description
C MSB MSB-1 ... LSB+1 LSB C The destination operand is shifted right by one bit position as shown in Figure 441. The carry bit C is shifted into the MSB and the LSB is shifted into the carry bit C. N: Z: C: V: Set if result is negative (MSB = 1), reset otherwise (MSB = 0) Set if result is zero, reset otherwise Loaded from the LSB Reset
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. RAM word EDE is shifted right one bit position. The MSB is loaded with 1.
19 C 0 0 0 0
15 MSB
0 LSB
4-102
MSP430 Instructions
Subtract source and borrow/.NOT. carry from destination Subtract source and borrow/.NOT. carry from destination SBC SBC.B dst dst or SBC.W dst
Operation
dst + 0FFFFh + C > dst dst + 0FFh + C > dst SUBC SUBC.B #0,dst #0,dst
Emulation
Description
The carry bit (C) is added to the destination operand minus one. The previous contents of the destination are lost. N: Set if result is negative, reset if positive Z: Set if result is zero, reset otherwise C: Set if there is a carry from the MSB of the result, reset otherwise. Set to 1 if no borrow, reset if borrow. V: Set if an arithmetic overflow occurs, reset otherwise. OSCOFF, CPUOFF, and GIE are not affected. The 16-bit counter pointed to by R13 is subtracted from a 32-bit counter pointed to by R12. SUB SBC @R13,0(R12) 2(R12) ; Subtract LSDs ; Subtract carry from MSD
Status Bits
Example
The 8-bit counter pointed to by R13 is subtracted from a 16-bit counter pointed to by R12. SUB.B SBC.B Note: @R13,0(R12) 1(R12) Borrow Implementation . Borrow Yes No Carry bit 0 1 ; Subtract LSDs ; Subtract carry from MSD
4-103
MSP430 Instructions
The carry bit (C) is set. N: Z: C: V: Not affected Not affected Set Not affected
OSCOFF, CPUOFF, and GIE are not affected. Emulation of the decimal subtraction: Subtract R5 from R6 decimally Assume that R5 = 03987h and R6 = 04137h ADD INV SETC DADD #06666h,R5 R5 ; Move content R5 from 09 to 60Fh ; R5 = 03987h + 06666h = 09FEDh ; Invert this (result back to 09) ; R5 = .NOT. R5 = 06012h ; Prepare carry = 1 ; Emulate subtraction by addition of: ; (010000h R5 1) ; R6 = R6 + R5 + 1 ; R6 = 0150h
DSUB
R5,R6
4-104
MSP430 Instructions
The negative bit (N) is set. N: Z: C: V: Set Not affected Not affected Not affected
Mode Bits
4-105
MSP430 Instructions
The zero bit (Z) is set. N: Z: C: V: Not affected Set Not affected Not affected
Mode Bits
4-106
MSP430 Instructions
Subtract source word from destination word Subtract source byte from destination byte SUB SUB.B src,dst or SUB.W src,dst src,dst or dst src dst
Operation Description
The source operand is subtracted from the destination operand. This is made by adding the 1s complement of the source + 1 to the destination. The source operand is not affected, the result is written to the destination operand. N: Z: C: V: Set if result is negative (src > dst), reset if positive (src <= dst) Set if result is zero (src = dst), reset otherwise (src dst) Set if there is a carry from the MSB, reset otherwise Set if the subtraction of a negative source operand from a positive destination operand delivers a negative result, or if the subtraction of a positive source operand from a negative destination operand delivers a positive result, reset otherwise (no overflow).
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. A 16-bit constant 7654h is subtracted from RAM word EDE.
SUB Example
A table word pointed to by R5 (20-bit address) is subtracted from R7. Afterwards, if R7 contains zero, jump to label TONI. R5 is then auto-incremented by 2. R7.19:16 = 0.
@R5+,R7 TONI
; Subtract table number from R7. R5 + 2 ; R7 = @R5 (before subtraction) ; R7 <> @R5 (before subtraction)
Byte CNT is subtracted from byte R12 points to. The address of CNT is within PC 32 K. The address R12 points to is in full memory range.
SUB.B
CNT,0(R12)
4-107
MSP430 Instructions
Subtract source word with carry from destination word Subtract source byte with carry from destination byte SUBC SUBC.B src,dst or SUBC.W src,dst src,dst
Operation Description
The source operand is subtracted from the destination operand. This is done by adding the 1s complement of the source + carry to the destination. The source operand is not affected, the result is written to the destination operand. Used for 32, 48, and 64-bit operands. N: Z: C: V: Set if result is negative (MSB = 1), reset if positive (MSB = 0) Set if result is zero, reset otherwise Set if there is a carry from the MSB, reset otherwise Set if the subtraction of a negative source operand from a positive destination operand delivers a negative result, or if the subtraction of a positive source operand from a negative destination operand delivers a positive result, reset otherwise (no overflow).
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. A 16-bit constant 7654h is subtracted from R5 with the carry from the previous instruction. R5.19:16 = 0
SUBC.W Example
#7654h,R5
A 48-bit number (3 words) pointed to by R5 (20-bit address) is subtracted from a 48-bit counter in RAM, pointed to by R7. R5 points to the next 48-bit number afterwards. The address R7 points to is in full memory range.
Byte CNT is subtracted from the byte, R12 points to. The carry of the previous instruction is used. The address of CNT is in lower 64 K.
SUBC.B
&CNT,0(R12)
4-108
MSP430 Instructions
dst.15:8 dst.7:0 The high and the low byte of the operand are exchanged. PC.19:16 bits are cleared in register mode. Not affected OSCOFF, CPUOFF, and GIE are not affected. Exchange the bytes of RAM word EDE (lower 64 K).
MOV SWPB
#1234h,&EDE &EDE
7 Low Byte
7 Low Byte
4-109
MSP430 Instructions
dst.7 dst.15:8, dst.7 dst.19:8 (Register Mode) Register Mode: the sign of the low byte of the operand is extended into the bits Rdst.19:8 Rdst.7 = 0: Rdst.19:8 = 000h afterwards. Rdst.7 = 1: Rdst.19:8 = FFFh afterwards. Other Modes: the sign of the low byte of the operand is extended into the high byte. dst.7 = 0: high byte = 00h afterwards. dst.7 = 1: high byte = FFh afterwards.
Status Bits
N: Z: C: V:
Set if result is negative, reset otherwise Set if result is zero, reset otherwise Set if result is not zero, reset otherwise (C = .not.Z) Reset
OSCOFF, CPUOFF, and GIE are not affected. The signed 8-bit data in EDE (lower 64 K) is sign extended and added to the 16-bit signed data in R7.
&EDE,R5 R5 R5,R7
; EDE -> R5. 00XXh ; Sign extend low byte to R5.19:8 ; Add signed 16-bit values
The signed 8-bit data in EDE (PC 32 K) is sign extended and added to the 20-bit data in R7.
EDE,R5 R5 R5,R7
; EDE -> R5. 00XXh ; Sign extend low byte to R5.19:8 ; Add signed 20-bit values
4-110
MSP430 Instructions
Test destination Test destination TST TST.B dst dst or TST.W dst
Operation
Emulation
Description
The destination operand is compared with zero. The status bits are set according to the result. The destination is not affected. N: Z: C: V: Set if destination is negative, reset if positive Set if destination contains zero, reset otherwise Set Reset
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. R7 is tested. If it is negative, continue at R7NEG; if it is positive but not zero, continue at R7POS. TST JN JZ ...... ...... ...... R7 R7NEG R7ZERO ; Test R7 ; R7 is negative ; R7 is zero ; R7 is positive but not zero ; R7 is negative ; R7 is zero
The low byte of R7 is tested. If it is negative, continue at R7NEG; if it is positive but not zero, continue at R7POS. TST.B JN JZ ...... ..... ...... R7 R7NEG R7ZERO ; Test low byte of R7 ; Low byte of R7 is negative ; Low byte of R7 is zero ; Low byte of R7 is positive but not zero ; Low byte of R7 is negative ; Low byte of R7 is zero
4-111
MSP430 Instructions
Exclusive OR source word with destination word Exclusive OR source byte with destination byte XOR XOR.B dst or XOR.W dst dst
Operation Description
src .xor. dst dst The source and destination operands are exclusively ORed. The result is placed into the destination. The source operand is not affected. The previous content of the destination is lost. N: Z: C: V: Set if result is negative (MSB = 1), reset if positive (MSB = 0) Set if result is zero, reset otherwise Set if result is not zero, reset otherwise (C = .not. Z) Set if both operands are negative before execution, reset otherwise
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Toggle bits in word CNTR (16-bit data) with information (bit = 1) in address-word TONI. Both operands are located in lower 64 K.
XOR Example
&TONI,&CNTR
A table word pointed to by R5 (20-bit address) is used to toggle bits in R6. R6.19:16 = 0.
XOR Example
@R5,R6
; Toggle bits in R6
Reset to zero those bits in the low byte of R7 that are different from the bits in byte EDE. R7.19:8 = 0. The address of EDE is within PC 32 K.
XOR.B INV.B
EDE,R7 R7
; Set different bits to 1 in R7. ; Invert low byte of R7, high byte is 0h
4-112
Extended Instructions
4.6.3
Extended Instructions
The extended MSP430X instructions give the MSP430X CPU full access to its 20-bit address space. Some MSP430X instructions require an additional word of op-code called the extension word. All addresses, indexes, and immediate numbers have 20-bit values, when preceded by the extension word. The MSP430X extended instructions are listed and described in the following pages. For MSP430X instructions that do not require the extension word, it is noted in the instruction description.
4-113
Extended Instructions
Add carry to destination address-word Add carry to destination word Add carry to destination byte ADCX.A ADCX ADCX.B dst dst dst
or
ADCX.W
dst
Operation Emulation
Description
The carry bit (C) is added to the destination operand. The previous contents of the destination are lost. N: Z: C: V: Set if result is negative (MSB = 1), reset if positive (MSB = 0) Set if result is zero, reset otherwise Set if there is a carry from the MSB of the result, reset otherwise Set if the result of two positive operands is negative, or if the result of two negative numbers is positive, reset otherwise
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. The 40-bit counter, pointed to by R12 and R13, is incremented. INCX.A ADCX.A @R12 @R13 ; Increment lower 20 bits ; Add carry to upper 20 bits
4-114
Extended Instructions
Add source address-word to destination address-word Add source word to destination word Add source byte to destination byte ADDX.A ADDX ADDX.B src,dst src,dst or ADDX.W src,dst
src,dst
Operation Description
src + dst dst The source operand is added to the destination operand. The previous contents of the destination are lost. Both operands can be located in the full address space. N: Z: C: V: Set if result is negative (MSB = 1), reset if positive (MSB = 0) Set if result is zero, reset otherwise Set if there is a carry from the MSB of the result, reset otherwise Set if the result of two positive operands is negative, or if the result of two negative numbers is positive, reset otherwise
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Ten is added to the 20-bit pointer CNTR located in two words CNTR (LSBs) and CNTR+2 (MSBs).
ADDX.A Example
#10,CNTR
A table word (16-bit) pointed to by R5 (20-bit address) is added to R6. The jump to label TONI is performed on a carry.
@R5,R6 TONI
A table byte pointed to by R5 (20-bit address) is added to R6. The jump to label TONI is performed if no carry occurs. The table pointer is auto-incremented by 1.
@R5+,R6 TONI
; Add table byte to R6. R5 + 1. R6: 000xxh ; Jump if no carry ; Carry occurred
Note: Use ADDA for the following two cases for better code density and execution. ADDX.A Rsrc,Rdst or ADDX.A #imm20,Rdst
4-115
Extended Instructions
Add source address-word and carry to destination address-word Add source word and carry to destination word Add source byte and carry to destination byte ADDCX.A src,dst ADDCX src,dst or ADDCX.W src,dst ADDCX.B src,dst src + dst + C dst The source operand and the carry bit C are added to the destination operand. The previous contents of the destination are lost. Both operands may be located in the full address space. N: Z: C: V: Set if result is negative (MSB = 1), reset if positive (MSB = 0) Set if result is zero, reset otherwise Set if there is a carry from the MSB of the result, reset otherwise Set if the result of two positive operands is negative, or if the result of two negative numbers is positive, reset otherwise
Operation Description
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Constant 15 and the carry of the previous instruction are added to the 20-bit counter CNTR located in two words.
ADDCX.A Example
#15,&CNTR
A table word pointed to by R5 (20-bit address) and the carry C are added to R6. The jump to label TONI is performed on a carry.
@R5,R6 TONI
A table byte pointed to by R5 (20-bit address) and the carry bit C are added to R6. The jump to label TONI is performed if no carry occurs. The table pointer is auto-incremented by 1.
@R5+,R6 TONI
4-116
Extended Instructions
Logical AND of source address-word with destination address-word Logical AND of source word with destination word Logical AND of source byte with destination byte ANDX.A ANDX ANDX.B src,dst src,dst or ANDX.W src,dst
src,dst
Operation Description
src .and. dst dst The source operand and the destination operand are logically ANDed. The result is placed into the destination. The source operand is not affected. Both operands may be located in the full address space. N: Z: C: V: Set if result is negative (MSB = 1), reset if positive (MSB = 0) Set if result is zero, reset otherwise Set if the result is not zero, reset otherwise. C = (.not. Z) Reset
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. The bits set in R5 (20-bit data) are used as a mask (AAA55h) for the address-word TOM located in two words. If the result is zero, a branch is taken to label TONI.
; Load 20-bit mask to R5 ; TOM .and. R5 -> TOM ; Jump if result 0 ; Result > 0
ANDX.A JZ Example
#AAA55h,TOM TONI
A table byte pointed to by R5 (20-bit address) is logically ANDed with R6. R6.19:8 = 0. The table pointer is auto-incremented by 1.
ANDX.B
@R5+,R6
4-117
Extended Instructions
Clear bits set in source address-word in destination address-word Clear bits set in source word in destination word Clear bits set in source byte in destination byte BICX.A BICX BICX.B src,dst src,dst or BICX.W src,dst
src,dst
Operation Description
(.not. src) .and. dst dst The inverted source operand and the destination operand are logically ANDed. The result is placed into the destination. The source operand is not affected. Both operands may be located in the full address space. N: Z: C: V: Not affected Not affected Not affected Not affected
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. The bits 19:15 of R5 (20-bit data) are cleared.
BICX.A Example
#0F8000h,R5
A table word pointed to by R5 (20-bit address) is used to clear bits in R7. R7.19:16 = 0
BICX.W Example
@R5,R7
; Clear bits in R7
A table byte pointed to by R5 (20-bit address) is used to clear bits in output Port1.
BICX.B
@R5,&P1OUT
4-118
Extended Instructions
Set bits set in source address-word in destination address-word Set bits set in source word in destination word Set bits set in source byte in destination byte BISX.A BISX BISX.B src,dst src,dst or BISX.W src,dst
src,dst
Operation Description
src .or. dst dst The source operand and the destination operand are logically ORed. The result is placed into the destination. The source operand is not affected. Both operands may be located in the full address space. N: Z: C: V: Not affected Not affected Not affected Not affected
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Bits 16 and 15 of R5 (20-bit data) are set to one.
BISX.A Example
#018000h,R5
BISX.W Example
@R5,R7
; Set bits in R7
A table byte pointed to by R5 (20-bit address) is used to set bits in output Port1.
BISX.B
@R5,&P1OUT
4-119
Extended Instructions
Test bits set in source address-word in destination address-word Test bits set in source word in destination word Test bits set in source byte in destination byte BITX.A BITX BITX.B src,dst src,dst or BITX.W src,dst
src,dst
Operation Description
src .and. dst The source operand and the destination operand are logically ANDed. The result affects only the status bits. Both operands may be located in the full address space. N: Z: C: V: Set if result is negative (MSB = 1), reset if positive (MSB = 0) Set if result is zero, reset otherwise Set if the result is not zero, reset otherwise. C = (.not. Z) Reset
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Test if bit 16 or 15 of R5 (20-bit data) is set. Jump to label TONI if so.
#018000h,R5 TONI
; Test R5.16:15 bits ; At least one bit is set ; Both are reset
A table word pointed to by R5 (20-bit address) is used to test bits in R7. Jump to label TONI if at least one bit is set.
@R5,R7 TONI
; Test bits in R7: C = .not.Z ; At least one is set ; Both are reset
A table byte pointed to by R5 (20-bit address) is used to test bits in input Port1. Jump to label TONI if no bit is set. The next table byte is addressed.
@R5+,&P1IN TONI
; Test input P1 bits. R5 + 1 ; No corresponding input bit is set ; At least one bit is set
4-120
Extended Instructions
Clear destination address-word Clear destination word Clear destination byte CLRX.A CLRX CLRX.B 0 > dst MOVX.A MOVX MOVX.B #0,dst #0,dst #0,dst dst dst dst
or CLRX.W
dst
Operation Emulation
The destination operand is cleared. Status bits are not affected. RAM address-word TONI is cleared. CLRX.A TONI ; 0 > TONI
4-121
Extended Instructions
Compare source address-word and destination address-word Compare source word and destination word Compare source byte and destination byte CMPX.A CMPX CMPX.B src,dst src,dst or CMPX.W src,dst
src,dst
Operation Description
(.not. src) + 1 + dst or dst src The source operand is subtracted from the destination operand by adding the 1s complement of the source + 1 to the destination. The result affects only the status bits. Both operands may be located in the full address space. N: Z: C: V: Set if result is negative (src > dst), reset if positive (src <= dst) Set if result is zero (src = dst), reset otherwise (src dst) Set if there is a carry from the MSB, reset otherwise Set if the subtraction of a negative source operand from a positive destination operand delivers a negative result, or if the subtraction of a positive source operand from a negative destination operand delivers a positive result, reset otherwise (no overflow).
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Compare EDE with a 20-bit constant 18000h. Jump to label TONI if EDE equals the constant. CMPX.A JEQ ... #018000h,EDE TONI ; Compare EDE with 18000h ; EDE contains 18000h ; Not equal
Example
A table word pointed to by R5 (20-bit address) is compared with R7. Jump to label TONI if R7 contains a lower, signed, 16-bit number. CMPX.W JL ... @R5,R7 TONI ; Compare two signed numbers ; R7 < @R5 ; R7 >= @R5
Example
A table byte pointed to by R5 (20-bit address) is compared to the input in I/O Port1. Jump to label TONI if the values are equal. The next table byte is addressed. CMPX.B JEQ ... @R5+,&P1IN TONI ; Compare P1 bits with table. R5 + 1 ; Equal contents ; Not equal
Note: Use CMPA for the following two cases for better density and execution. CMPA Rsrc,Rdst or CMPA #imm20,Rdst
4-122
Extended Instructions
Add carry decimally to destination address-word Add carry decimally to destination word Add carry decimally to destination byte DADCX.A DADCX DADCX.B dst dst dst
or
DADCX.W
src,dst
Operation Emulation
dst + C > dst (decimally) DADDX.A DADDX DADDX.B #0,dst #0,dst #0,dst
The carry bit (C) is added decimally to the destination. N: Z: C: V: Set if MSB of result is 1 (address-word > 79999h, word > 7999h, byte > 79h), reset if MSB is 0. Set if result is zero, reset otherwise. Set if the BCD result is too large (address-word > 99999h, word > 9999h, byte > 99h), reset otherwise. Undefined.
OSCOFF, CPUOFF, and GIE are not affected. The 40-bit counter, pointed to by R12 and R13, is incremented decimally. DADDX.A DADCX.A #1,0(R12) 0(R13) ; Increment lower 20 bits ; Add carry to upper 20 bits
4-123
Extended Instructions
Add source address-word and carry decimally to destination address-word Add source word and carry decimally to destination word Add source byte and carry decimally to destination byte DADDX.A src,dst DADDX src,dst or DADDX.W src,dst DADDX.B src,dst src + dst + C dst (decimally) The source operand and the destination operand are treated as two (.B), four (.W), or five (.A) binary coded decimals (BCD) with positive signs. The source operand and the carry bit C are added decimally to the destination operand. The source operand is not affected. The previous contents of the destination are lost. The result is not defined for non-BCD numbers. Both operands may be located in the full address space. N: Z: C: V: Set if MSB of result is 1 (address-word > 79999h, word > 7999h, byte > 79h), reset if MSB is 0. Set if result is zero, reset otherwise. Set if the BCD result is too large (address-word > 99999h, word > 9999h, byte > 99h), reset otherwise. Undefined.
Operation Description
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Decimal 10 is added to the 20-bit BCD counter DECCNTR located in two words.
DADDX.A Example
The eight-digit BCD number contained in 20-bit addresses BCD and BCD+2 is added decimally to an eight-digit BCD number contained in R4 and R5 (BCD+2 and R5 contain the MSDs).
; Clear carry ; Add LSDs ; Add MSDs with carry ; Result >99999999: go to error routine Result ok
The two-digit BCD number contained in 20-bit address BCD is added decimally to a two-digit BCD number contained in R4.
4-124
Extended Instructions
Decrement destination address-word Decrement destination word Decrement destination byte DECX DECX DECX.B dst dst dst
or
DECX.W
dst
Operation Emulation
Description
The destination operand is decremented by one. The original contents are lost. N: Z: C: V: Set if result is negative, reset if positive Set if dst contained 1, reset otherwise Reset if dst contained 0, set otherwise Set if an arithmetic overflow occurs, otherwise reset.
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. RAM address-word TONI is decremented by 1 DECX.A TONI ; Decrement TONI
4-125
Extended Instructions
Double-decrement destination address-word Double-decrement destination word Double-decrement destination byte DECDX.A DECDX DECDX.B dst dst dst
or
DECDX.W
dst
Operation Emulation
The destination operand is decremented by two. The original contents are lost. N: Z: C: V: Set if result is negative, reset if positive Set if dst contained 2, reset otherwise Reset if dst contained 0 or 1, set otherwise Set if an arithmetic overflow occurs, otherwise reset.
OSCOFF, CPUOFF, and GIE are not affected. RAM address-word TONI is decremented by 2. DECDX.A TONI ; Decrement TONI by two
4-126
Extended Instructions
Increment destination address-word Increment destination word Increment destination byte INCX.A INCX INCX.B dst dst dst
or INCX.W
dst
Operation Emulation
The destination operand is incremented by one. The original contents are lost. N: Set if result is negative, reset if positive Z: Set if dst contained 0FFFFFh, reset otherwise Set if dst contained 0FFFFh, reset otherwise Set if dst contained 0FFh, reset otherwise C: Set if dst contained 0FFFFFh, reset otherwise Set if dst contained 0FFFFh, reset otherwise Set if dst contained 0FFh, reset otherwise V: Set if dst contained 07FFFh, reset otherwise Set if dst contained 07FFFh, reset otherwise Set if dst contained 07Fh, reset otherwise OSCOFF, CPUOFF, and GIE are not affected. RAM address-word TONI is incremented by 1. INCX.A TONI ; Increment TONI (20-bits)
4-127
Extended Instructions
Double-increment destination address-word Double-increment destination word Double-increment destination byte INCDX.A INCDX INCDX.B dst dst dst
or INCDX.W
dst
Operation Emulation
The destination operand is incremented by two. The original contents are lost. N: Set if result is negative, reset if positive Z: Set if dst contained 0FFFFEh, reset otherwise Set if dst contained 0FFFEh, reset otherwise Set if dst contained 0FEh, reset otherwise C: Set if dst contained 0FFFFEh or 0FFFFFh, reset otherwise Set if dst contained 0FFFEh or 0FFFFh, reset otherwise Set if dst contained 0FEh or 0FFh, reset otherwise V: Set if dst contained 07FFFEh or 07FFFFh, reset otherwise Set if dst contained 07FFEh or 07FFFh, reset otherwise Set if dst contained 07Eh or 07Fh, reset otherwise OSCOFF, CPUOFF, and GIE are not affected. RAM byte LEO is incremented by two; PC points to upper memory INCDX.B LEO ; Increment LEO by two
4-128
Extended Instructions
Invert destination Invert destination Invert destination INVX.A INVX INVX.B dst dst dst
or INVX.W
dst
Operation Emulation
The destination operand is inverted. The original contents are lost. N: Set if result is negative, reset if positive Z: Set if dst contained 0FFFFFh, reset otherwise Set if dst contained 0FFFFh, reset otherwise Set if dst contained 0FFh, reset otherwise C: Set if result is not zero, reset otherwise ( = .NOT. Zero) V: Set if initial destination operand was negative, otherwise reset OSCOFF, CPUOFF, and GIE are not affected. 20-bit content of R5 is negated (twos complement). INVX.A R5 ; Invert R5 INCX.A R5 ; R5 is now negated Content of memory byte LEO is negated. PC is pointing to upper memory INVX.B LEO ; Invert LEO INCX.B LEO ; MEM(LEO) is negated
Example
4-129
Extended Instructions
Move source address-word to destination address-word Move source word to destination word Move source byte to destination byte MOVX.A MOVX MOVX.B src dst The source operand is copied to the destination. The source operand is not affected. Both operands may be located in the full address space. N: Z: C: V: Not affected Not affected Not affected Not affected src,dst src,dst or MOVX.W src,dst
src,dst
Operation Description
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Move a 20-bit constant 18000h to absolute address-word EDE.
MOVX.A Example
#018000h,&EDE
The contents of table EDE (word data, 20-bit addresses) are copied to table TOM. The length of the table is 030h words.
#EDE,R10
@R10+,TOM-EDE-2(R10) ; R10 points to both tables. R10+2 #EDE+60h,R10 Loop ; End of table reached? ; Not yet ; Copy completed
The contents of table EDE (byte data, 20-bit addresses) are copied to table TOM. The length of the table is 020h bytes.
#EDE,R10 #20h,R9
@R10+,TOM-EDE-1(R10) ; R10 points to both tables. ; R10+1 R9 Loop ; Decrement counter ; Not yet done ; Copy completed
4-130
Extended Instructions
Ten of the 28 possible addressing combinations of the MOVX.A instruction can use the MOVA instruction. This saves two bytes and code cycles. Examples for the addressing combinations are:
MOVA Rsrc,Rdst MOVA #imm20,Rdst MOVA &abs20,Rdst MOVA @Rsrc,Rdst MOVA @Rsrc+,Rdst MOVA Rsrc,&abs20
The next four replacements are possible only if 16-bit indexes are sufficient for the addressing.
MOVA z16(Rsrc),Rdst ; Indexed/Reg MOVA Rsrc,z16(Rdst) ; Reg/Indexed MOVA symb16,Rdst MOVA Rsrc,symb16 ; Symbolic/Reg ; Reg/Symbolic
4-131
Extended Instructions
Restore n CPU registers (20-bit data) from the stack Restore n CPU registers (16-bit data) from the stack POPM.A POPM.W #n,Rdst #n,Rdst 1 n 16 or POPM #n,Rdst 1 n 16
Operation
POPM.A: Restore the register values from stack to the specified CPU registers. The stack pointer SP is incremented by four for each register restored from stack. The 20-bit values from stack (2 words per register) are restored to the registers. POPM.W: Restore the 16-bit register values from stack to the specified CPU registers. The stack pointer SP is incremented by two for each register restored from stack. The 16-bit values from stack (one word per register) are restored to the CPU registers. Note : This does not use the extension word.
Description
POPM.A: The CPU registers pushed on the stack are moved to the extended CPU registers, starting with the CPU register (Rdst - n + 1). The stack pointer is incremented by (n 4) after the operation. POPM.W: The 16-bit registers pushed on the stack are moved back to the CPU registers, starting with CPU register (Rdst - n + 1). The stack pointer is incremented by (n 2) after the instruction. The MSBs (Rdst.19:16) of the restored CPU registers are cleared
Not affected, except SR is included in the operation OSCOFF, CPUOFF, and GIE are not affected, except SR is included in the operation. Restore the 20-bit registers R9, R10, R11, R12, R13 from the stack.
Example
POPM.A Example
#5,R13
Restore the 16-bit registers R9, R10, R11, R12, R13 from the stack.
POPM.W
#5,R13
4-132
Extended Instructions
Save n CPU registers (20-bit data) on the stack Save n CPU registers (16-bit words) on the stack PUSHM.A PUSHM.W #n,Rdst #n,Rdst 1 n 16 or PUSHM 1 n 16
#n,Rdst
Operation
PUSHM.A: Save the 20-bit CPU register values on the stack. The stack pointer (SP) is decremented by four for each register stored on the stack. The MSBs are stored first (higher address). PUSHM.W: Save the 16-bit CPU register values on the stack. The stack pointer is decremented by two for each register stored on the stack.
Description
PUSHM.A: The n CPU registers, starting with Rdst backwards, are stored on the stack. The stack pointer is decremented by (n 4) after the operation. The data (Rn.19:0) of the pushed CPU registers is not affected. PUSHM.W: The n registers, starting with Rdst backwards, are stored on the stack. The stack pointer is decremented by (n 2) after the operation. The data (Rn.19:0) of the pushed CPU registers is not affected. Note : This instruction does not use the extension word.
Not affected. OSCOFF, CPUOFF, and GIE are not affected. Save the five 20-bit registers R9, R10, R11, R12, R13 on the stack.
PUSHM.A Example
#5,R13
Save the five 16-bit registers R9, R10, R11, R12, R13 on the stack.
PUSHM.W
#5,R13
4-133
Extended Instructions
Restore single address-word from the stack Restore single word from the stack Restore single byte from the stack POPX.A POPX POPX.B dst dst or POPX.W dst
dst
Operation
Restore the 8/16/20-bit value from the stack to the destination. 20-bit addresses are possible. The stack pointer SP is incremented by two (byte and word operands) and by four (address-word operand). MOVX(.B,.A) @SP+,dst
Emulation Description
The item on TOS is written to the destination operand. Register Mode, Indexed Mode, Symbolic Mode, and Absolute Mode are possible. The stack pointer is incremented by two or four. Note: the stack pointer is incremented by two also for byte operations.
Not affected. OSCOFF, CPUOFF, and GIE are not affected. Write the 16-bit value on TOS to the 20-bit address &EDE.
POPX.W Example
&EDE
POPX.A
R9
; Write address-word to R9
4-134
Extended Instructions
Save a single address-word on the stack Save a single word on the stack Save a single byte on the stack PUSHX.A src PUSHX src or PUSHX.W PUSHX.B src
src
Operation
Save the 8/16/20-bit value of the source operand on the TOS. 20-bit addresses are possible. The stack pointer (SP) is decremented by two (byte and word operands) or by four (address-word operand) before the write operation. The stack pointer is decremented by two (byte and word operands) or by four (address-word operand). Then the source operand is written to the TOS. All seven addressing modes are possible for the source operand. Note : This instruction does not use the extension word.
Description
Not affected. OSCOFF, CPUOFF, and GIE are not affected. Save the byte at the 20-bit address &EDE on the stack.
PUSHX.B Example
&EDE
PUSHX.A
R9
; Save address-word in R9
4-135
Extended Instructions
Rotate Left Arithmetically the 20-bit CPU register content Rotate Left Arithmetically the 16-bit CPU register content RLAM.A RLAM.W #n,Rdst #n,Rdst 1n4 or RLAM #n,Rdst 1n4
Operation Description
C MSB MSB-1 .... LSB+1 LSB 0 The destination operand is shifted arithmetically left one, two, three, or four positions as shown in Figure 444. RLAM works as a multiplication (signed and unsigned) with 2, 4, 8, or 16. The word instruction RLAM.W clears the bits Rdst.19:16 Note : This instruction does not use the extension word.
Status Bits
N:
Set if result is negative .A: Rdst.19 = 1, reset if Rdst.19 = 0 .W: Rdst.15 = 1, reset if Rdst.15 = 0 Set if result is zero, reset otherwise Loaded from the MSB (n = 1), MSB-1 (n = 2), MSB-2 (n = 3), MSB-3 (n = 4) Undefined
OSCOFF, CPUOFF, and GIE are not affected. The 20-bit operand in R5 is shifted left by three positions. It operates equal to an arithmetic multiplication by 8.
RLAM.A
#3,R5
; R5 = R5 x 8
19 C MSB
0 LSB 0
4-136
Extended Instructions
Rotate left arithmetically address-word Rotate left arithmetically word Rotate left arithmetically byte RLAX.B RLAX RLAX.B dst dst dst
or
RLAX.W
dst
Operation Emulation
C < MSB < MSB1 .... LSB+1 < LSB < 0 ADDX.A ADDX ADDX.B dst,dst dst,dst dst,dst
Description
The destination operand is shifted left one position as shown in Figure 445. The MSB is shifted into the carry bit (C) and the LSB is filled with 0. The RLAX instruction acts as a signed multiplication by 2.
Status Bits
N: Z: C: V:
Set if result is negative, reset if positive Set if result is zero, reset otherwise Loaded from the MSB Set if an arithmetic overflow occurs: the initial value is 040000h dst < 0C0000h; reset otherwise Set if an arithmetic overflow occurs: the initial value is 04000h dst < 0C000h; reset otherwise Set if an arithmetic overflow occurs: the initial value is 040h dst < 0C0h; reset otherwise
OSCOFF, CPUOFF, and GIE are not affected. The 20-bit value in R7 is multiplied by 2. RLAX.A R7 ; Shift left R7 (20-bit)
4-137
Extended Instructions
Rotate left through carry address-word Rotate left through carry word Rotate left through carry byte RLCX.A RLCX RLCX.B dst dst dst
or
RLCX.W
dst
Operation Emulation
C < MSB < MSB1 .... LSB+1 < LSB < C ADDCX.A ADDCX ADDCX.B dst,dst dst,dst dst,dst
Description
The destination operand is shifted left one position as shown in Figure 446. The carry bit (C) is shifted into the LSB and the MSB is shifted into the carry bit (C).
Status Bits
N: Z: C: V:
Set if result is negative, reset if positive Set if result is zero, reset otherwise Loaded from the MSB Set if an arithmetic overflow occurs the initial value is 040000h dst < 0C0000h; reset otherwise Set if an arithmetic overflow occurs: the initial value is 04000h dst < 0C000h; reset otherwise Set if an arithmetic overflow occurs: the initial value is 040h dst < 0C0h; reset otherwise
OSCOFF, CPUOFF, and GIE are not affected. The 20-bit value in R5 is shifted left one position. RLCX.A R5 ; (R5 x 2) + C > R5
Example
The RAM byte LEO is shifted left one position. PC is pointing to upper memory RLCX.B LEO ; RAM(LEO) x 2 + C > RAM(LEO)
4-138
Extended Instructions
Rotate Right Arithmetically the 20-bit CPU register content Rotate Right Arithmetically the 16-bit CPU register content RRAM.A RRAM.W #n,Rdst #n,Rdst 1n4 or RRAM #n,Rdst 1n4
Operation Description
MSB MSB MSB-1 . LSB+1 LSB C The destination operand is shifted right arithmetically by one, two, three, or four bit positions as shown in Figure 447. The MSB retains its value (sign). RRAM operates equal to a signed division by 2/4/8/16. The MSB is retained and shifted into MSB-1. The LSB+1 is shifted into the LSB, and the LSB is shifted into the carry bit C. The word instruction RRAM.W clears the bits Rdst.19:16. Note : This instruction does not use the extension word.
Status Bits
N:
Set if result is negative .A: Rdst.19 = 1, reset if Rdst.19 = 0 .W: Rdst.15 = 1, reset if Rdst.15 = 0 Set if result is zero, reset otherwise Loaded from the LSB (n = 1), LSB+1 (n = 2), LSB+2 (n = 3), or LSB+3 (n = 4) Reset
OSCOFF, CPUOFF, and GIE are not affected. The signed 20-bit number in R5 is shifted arithmetically right two positions.
RRAM.A Example
#2,R5
; R5/4 -> R5
The signed 20-bit value in R15 is multiplied by 0.75. (0.5 + 0.25) x R15 PUSHM.A RRAM.A ADDX.A RRAM.A #1,R15 #1,R15 @SP+,R15 #1,R15 ; Save extended R15 on stack ; R15 0.5 -> R15 ; R15 0.5 + R15 = 1.5 R15 -> R15 ; (1.5 R15) 0.5 = 0.75 R15 -> R15
19 C MSB
0 LSB
4-139
Extended Instructions
Rotate Right Arithmetically the 20-bit operand Rotate Right Arithmetically the 16-bit operand Rotate Right Arithmetically the 8-bit operand RRAX.A RRAX.W RRAX RRAX.B RRAX.A RRAX.W RRAX.B Rdst Rdst Rdst Rdst dst dst dst
or
RRAX dst
Operation Description
MSB MSB MSB-1 . ... LSB+1 LSB C Register Mode for the destination: the destination operand is shifted right by one bit position as shown in Figure 448. The MSB retains its value (sign). The word instruction RRAX.W clears the bits Rdst.19:16, the byte instruction RRAX.B clears the bits Rdst.19:8. The MSB retains its value (sign), the LSB is shifted into the carry bit. RRAX here operates equal to a signed division by 2. All other modes for the destination: the destination operand is shifted right arithmetically by one bit position as shown in Figure 449. The MSB retains its value (sign), the LSB is shifted into the carry bit. RRAX here operates equal to a signed division by 2. All addressing modes with the exception of the Immediate Mode are possible in the full memory.
Status Bits
N:
Z: C: V: Mode Bits
Set if result is negative .A: dst.19 = 1, reset if dst.19 = 0 .W: dst.15 = 1, reset if dst.15 = 0 .B: dst.7 = 1, reset if dst.7 = 0 Set if result is zero, reset otherwise Loaded from LSB Reset
4-140
Extended Instructions
Example
#4 R5
; R5/16 > R5
RRAX.B
&EDE
19 C
16
15 MSB
0 LSB
0000
19 C MSB
0 LSB
15 C MSB
0 LSB
31 0 19 C MSB
20 0 0 LSB
4-141
Extended Instructions
Rotate Right through carry the 20-bit CPU register content Rotate Right through carry the 16-bit CPU register content RRCM.A RRCM.W #n,Rdst #n,Rdst 1n4 or RRCM #n,Rdst 1n4
Operation Description
C MSB MSB-1 ... LSB+1 LSB C The destination operand is shifted right by one, two, three, or four bit positions as shown in Figure 450. The carry bit C is shifted into the MSB, the LSB is shifted into the carry bit. The word instruction RRCM.W clears the bits Rdst.19:16 Note : This instruction does not use the extension word.
Status Bits
N:
Set if result is negative .A: Rdst.19 = 1, reset if Rdst.19 = 0 .W: Rdst.15 = 1, reset if Rdst.15 = 0 Set if result is zero, reset otherwise Loaded from the LSB (n = 1), LSB+1 (n = 2), LSB+2 (n = 3) or LSB+3 (n = 4) Reset
OSCOFF, CPUOFF, and GIE are not affected. The address-word in R5 is shifted right by three positions. The MSB-2 is loaded with 1.
The word in R6 is shifted right by two positions. The MSB is loaded with the LSB. The MSB-1 is loaded with the contents of the carry flag. ; R6 = R6 2. R6.19:16 = 0
RRCM.W
#2,R6
19 C MSB
0 LSB
4-142
Extended Instructions
Rotate Right through carry the 20-bit operand Rotate Right through carry the 16-bit operand Rotate Right through carry the 8-bit operand RRCX.A RRCX.W RRCX RRCX.B RRCX.A RRCX.W RRCX.B Rdst Rdst Rdst Rdst dst dst dst
or
RRCX dst
Operation Description
C MSB MSB-1 ... LSB+1 LSB C Register Mode for the destination: the destination operand is shifted right by one bit position as shown in Figure 451. The word instruction RRCX.W clears the bits Rdst.19:16, the byte instruction RRCX.B clears the bits Rdst.19:8. The carry bit C is shifted into the MSB, the LSB is shifted into the carry bit. All other modes for the destination: the destination operand is shifted right by one bit position as shown in Figure 452. The carry bit C is shifted into the MSB, the LSB is shifted into the carry bit. All addressing modes with the exception of the Immediate Mode are possible in the full memory.
Status Bits
N:
Z: C: V: Mode Bits
Set if result is negative .A: dst.19 = 1, reset if dst.19 = 0 .W: dst.15 = 1, reset if dst.15 = 0 .B: dst.7 = 1, reset if dst.7 = 0 Set if result is zero, reset otherwise Loaded from LSB Reset
4-143
Extended Instructions
Example
The 20-bit operand at address EDE is shifted right by one position. The MSB is loaded with 1.
RPT RRCX.W
#12 R6
; R6 = R6 12. R6.19:16 = 0
19 C 0000
16
15 MSB
0 LSB
19 C MSB
0 LSB
15 C MSB
0 LSB
31 0 19 C MSB
20 0 0 LSB
4-144
Extended Instructions
Rotate Right Unsigned the 20-bit CPU register content Rotate Right Unsigned the 16-bit CPU register content RRUM.A RRUM.W 0 #n,Rdst #n,Rdst 1n4 or RRUM #n,Rdst 1n4
Operation Description
The destination operand is shifted right by one, two, three, or four bit positions as shown in Figure 453. Zero is shifted into the MSB, the LSB is shifted into the carry bit. RRUM works like an unsigned division by 2, 4, 8, or 16. The word instruction RRUM.W clears the bits Rdst.19:16. Note : This instruction does not use the extension word.
Status Bits
N:
Set if result is negative .A: Rdst.19 = 1, reset if Rdst.19 = 0 .W: Rdst.15 = 1, reset if Rdst.15 = 0 Set if result is zero, reset otherwise Loaded from the LSB (n = 1), LSB+1 (n = 2), LSB+2 (n = 3) or LSB+3 (n = 4) Reset
OSCOFF, CPUOFF, and GIE are not affected. The unsigned address-word in R5 is divided by 16. ; R5 = R5 4. R5/16
RRUM.A Example
#4,R5
The word in R6 is shifted right by one bit. The MSB R6.15 is loaded with 0.
RRUM.W
#1,R6
; R6 = R6/2. R6.19:15 = 0
0 19 C 0 MSB 0 LSB
4-145
Extended Instructions
Rotate Right unsigned the 20-bit operand Rotate Right unsigned the 16-bit operand Rotate Right unsigned the 8-bit operand RRUX.A RRUX.W RRUX RRUX.B Rdst Rdst Rdst Rdst
Operation Description
C=0 MSB MSB-1 ... LSB+1 LSB C RRUX is valid for register Mode only: the destination operand is shifted right by one bit position as shown in Figure 454. The word instruction RRUX.W clears the bits Rdst.19:16. The byte instruction RRUX.B clears the bits Rdst.19:8. Zero is shifted into the MSB, the LSB is shifted into the carry bit. N: Set if result is negative .A: dst.19 = 1, reset if dst.19 = 0 .W: dst.15 = 1, reset if dst.15 = 0 .B: dst.7 = 1, reset if dst.7 = 0 Set if result is zero, reset otherwise Loaded from LSB Reset
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. The word in R6 is shifted right by twelve positions.
RPT RRUX.W
#12 R6
; R6 = R6 12. R6.19:16 = 0
19 C 0 MSB
0 LSB
4-146
Extended Instructions
Subtract source and borrow/.NOT. carry from destination address-word Subtract source and borrow/.NOT. carry from destination word Subtract source and borrow/.NOT. carry from destination byte SBCX.A SBCX SBCX.B dst dst dst
or
SBCX.W dst
Operation
dst + 0FFFFFh + C > dst dst + 0FFFFh + C > dst dst + 0FFh + C > dst SUBCX.A SUBCX SUBCX.B #0,dst #0,dst #0,dst
Emulation
Description
The carry bit (C) is added to the destination operand minus one. The previous contents of the destination are lost. N: Set if result is negative, reset if positive Z: Set if result is zero, reset otherwise C: Set if there is a carry from the MSB of the result, reset otherwise. Set to 1 if no borrow, reset if borrow. V: Set if an arithmetic overflow occurs, reset otherwise. OSCOFF, CPUOFF, and GIE are not affected. The 8-bit counter pointed to by R13 is subtracted from a 16-bit counter pointed to by R12. SUBX.B SBCX.B Note: @R13,0(R12) 1(R12) Borrow Implementation . Borrow Yes No Carry bit 0 1 ; Subtract LSDs ; Subtract carry from MSD
Status Bits
4-147
Extended Instructions
Subtract source address-word from destination address-word Subtract source word from destination word Subtract source byte from destination byte SUBX.A SUBX SUBX.B src,dst src,dst or SUBX.W src,dst
src,dst
Operation Description
The source operand is subtracted from the destination operand. This is made by adding the 1s complement of the source + 1 to the destination. The source operand is not affected. The result is written to the destination operand. Both operands may be located in the full address space. N: Z: C: V: Set if result is negative (src > dst), reset if positive (src <= dst) Set if result is zero (src = dst), reset otherwise (src dst) Set if there is a carry from the MSB, reset otherwise Set if the subtraction of a negative source operand from a positive destination operand delivers a negative result, or if the subtraction of a positive source operand from a negative destination operand delivers a positive result, reset otherwise (no overflow).
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. A 20-bit constant 87654h is subtracted from EDE (LSBs) and EDE+2 (MSBs).
SUBX.A Example
A table word pointed to by R5 (20-bit address) is subtracted from R7. Jump to label TONI if R7 contains zero after the instruction. R5 is auto-incremented by 2. R7.19:16 = 0
@R5+,R7 TONI
; Subtract table number from R7. R5 + 2 ; R7 = @R5 (before subtraction) ; R7 <> @R5 (before subtraction)
Byte CNT is subtracted from the byte R12 points to in the full address space. Address of CNT is within PC 512 K.
SUBX.B
CNT,0(R12)
Note: Use SUBA for the following two cases for better density and execution. SUBX.A Rsrc,Rdst or SUBX.A #imm20,Rdst
4-148
Extended Instructions
Subtract source address-word with carry from destination address-word Subtract source word with carry from destination word Subtract source byte with carry from destination byte SUBCX.A src,dst SUBCX src,dst or SUBCX.W src,dst SUBCX.B src,dst (.not. src) + C + dst dst or dst (src 1) + C dst The source operand is subtracted from the destination operand. This is made by adding the 1s complement of the source + carry to the destination. The source operand is not affected, the result is written to the destination operand. Both operands may be located in the full address space. N: Z: C: V: Set if result is negative (MSB = 1), reset if positive (MSB = 0) Set if result is zero, reset otherwise Set if there is a carry from the MSB, reset otherwise Set if the subtraction of a negative source operand from a positive destination operand delivers a negative result, or if the subtraction of a positive source operand from a negative destination operand delivers a positive result, reset otherwise (no overflow).
Operation Description
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. A 20-bit constant 87654h is subtracted from R5 with the carry from the previous instruction.
A 48-bit number (3 words) pointed to by R5 (20-bit address) is subtracted from a 48-bit counter in RAM, pointed to by R7. R5 auto-increments to point to the next 48-bit number.
SUBX.W
@R5+,0(R7)
Byte CNT is subtracted from the byte, R12 points to. The carry of the previous instruction is used. 20-bit addresses.
SUBCX.B &CNT,0(R12)
4-149
Extended Instructions
Swap bytes of lower word Swap bytes of word SWPBX.A SWPBX.W dst dst
or
SWPBX
dst
Operation Description
dst.15:8 dst.7:0 Register Mode: Rn.15:8 are swapped with Rn.7:0. When the .A extension is used, Rn.19:16 are unchanged. When the .W extension is used, Rn.19:16 are cleared. Other Modes: When the .A extension is used, bits 31:20 of the destination address are cleared, bits 19:16 are left unchanged, and bits 15:8 are swapped with bits 7:0. When the .W extension is used, bits 15:8 are swapped with bits 7:0 of the addressed word. Not affected OSCOFF, CPUOFF, and GIE are not affected. Exchange the bytes of RAM address-word EDE.
#23456h,&EDE EDE
MOVA SWPBX.W
#23456h,R5 R5
7 Low Byte
4-150
Extended Instructions
15 High Byte
7 Low Byte
After SWPBX.A 31 20 19 0 X
16
15 Low Byte
7 High Byte
7 Low Byte
7 Low Byte
4-151
Extended Instructions
Extend sign of lower byte to address-word Extend sign of lower byte to word SXTX.A SXTX.W dst dst
or
SXTX dst
Operation Description
dst.7 dst.15:8, Rdst.7 Rdst.19:8 (Register Mode) Register Mode: The sign of the low byte of the operand (Rdst.7) is extended into the bits Rdst.19:8. Other Modes: SXTX.A: the sign of the low byte of the operand (dst.7) is extended into dst.19:8. The bits dst.31:20 are cleared. SXTX[.W]: the sign of the low byte of the operand (dst.7) is extended into dst.15:8.
Status Bits
N: Z: C: V:
Set if result is negative, reset otherwise Set if result is zero, reset otherwise Set if result is not zero, reset otherwise (C = .not.Z) Reset
OSCOFF, CPUOFF, and GIE are not affected. The signed 8-bit data in EDE.7:0 is sign extended to 20 bits: EDE.19:8. Bits 31:20 located in EDE+2 are cleared.
SXTX.A
&EDE
4-152
Extended Instructions
SXTX[.W] dst 15 8 7 S 6 0
4-153
Extended Instructions
Test destination address-word Test destination word Test destination byte TSTX.A TSTX TST.B dst dst dst
or TST.W dst
Operation
dst + 0FFFFFh + 1 dst + 0FFFFh + 1 dst + 0FFh + 1 CMPX.A CMPX CMPX.B #0,dst #0,dst #0,dst
Emulation
Description
The destination operand is compared with zero. The status bits are set according to the result. The destination is not affected. N: Z: C: V: Set if destination is negative, reset if positive Set if destination contains zero, reset otherwise Set Reset
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. RAM byte LEO is tested; PC is pointing to upper memory. If it is negative, continue at LEONEG; if it is positive but not zero, continue at LEOPOS. TSTX.B JN JZ ...... ...... ...... LEO LEONEG LEOZERO ; Test LEO ; LEO is negative ; LEO is zero ; LEO is positive but not zero ; LEO is negative ; LEO is zero
4-154
Extended Instructions
Exclusive OR source address-word with destination address-word Exclusive OR source word with destination word Exclusive OR source byte with destination byte XORX.A XORX XORX.B src,dst src,dst or XORX.W src,dst
src,dst
Operation Description
src .xor. dst dst The source and destination operands are exclusively ORed. The result is placed into the destination. The source operand is not affected. The previous contents of the destination are lost. Both operands may be located in the full address space. N: Z: C: V: Set if result is negative (MSB = 1), reset if positive (MSB = 0) Set if result is zero, reset otherwise Set if result is not zero, reset otherwise (carry = .not. Zero) Set if both operands are negative (before execution), reset otherwise.
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Toggle bits in address-word CNTR (20-bit data) with information in address-word TONI (20-bit address).
XORX.A Example
TONI,&CNTR
XORX.W Example
@R5,R6
Reset to zero those bits in the low byte of R7 that are different from the bits in byte EDE (20-bit address).
XORX.B INV.B
EDE,R7 R7
4-155
Address Instructions
4.6.4
Address Instructions
MSP430X address instructions are instructions that support 20-bit operands but have restricted addressing modes. The addressing modes are restricted to the Register mode and the Immediate mode, except for the MOVA instruction. Restricting the addressing modes removes the need for the additional extension-word op-code improving code density and execution time. The MSP430X address instructions are listed and described in the following pages.
4-156
Address Instructions
ADDA Syntax
Add 20-bit source to a 20-bit destination register ADDA ADDA Rsrc,Rdst #imm20,Rdst
Operation Description
src + Rdst Rdst The 20-bit source operand is added to the 20-bit destination CPU register. The previous contents of the destination are lost. The source operand is not affected. N: Z: C: V: Set if result is negative (Rdst.19 = 1), reset if positive (Rdst.19 = 0) Set if result is zero, reset otherwise Set if there is a carry from the 20-bit result, reset otherwise Set if the result of two positive operands is negative, or if the result of two negative numbers is positive, reset otherwise.
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. R5 is increased by 0A4320h. The jump to TONI is performed if a carry occurs.
ADDA JC ...
#0A4320h,R5 TONI
4-157
Address Instructions
dst PC MOVA dst,PC An unconditional branch is taken to a 20-bit address anywhere in the full address space. All seven source addressing modes can be used. The branch instruction is an address-word instruction. If the destination address is contained in a memory location X, it is contained in two ascending words: X (LSBs) and (X + 2) (MSBs). N: Z: C: V: Not affected Not affected Not affected Not affected
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Examples for all addressing modes are given. Immediate Mode: Branch to label EDE located anywhere in the 20-bit address space or branch directly to address.
BRA BRA
#EDE #01AA04h
; MOVA
#imm20,PC
Symbolic Mode: Branch to the 20-bit address contained in addresses EXEC (LSBs) and EXEC+2 (MSBs). EXEC is located at the address (PC + X) where X is within 32 K. Indirect addressing.
BRA
EXEC
; MOVA
z16(PC),PC
Note: if the 16-bit index is not sufficient, a 20-bit index may be used with the following instruction.
MOVX.A
EXEC,PC
Absolute Mode: Branch to the 20-bit address contained in absolute addresses EXEC (LSBs) and EXEC+2 (MSBs). Indirect addressing.
BRA
&EXEC
; MOVA
&abs20,PC
Register Mode: Branch to the 20-bit address contained in register R5. Indirect R5.
BRA
R5
; MOVA
R5,PC
4-158
Address Instructions
Indirect Mode: Branch to the 20-bit address contained in the word pointed to by register R5 (LSBs). The MSBs have the address (R5 + 2). Indirect, indirect R5.
BRA
@R5
; MOVA
@R5,PC
Indirect, Auto-Increment Mode: Branch to the 20-bit address contained in the words pointed to by register R5 and increment the address in R5 afterwards by 4. The next time the S/W flow uses R5 as a pointer, it can alter the program execution due to access to the next address in the table pointed to by R5. Indirect, indirect R5.
BRA
@R5+
; MOVA
@R5+,PC. R5 + 4
Indexed Mode: Branch to the 20-bit address contained in the address pointed to by register (R5 + X) (e.g. a table with addresses starting at X). (R5 + X) points to the LSBs, (R5 + X + 2) points to the MSBs of the address. X is within R5 32 K. Indirect, indirect (R5 + X).
BRA
X(R5)
; MOVA
z16(R5),PC
Note: if the 16-bit index is not sufficient, a 20-bit index X may be used with the following instruction:
MOVX.A
X(R5),PC
4-159
Address Instructions
Call a Subroutine CALLA dst SP 2 PC.19:16 SP 2 PC.15:0 tmp dst tmp 20-bit dst is evaluated and stored SP @SP updated PC with return address to TOS (MSBs) SP @SP updated PC to TOS (LSBs) PC saved 20-bit dst to PC
Description
A subroutine call is made to a 20-bit address anywhere in the full address space. All seven source addressing modes can be used. The call instruction is an address-word instruction. If the destination address is contained in a memory location X, it is contained in two ascending words: X (LSBs) and (X + 2) (MSBs). Two words on the stack are needed for the return address. The return is made with the instruction RETA. N: Z: C: V: Not affected Not affected Not affected Not affected
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Examples for all addressing modes are given. Immediate Mode: Call a subroutine at label EXEC or call directly an address.
CALLA CALLA
#EXEC #01AA04h
Symbolic Mode: Call a subroutine at the 20-bit address contained in addresses EXEC (LSBs) and EXEC+2 (MSBs). EXEC is located at the address (PC + X) where X is within 32 K. Indirect addressing.
CALLA
EXEC
Absolute Mode: Call a subroutine at the 20-bit address contained in absolute addresses EXEC (LSBs) and EXEC+2 (MSBs). Indirect addressing.
CALLA
&EXEC
Register Mode: Call a subroutine at the 20-bit address contained in register R5. Indirect R5.
CALLA
R5
4-160
Address Instructions
Indirect Mode: Call a subroutine at the 20-bit address contained in the word pointed to by register R5 (LSBs). The MSBs have the address (R5 + 2). Indirect, indirect R5.
CALLA
@R5
Indirect, Auto-Increment Mode: Call a subroutine at the 20-bit address contained in the words pointed to by register R5 and increment the 20-bit address in R5 afterwards by 4. The next time the S/W flow uses R5 as a pointer, it can alter the program execution due to access to the next word address in the table pointed to by R5. Indirect, indirect R5.
CALLA
@R5+
Indexed Mode: Call a subroutine at the 20-bit address contained in the address pointed to by register (R5 + X) e.g. a table with addresses starting at X. (R5 + X) points to the LSBs, (R5 + X + 2) points to the MSBs of the word address. X is within R5 32 K. Indirect, indirect (R5 + X).
CALLA
X(R5)
4-161
Address Instructions
Clear 20-bit destination register CLRA 0 > Rdst MOVA #0,Rdst Rdst
The destination register is cleared. Status bits are not affected. The 20-bit value in R10 is cleared. CLRA R10 ; 0 > R10
4-162
Address Instructions
CMPA Syntax
Compare the 20-bit source with a 20-bit destination register CMPA CMPA Rsrc,Rdst #imm20,Rdst or Rdst src
Operation Description
The 20-bit source operand is subtracted from the 20-bit destination CPU register. This is made by adding the 1s complement of the source + 1 to the destination register. The result affects only the status bits. N: Z: C: V: Set if result is negative (src > dst), reset if positive (src <= dst) Set if result is zero (src = dst), reset otherwise (src dst) Set if there is a carry from the MSB, reset otherwise Set if the subtraction of a negative source operand from a positive destination operand delivers a negative result, or if the subtraction of a positive source operand from a negative destination operand delivers a positive result, reset otherwise (no overflow).
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. A 20-bit immediate operand and R6 are compared. If they are equal the program continues at label EQUAL.
#12345h,R6 EQUAL
The 20-bit values in R5 and R6 are compared. If R5 is greater than (signed) or equal to R6, the program continues at label GRE.
R6,R5 GRE
4-163
Address Instructions
The destination register is decremented by two. The original contents are lost. N: Z: C: V: Set if result is negative, reset if positive Set if Rdst contained 2, reset otherwise Reset if Rdst contained 0 or 1, set otherwise Set if an arithmetic overflow occurs, otherwise reset.
OSCOFF, CPUOFF, and GIE are not affected. The 20-bit value in R5 is decremented by 2 DECDA R5 ; Decrement R5 by two
4-164
Address Instructions
The destination register is incremented by two. The original contents are lost. N: Set if result is negative, reset if positive Z: Set if Rdst contained 0FFFFEh, reset otherwise Set if Rdst contained 0FFFEh, reset otherwise Set if Rdst contained 0FEh, reset otherwise C: Set if Rdst contained 0FFFFEh or 0FFFFFh, reset otherwise Set if Rdst contained 0FFFEh or 0FFFFh, reset otherwise Set if Rdst contained 0FEh or 0FFh, reset otherwise V: Set if Rdst contained 07FFFEh or 07FFFFh, reset otherwise Set if Rdst contained 07FFEh or 07FFFh, reset otherwise Set if Rdst contained 07Eh or 07Fh, reset otherwise OSCOFF, CPUOFF, and GIE are not affected. The 20-bit value in R5 is incremented by 2 INCDA R5 ; Increment R5 by two
4-165
Address Instructions
MOVA Syntax
Move the 20-bit source to the 20-bit destination MOVA MOVA MOVA MOVA MOVA MOVA MOVA MOVA MOVA src Rsrc Rsrc,Rdst #imm20,Rdst z16(Rsrc),Rdst EDE,Rdst &abs20,Rdst @Rsrc,Rdst @Rsrc+,Rdst Rsrc,z16(Rdst) Rsrc,&abs20 Rdst dst
Operation
Description
The 20-bit source operand is moved to the 20-bit destination. The source operand is not affected. The previous content of the destination is lost. Not affected OSCOFF, CPUOFF, and GIE are not affected. Copy 20-bit value in R9 to R8.
MOVA
R9,R8
; R9 -> R8
MOVA
#12345h,R12
Copy 20-bit value addressed by (R9 + 100h) to R8. Source operand in addresses (R9 + 100h) LSBs and (R9 + 102h) MSBs ; Index: 32 K. 2 words transferred
MOVA
100h(R9),R8
Move 20-bit value in 20-bit absolute addresses EDE (LSBs) and EDE+2 (MSBs) to R12.
MOVA
&EDE,R12
Move 20-bit value in 20-bit addresses EDE (LSBs) and EDE+2 (MSBs) to R12. PC index 32 K.
MOVA
EDE,R12
Copy 20-bit value R9 points to (20 bit address) to R8. Source operand in addresses @R9 LSBs and @(R9 + 2) MSBs.
MOVA
@R9,R8
4-166
Address Instructions
Copy 20-bit value R9 points to (20 bit address) to R8. R9 is incremented by four afterwards. Source operand in addresses @R9 LSBs and @(R9 + 2) MSBs.
MOVA
@R9+,R8
Copy 20-bit value in R8 to destination addressed by (R9 + 100h). Destination operand in addresses @(R9 + 100h) LSBs and @(R9 + 102h) MSBs.
MOVA
R8,100h(R9)
Move 20-bit value in R13 to 20-bit absolute addresses EDE (LSBs) and EDE+2 (MSBs).
MOVA
R13,&EDE
Move 20-bit value in R13 to 20-bit addresses EDE (LSBs) and EDE+2 (MSBs). PC index 32 K.
MOVA
R13,EDE
4-167
Address Instructions
Return from subroutine RETA @SP SP + 2 @SP SP + 2 MOVA PC.15:0 SP PC.19:16 SP @SP+,PC LSBs (15:0) of saved PC to PC.15:0 MSBs (19:16) of saved PC to PC.19:16
Emulation Description
The 20-bit return address information, pushed onto the stack by a CALLA instruction, is restored to the program counter PC. The program continues at the address following the subroutine call. The status register bits SR.11:0 are not affected. This allows the transfer of information with these bits. N: Z: C: V: Not affected Not affected Not affected Not affected
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. Call a subroutine SUBR from anywhere in the 20-bit address space and return to the address after the CALLA.
CALLA ...
#SUBR
; Call subroutine starting at SUBR ; Return by RETA to here ; Save R14 and R13 (20 bit data) ; Subroutine code ; Restore R13 and R14 (20 bit data) ; Return (to full address space)
4-168
Address Instructions
Emulation Description
The destination register is compared with zero. The status bits are set according to the result. The destination register is not affected. N: Z: C: V: Set if destination register is negative, reset if positive Set if destination register contains zero, reset otherwise Set Reset
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. The 20-bit value in R7 is tested. If it is negative, continue at R7NEG; if it is positive but not zero, continue at R7POS. TSTA JN JZ ...... ...... ...... R7 R7NEG R7ZERO ; Test R7 ; R7 is negative ; R7 is zero ; R7 is positive but not zero ; R7 is negative ; R7 is zero
4-169
Address Instructions
SUBA Syntax
Subtract 20-bit source from 20-bit destination register SUBA SUBA Rsrc,Rdst #imm20,Rdst or Rdst src Rdst
Operation Description
The 20-bit source operand is subtracted from the 20-bit destination register. This is made by adding the 1s complement of the source + 1 to the destination. The result is written to the destination register, the source is not affected. N: Z: C: V: Set if result is negative (src > dst), reset if positive (src <= dst) Set if result is zero (src = dst), reset otherwise (src dst) Set if there is a carry from the MSB (Rdst.19), reset otherwise Set if the subtraction of a negative source operand from a positive destination operand delivers a negative result, or if the subtraction of a positive source operand from a negative destination operand delivers a positive result, reset otherwise (no overflow).
Status Bits
OSCOFF, CPUOFF, and GIE are not affected. The 20-bit value in R5 is subtracted from R6. If a carry occurs, the program continues at label TONI.
SUBA JC ...
R5,R6 TONI
4-170
Chapter 5
FLL+
Clock Module
The FLL+ clock module provides the clocks for MSP430x4xx devices. This chapter discusses the FLL+ clock module. The FLL+ clock module is implemented in all MSP430x4xx devices.
Topic
5.1 5.2 5.3
Page
FLL+ Clock Module Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 FLL+ Clock Module Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8 FLL+ Clock Module Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15
5-1
either with low-frequency 32768-Hz watch crystals or standard crystals or resonators in the 450-kHz to 8-MHz range. See the device-specific data sheet for details.
- XT2CLK: Optional high-frequency oscillator that can be used with
standard crystals, resonators, or external clock sources in the 450-kHz to 8-MHz range. In MSP430F47x3/4 and MSP430F471xx devices the upper limit is 16 MHz. See the device-specific data sheet for details.
- DCOCLK: Internal digitally controlled oscillator (DCO) with RC-type
typical frequency. Four clock signals are available from the FLL+ module:
- ACLK: Auxiliary clock. The ACLK is software selectable as LFXT1CLK or
VLOCLK as clock source. ACLK is software selectable for individual peripheral modules.
- ACLK/n: Buffered output of the ACLK. The ACLK/n is ACLK divided by
VLOCLK, XT2CLK (if available), or DCOCLK. MCLK can be divided by 1, 2, 4, or 8 within the FLL block. MCLK is used by the CPU and system.
- SMCLK: Sub-main clock. SMCLK is software selectable as XT2CLK (if
5-2
The block diagrams of the FLL+ clock module are shown in Figure 51 to Figure 54.
- Figure 51 shows the block diagram for MSP430x43x, MSP430x44x,
devices.
- Figure 53
5-3
Figure 51. MSP430x43x, MSP430x44x, MSP430FG47x, MSP430F47x, and MSP430x461x Frequency-Locked Loop
FLL_DIVx
ACLK/n
ACLK
XIN
XOUT
SCG1
FNx 4
11 11
off
DC Generator
FLLDx
Divider /1/2/4/8
fDCO fDCO/D
1 0
SELS SMCLKOFF 0 1
0 1 SMCLK
XT20FF XT2IN
XT2OUT
XT2 Oscillator
5-4
ACLK/n
ACLK
XIN
XOUT
CPUOFF
FLLDx DCOPLUS
Divider /1/2/4/8
fDCO fDCO/D
1 0 SMCLK
5-5
ACLK/n
ACLK
XIN
XOUT
SCG1
FNx 4
11 11
off
DC Generator
FLLDx
Divider /1/2/4/8
fDCO fDCO/D
1 0
SELS SMCLKOFF 0 1
0 1 SMCLK
XT2OUT
5-6
ACLK/n ACLK
XIN
XOUT
0V
00 01
CPUOFF
XCAPxPF
0 10 1 11 MCLK
/(N+1)
SCG1
off
DC Generator
Divider /1/2/4/8
SMCLKOFF
5-7
5.2.1
capability
- Clock stability over operating temperature and supply voltage
The FLL+ clock module addresses the above conflicting requirements by allowing the user to select from the three available clock signals: ACLK, MCLK, and SMCLK. For optimal low-power performance, the ACLK can be configured to oscillate with a low-power 32786-Hz watch-crystal, providing a stable time base for the system and low-power standby operation. The MCLK can be configured to operate from the on-chip DCO, stabilized by the FLL, and can activate when requested by interrupt events. The digital frequency-locked loop provides decreased start-time and stabilization delay over an analog phase-locked loop. A phase-locked loop takes hundreds or thousands of clock cycles to start and stabilize. The FLL starts immediately at its previous setting.
5-8
5.2.2
5.2.3
LFXT1 Oscillator
The LFXT1 oscillator supports ultralow-current consumption using a 32,768-Hz watch crystal in LF mode (XTS_FLL = 0). A watch crystal connects to XIN and XOUT without any external components. The LFXT1 oscillator supports high-speed crystals or resonators when in HF mode (XTS_FLL = 1). The high-speed crystal or resonator connects to XIN and XOUT. LFXT1 may be used with an external clock signal on the XIN pin when XTS_FLL = 1. The input frequency range is ~1 Hz to 8 MHz. When the input frequency is below 450 kHz, the XT1OF bit may be set to prevent the CPU from being clocked from the external frequency. The software-selectable XCAPxPF bits configure the internally provided load capacitance for the LFXT1 crystal. The internal pin capacitance plus the parasitic 2-pF pin capacitance combine serially to form the load capacitance. The load capacitance can be selected as 1, 6, 8, or 10 pF. Additional external capacitors can be added if necessary. Software can disable LFXT1 by setting OSCOFF if this signal does not source MCLK (SELM 3 or CPUOFF = 1 ). Note: LFXT1 Oscillator Characteristics
Low-frequency crystals often require hundreds of milliseconds to start up, depending on the crystal. Ultralow-power oscillators such as the LFXT1 in LF mode should be guarded from noise coupling from other sources. The crystal should be placed as close as possible to the MSP430 with the crystal housing grounded and the crystal traces guarded with ground traces. The default value of XCAPxPF is 0, providing a crystal load capacitance of ~1 pF. Reliable crystal operation may not be achieved unless the crystal is provided with the proper load capacitance, either by selection of XCAPxPF values or by external capacitors.
5-9
5.2.4
XT2 Oscillator
Some devices have a second crystal oscillator, XT2. XT2 sources XT2CLK and its characteristics are identical to LFXT1 in HF mode, except XT2 does not have internal load capacitors. The required load capacitance for the high-frequency crystal or resonator must be provided externally. The XT2OFF bit disables the XT2 oscillator if XT2CLK is unused for MCLK (SELMx 2 or CPUOFF = 1) and SMCLK (SELS = 0 or SMCLKOFF = 1). XT2 may be used with external clock signals on the XT2IN pin. When used with an external signal, the external frequency must meet the data sheet parameters for XT2. If there is only one crystal in the system it should be connected to LFXT1. Using only XT2 causes the LFOF fault flag to remain set, not allowing for the OFIFG to ever be cleared.
5-10
5.2.5
5.2.6
5-11
5.2.7
DCO Modulator
The modulator mixes two adjacent DCO frequencies to produce an intermediate effective frequency and spread the clock energy, reducing electromagnetic interference (EMI). The modulator mixes the two adjacent frequencies across 32 DCOCLK clock cycles. The error of the effective frequency is zero every 32 DCOCLK cycles and does not accumulate. The modulator settings and DCO control are automatically controlled by the FLL hardware. Figure 55 illustrates the modulator operation.
5-12
5.2.8
5.2.9
5-13
The crystal oscillator fault bits LFOF, XT1OF and XT2OF are set if the corresponding crystal oscillator is turned on and not operating properly. The fault bits remain set as long as the fault condition exists and are automatically cleared if the enabled oscillators function normally. During a LFXT1crystal failure, no ACLK signal is generated and the FLL+ continues to count down to zero in an attempt to lock ACLK and MCLK/(D[N+1]). The DCO tap moves to the lowest position (SCFI1.7 to SCFI1.3 are cleared) and the DCOF is set. A DCOF is also generated if the N-multiplier value is set too high for the selected DCO frequency range resulting the DCO tap to move to the highest position (SCFI1.7 to SCFI1.3 are set). The DCOF is cleared automatically if the DCO tap is not in the lowest or the highest positions. The OFIFG oscillator-fault interrupt flag is set and latched at POR or when an oscillator fault (LFOF, XT1OF, XT2OF, or DCOF set) is detected. When OFIFG is set, MCLK is sourced from the DCO, and if OFIE is set, the OFIFG requests an NMI interrupt. When the interrupt is granted, the OFIE is reset automatically. The OFIFG flag must be cleared by software. The source of the fault can be identified by checking the individual fault bits. When OFIFG is set and MCLK is automatically switched to the DCO, the SELMx bit settings are not changed. This condition must be handled by user software. Note: DCO Active During Oscillator Fault
DCOCLK is active even at the lowest DCO tap. The clock signal is available for the CPU to execute code and service an NMI during an oscillator fault.
5-14
Short Form SCFQCTL SCFI0 SCFI1 FLL_CTL0 FLL_CTL1 FLL_CTL2 IE1 IFG1
Register Type Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write
Initial State 01Fh with PUC 040h with PUC Reset with PUC 003h with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC
5-15
SCFQ_M
Bit 7
Modulation. This enables or disables modulation. 0 Modulation enabled 1 Modulation disabled Multiplier. These bits set the multiplier value for the DCO. N must be > 0 or unpredictable operation results. When DCOPLUS = 0: fDCOCLK = (N + 1) fcrystal When DCOPLUS = 1: fDCOCLK = D x (N + 1) fcrystal
Bits 6-0
FLLDx
Bits 7-6
FLL+ loop divider. These bits divide fDCOCLK in the FLL+ feedback loop. This results in an additional multiplier for the multiplier bits. See also multiplier bits. 00 /1 01 /2 10 /4 11 /8 DCO range control. These bits select the fDCO operating range. 0000 0.65 to 6.1 MHz 0001 1.3 to 12.1 MHz 001x 2 to 17.9 MHz 01xx 2.8 to 26.6 MHz 1xxx 4.2 to 46 MHz Least significant modulator bits. Bit 0 is the modulator LSB. These bits affect the modulator pattern. All MODx bits are modified automatically by the FLL+.
FN_x
Bits 5-2
MODx
Bits 10
5-16
DCOx MODx
These bits select the DCO tap and are modified automatically by the FLL+. Most significant modulator bits. Bit 2 is the modulator MSB. These bits affect the modulator pattern. All MODx bits are modified automatically by the FLL+.
5-17
6 XTS_FLL rw0
5 XCAPxPF rw0
3 XT2OF r0
2 XT1OF r0
1 LFOF r(1)
0 DCOF r1
rw0
DCOPLUS
Bit 7
DCO output pre-divider. This bit selects if the DCO output is pre-divided before sourcing MCLK or SMCLK. The division rate is selected with the FLL_D bits 0 DCO output is divided 1 DCO output is not divided LFTX1 mode select 0 Low frequency mode 1 High frequency mode Oscillator capacitor selection. These bits select the effective capacitance seen by the LFXT1 crystal or resonator. Should be set to 00 if the high-frequency mode is selected for LFXT1 with XTS_FLL = 1. 00 ~1 pF 01 ~6 pF 10 ~8 pF 11 ~10 pF XT2 oscillator fault. Not present in MSP430x41x, and MSP430x42x devices. 0 No fault condition present 1 Fault condition present LFXT1 high-frequency oscillator fault 0 No fault condition present 1 Fault condition present LFXT1 low-frequency oscillator fault 0 No fault condition present 1 Fault condition present DCO oscillator fault 0 No fault condition present 1 Fault condition present
XTS_FLL
Bit 6
XCAPxPF
Bits 54
XT2OF
Bit 3
XT1OF
Bit 2
LFOF
Bit 1
DCOF
Bit 0
5-18
5 XT2OFF rw(1)
4 SELMx rw(0)
2 SELS
1 FLL_DIVx rw(0)
rw(0)
rw(0)
rw(0)
Not present in MSP430x41x, MSP430x42x devices except MSP430F41x2. Only supported by MSP430xG46x, MSP430FG47x, MSP430F47x, MSP430x47x3/4, and MSP430F471xx devices. Otherwise unused.
LFXT1DIG
Bit 7
Select digital external clock source. This bit enables the input of an external digital clock signal on XIN in low-frequency mode (XTS_FLL = 0). Only supported in MSP430xG46x, MSP430FG47x, MSP430F47x, MSP430x47x3/4, and MSP430F471xx devices. 0 Crystal input selected 1 Digital clock input selected SMCLK off. This bit turns off SMCLK. Not present in MSP430x41x and MSPx42x devices. 0 SMCLK is on 1 SMCLK is off XT2 off. This bit turns off the XT2 oscillator. Not present in MSP430x41x and MSPx42x devices. 0 XT2 is on 1 XT2 is off if it is not used for MCLK or SMCLK Select MCLK. These bits select the MCLK source. Not present in MSP430x41x and MSP430x42x devices except MSP430F41x2. 00 DCOCLK 01 DCOCLK 10 XT2CLK 11 LFXT1CLK In the MSP430F41x2 devices: 00 DCOCLK 01 DCOCLK 10 LFXT1CLK or VLO 11 LFXT1CLK or VLO Select SMCLK. This bit selects the SMCLK source. Not present in MSP430x41x and MSP430x42x devices. 0 DCOCLK 1 XT2CLK ACLK divider 00 /1 01 /2 10 /4 11 /8
SMCLKOFF
Bit 6
XT2OFF
Bit 5
SELMx
Bits 43
SELS
Bit 2
FLL_DIVx
Bits 10
5-19
XT2Sx
Bits 7-6
XT2 range select. These bits select the frequency range for XT2. 00 0.4 to 1-MHz crystal or resonator 01 1 to 3-MHz crystal or resonator 10 3 to 16-MHz crystal or resonator 11 Digital external 0.4 to 16-MHz clock source Reserved.
Reserved
Bits 5-0
Reserved LFXT1Sx
Reserved. Lowfrequency clock select and LFXT1 range select. These bits select between LFXT1 and VLO when XTS_FLL = 0. When XTS_FLL = 0: 00 32768-Hz crystal on LFXT1 01 Reserved 10 VLOCLK 11 Digital external clock source When XTS_FLL = 1: 00 Reserved 01 Reserved 10 Reserved 11 Reserved Reserved.
Reserved
Bits 3-0
5-20
Bits 7-2
OFIE
These bits may be used by other modules. See device-specific data sheet. Oscillator fault interrupt enable. This bit enables the OFIFG interrupt. Because other bits in IE1 may be used for other modules, it is recommended to set or clear this bit using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions. 0 Interrupt not enabled 1 Interrupt enabled This bit may be used by other modules. See device-specific data sheet.
Bit 1
Bits 0
5-21
Bits 7-2
OFIFG
These bits may be used by other modules. See device-specific data sheet. Oscillator fault interrupt flag. Because other bits in IFG1 may be used for other modules, it is recommended to set or clear this bit using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions. 0 No interrupt pending 1 Interrupt pending This bit may be used by other modules. See device-specific data sheet.
Bit 1
Bits 0
5-22
Chapter 6
Flash
Memory Controller
This chapter describes the operation of the MSP430 flash memory controller.
Topic
6.1 6.2 6.3 6.4
Page
Flash Memory Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 Flash Memory Segmentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 Flash Memory Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6 Flash Memory Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-21
6-1
MSP430F47x, MSP430F47x3/4, and MSP430F471xx devices only (see the device-specific data sheet). The block diagram of the flash memory and controller is shown in Figure 61. Note: Minimum VCC During Flash Write or Erase
The minimum VCC voltage during a flash write or erase operation is between 2.2 V and 2.7 V (see the device-specific data sheet). If VCC falls below the minimum VCC during a write or erase, the result of the write or erase is unpredictable.
6-2
MAB
FCTL1
FCTL2
FCTL3
Timing Generator
6-3
F000h 10FFh
SegmentA SegmentB
1000h
6-4
; ; ; ;
; Lock SegmentA BIT #LOCKA,&FCTL3 JNZ SEGALOCKED MOV #FWKEY+LOCKA,&FCTL3 SEGA_LOCKED ; SegmentA is locked
; ; ; ;
6-5
Reading or writing to flash memory while it is being programmed or erased is prohibited. If CPU execution is required during the write or erase, the code to be executed must be in RAM. Any flash update can be initiated from within flash memory or RAM.
6.3.1
BUSY
WAIT
The flash timing generator can be sourced from ACLK, SMCLK, or MCLK. The selected clock source should be divided using the FNx bits to meet the frequency requirements for fFTG. If the fFTG frequency deviates from the specification during the write or erase operation, the result of the write or erase may be unpredictable, or the flash memory may be stressed above the limits of reliable operation.
6-6
6.3.2
Any erase is initiated by a dummy write into the address range to be erased. The dummy write starts the flash timing generator and the erase operation. Figure 64 shows the erase cycle timing. The BUSY bit is set immediately after the dummy write and remains set throughout the erase cycle. BUSY, GMERAS (when present), MERAS, and ERASE are automatically cleared when the cycle completes. The erase cycle timing is not dependent on the amount of flash memory present on a device. Erase cycle times are device-specific (see the device-specific data sheet).
6-7
BUSY
tMass Erase, tSeg Erase, or tGlobal Mass Erase (see device-specific data sheet)
A dummy write to an address not in the range to be erased does not start the erase cycle, does not affect the flash memory, and is not flagged in any way. This errant dummy write is ignored.
6-8
Disable watchdog
Dummy write
; Segment Erase from flash. 514 kHz < SMCLK < 952 kHz ; Assumes ACCVIE = NMIIE = OFIE = 0. MOV #WDTPW+WDTHOLD,&WDTCTL ; Disable WDT MOV #FWKEY+FSSEL1+FN0,&FCTL2 ; SMCLK/2 MOV #FWKEY,&FCTL3 ; Clear LOCK MOV #FWKEY+ERASE,&FCTL1 ; Enable segment erase CLR &0FC10h ; Dummy write, erase S1 MOV #FWKEY+LOCK,&FCTL3 ; Done, set LOCK ... ; Re-enable WDT?
6-9
Disable watchdog
Dummy write
yes BUSY = 1
; Segment Erase from RAM. 514 kHz ; Assumes ACCVIE = NMIIE = OFIE = MOV #WDTPW+WDTHOLD,&WDTCTL L1 BIT #BUSY,&FCTL3 JNZ L1 MOV #FWKEY+FSSEL1+FN0,&FCTL2 MOV #FWKEY,&FCTL3 MOV #FWKEY+ERASE,&FCTL1 CLR &0FC10h L2 BIT #BUSY,&FCTL3 JNZ L2 MOV #FWKEY+LOCK,&FCTL3 ...
< SMCLK < 952 kHz 0. ; Disable WDT ; Test BUSY ; Loop while busy ; SMCLK/2 ; Clear LOCK ; Enable erase ; Dummy write, erase S1 ; Test BUSY ; Loop while busy ; Done, set LOCK ; Re-enable WDT?
6-10
6.3.3
Both write modes use a sequence of individual write instructions, but using the block write mode is approximately twice as fast as byte/word mode, because the voltage generator remains on for the complete block write. Any instruction that modifies a destination can be used to modify a flash location in either byte/word mode or block-write mode. A flash word (low + high byte) must not be written more than twice between erasures. Otherwise, damage can occur. The BUSY bit is set while a write operation is active and cleared when the operation completes. If the write operation is initiated from RAM, the CPU must not access flash while BUSY = 1. Otherwise, an access violation occurs, ACCVIFG is set, and the flash write is unpredictable.
Byte/Word Write
A byte/word write operation can be initiated from within flash memory or from RAM. When initiating from within flash memory, all timing is controlled by the flash controller, and the CPU is held while the write completes. After the write completes, the CPU resumes code execution with the instruction following the write. The byte/word write timing is shown in Figure 67.
Programming Operation Active Remove Programming Voltage
BUSY
When a byte/word write is executed from RAM, the CPU continues to execute code from RAM. The BUSY bit must be zero before the CPU accesses flash again, otherwise an access violation occurs, ACCVIFG is set, and the write result is unpredictable.
6-11
In byte/word mode, the internally generated programming voltage is applied to the complete 64-byte block each time a byte or word is written for tWORD minus threefFTG cycles. With each byte or word write, the amount of time the block is subjected to the programming voltage accumulates. The cumulative programming time, tCPT, must not be exceeded for any block. If the cumulative programming time is met, the block must be erased before performing any further writes to any address within the block. See the device-specific data sheet for specifications.
Disable watchdog
; Byte/word write from flash. 514 kHz < SMCLK < 952 kHz ; Assumes 0FF1Eh is already erased ; Assumes ACCVIE = NMIIE = OFIE = 0. MOV #WDTPW+WDTHOLD,&WDTCTL ; Disable WDT MOV #FWKEY+FSSEL1+FN0,&FCTL2 ; SMCLK/2 MOV #FWKEY,&FCTL3 ; Clear LOCK MOV #FWKEY+WRT,&FCTL1 ; Enable write MOV #0123h,&0FF1Eh ; 0123h > 0FF1Eh MOV #FWKEY,&FCTL1 ; Done. Clear WRT MOV #FWKEY+LOCK,&FCTL3 ; Set LOCK ... ; Re-enable WDT?
6-12
Disable watchdog
yes BUSY = 1
yes BUSY = 1
; Byte/word write from RAM. 514 kHz < SMCLK < 952 kHz ; Assumes 0FF1Eh is already erased ; Assumes ACCVIE = NMIIE = OFIE = 0. MOV #WDTPW+WDTHOLD,&WDTCTL ; Disable WDT L1 BIT #BUSY,&FCTL3 ; Test BUSY JNZ L1 ; Loop while busy MOV #FWKEY+FSSEL1+FN0,&FCTL2 ; SMCLK/2 MOV #FWKEY,&FCTL3 ; Clear LOCK MOV #FWKEY+WRT,&FCTL1 ; Enable write MOV #0123h,&0FF1Eh ; 0123h > 0FF1Eh L2 BIT #BUSY,&FCTL3 ; Test BUSY JNZ L2 ; Loop while busy MOV #FWKEY,&FCTL1 ; Clear WRT MOV #FWKEY+LOCK,&FCTL3 ; Set LOCK ... ; Re-enable WDT?
6-13
Block Write
The block write can be used to accelerate the flash write process when many sequential bytes or words need to be programmed. The flash programming voltage remains on for the duration of writing the 64-byte block. The cumulative programming time tCPT must not be exceeded for any block during a block write. A block write cannot be initiated from within flash memory. The block write must be initiated from RAM only. The BUSY bit remains set throughout the duration of the block write. The WAIT bit must be checked between writing each byte or word in the block. When WAIT is set the next byte or word of the block can be written. When writing successive blocks, the BLKWRT bit must be cleared after the current block is complete. BLKWRT can be set initiating the next block write after the required flash recovery time given by tEnd. BUSY is cleared following each block write completion indicating the next block can be written. Figure 610 shows the block write timing; see device-specific data sheet for specifications.
Cumulative Programming Time tCPT =< 10ms, VCC Current Consumption is Increased BUSY
tBlock, 0
WAIT
tBlock 1-63
tBlock, 1-63
tBlock,End
6-14
Disable watchdog
yes BUSY = 1
Set BLKWRT=WRT=1
yes
WAIT=0?
no Block Border?
Set BLKWRT=0
yes BUSY = 1
yes
Another Block?
6-15
; Write one block starting at 0F000h. ; Must be executed from RAM, Assumes Flash is already erased. ; 514 kHz < SMCLK < 952 kHz
; Assumes ACCVIE = NMIIE = OFIE = 0. MOV #32,R5 ; Use as write counter MOV #0F000h,R6 ; Write pointer
MOV L1 BIT JNZ #WDTPW+WDTHOLD,&WDTCTL #BUSY,&FCTL3 L1 #FWKEY,&FCTL3 #FWKEY+BLKWRT+WRT,&FCTL1 Write_Value,0(R6) #WAIT,&FCTL3 L3 R6 R5 L2 #FWKEY,&FCTL1 #BUSY,&FCTL3 L4 #FWKEY+LOCK,&FCTL3 ; Disable WDT ; Test BUSY ; Loop while busy ; ; ; ; ; ; ; ; ; ; ; ; ; Clear LOCK Enable block write Write location Test WAIT Loop while WAIT=0 Point to next word Decrement write counter End of block? Clear WRT,BLKWRT Test BUSY Loop while busy Set LOCK Re-enable WDT if needed
MOV
MOV MOV L2 MOV L3 BIT JZ INCD DEC JNZ MOV L4 BIT JNZ MOV ...
#FWKEY+FSSEL1+FN0,&FCTL2 ; SMCLK/2
6-16
6.3.4
Interrupts are automatically disabled during any flash operation on F47x3/4 and F471xx devices when EEI = 0 and EEIEX = 0 and on all other devices where EEI and EEIEX are not present. After the flash operation has completed, interrupts are automatically re-enabled. Any interrupt that occurred during the operation will have its associated flag set and will generate an interrupt request when re-enabled. On F47x3/4 and F471xx devices when EEIEX = 1 and GIE = 1, an interrupt will immediately abort any flash operation and the FAIL flag will be set. When EEI = 1, GIE = 1, and EEIEX = 0, a segment erase will be interrupted by a pending interrupt every 32 fFTG cycles. After servicing the interrupt, the segment erase is continued for at least 32 fFTG cycles or until it is complete. During the servicing of the interrupt, the BUSY bit remains set, but the flash memory can be accessed by the CPU without causing an access violation. Nested interrupts are not supported, because the RETI instruction is decoded to detect the return from interrupt. The watchdog timer (in watchdog mode) should be disabled before a flash erase cycle. A reset aborts the erase and the result is unpredictable. After the erase cycle has completed, the watchdog may be re-enabled.
6-17
6.3.5
6.3.6
6.3.7
6-18
6.3.8
6.3.9
6-19
Flash Memory
Host
MSP430
6-20
Initial State 09600h with PUC 09642h with PUC 09618h with PUC 0000h with PUC Reset with PUC
09658h in MSP430FG47x, MSP430F47x, MSP430F47x3/4, and MSP430F471xx devices MSP430FG47x, MSP430F47x, MSP430F47x3/4, and MSP430F471xx devices only
6-21
7 BLKWRT rw0
6 WRT rw0
5 Reserved r0
4 EEIEX r0
2 MERAS rw0
1 ERASE rw0
0 Reserved r0
MSP430FG461x devices only. Reserved with r0 access on all other devices. F47x3/4 and F471xx devices only. Reserved with r0 access on all other devices.
FCTLx password. Always read as 096h. Must be written as 0A5h or a PUC is generated. Block write mode. WRT must also be set for block write mode. BLKWRT is automatically reset when EMEX is set. 0 Block-write mode is off 1 Block-write mode is on Write. This bit is used to select any write mode. WRT is automatically reset when EMEX is set. 0 Write mode is off 1 Write mode is on Reserved. Always read as 0. Enable emergency interrupt exit. Setting this bit enables an interrupt to cause an emergency exit from a flash operation when GIE = 1. EEIEX is automatically reset when EMEX is set. 0 Exit interrupt disabled 1 Exit on interrupt enabled Enable erase Interrupts. Setting this bit allows a segment erase to be interrupted by an interrupt request. After the interrupt is serviced, the erase cycle is resumed. 0 Interrupts during segment erase disabled 1 Interrupts during segment erase enabled
WRT
Bit 6
Reserved EEIEX
Bit 5 Bit 4
EEI
Bits 3
6-22
Global mass erase, mass erase, and erase. These bits are used together to select the erase mode. GMERAS, MERAS, and ERASE are automatically reset when EMEX is set or the erase operation completes.
GMERAS 0 X 0 0 1 1 MERAS 0 0 1 1 1 1 ERASE 0 1 0 1 0 1 No erase Erase individual segment only Erase main memory segment of selected array Erase main memory segments and information segments of selected array Erase main memory segments of all memory arrays. Erase all main memory and information segments of all memory arrays Erase Cycle
Reserved
Bit 0
6-23
7 FSSELx rw0
3 FNx
rw1
rw-0
rw-0
rw-0
rw0
rw-1
rw0
FWKEYx
FCTLx password. Always read as 096h. Must be written as 0A5h, or a PUC is generated. Flash controller clock source select 00 ACLK 01 MCLK 10 SMCLK 11 SMCLK Flash controller clock divider. These six bits select the divider for the flash controller clock. The divisor value is FNx + 1. For example, when FNx = 00h, 0the divisor is 1. When FNx = 03Fh the divisor is 64.
FSSELx
FNx
Bits 5-0
6-24
7 FAIL r(w)0
6 LOCKA r(w)1
5 EMEX rw-0
4 LOCK rw-1
3 WAIT r-1
2 ACCVIFG rw0
1 KEYV rw-(0)
0 BUSY r(w)0
MSP430FG47x, MSP430F47x, MSP430F47x3/4, and MSP430F471xx devices only. Reserved with r0 access on all other devices.
FWKEYx
FCTLx password. Always read as 096h. Must be written as 0A5h, or a PUC is generated. Operation failure. This bit is set if the fFTG clock source fails or if a flash operation is aborted from an interrupt when EEIEX = 1. FAIL must be reset with software. 0 No failure 1 Failure SegmentA and Info lock. Write a 1 to this bit to change its state. Writing 0 has no effect. 0 Segment A unlocked and all information memory is erased during a mass erase. 1 Segment A locked and all information memory is protected from erasure during a mass erase. Emergency exit 0 No emergency exit 1 Emergency exit Lock. This bit unlocks the flash memory for writing or erasing. The LOCK bit can be set anytime during a byte/word write or erase operation and the operation completes normally. In the block write mode, if the LOCK bit is set while BLKWRT=WAIT=1, then BLKWRT and WAIT are reset, and the mode ends normally. 0 Unlocked 1 Locked Wait. Indicates the flash memory is being written. 0 The flash memory is not ready for the next byte/word write 1 The flash memory is ready for the next byte/word write Access violation interrupt flag 0 No interrupt pending 1 Interrupt pending
FAIL
LOCKA
Bit 6
EMEX
Bit 5
LOCK
Bit 4
WAIT
Bit 3
ACCVIFG
Bit 2
6-25
Bit 1
Flash security key violation. This bit indicates an incorrect FCTLx password was written to any flash control register and generates a PUC when set. KEYV must be reset with software. 0 FCTLx password was written correctly 1 FCTLx password was written incorrectly Busy. This bit indicates the status of the flash timing generator. 0 Not busy 1 Busy
BUSY
Bit 0
6-26
5 MRG1
4 MRG0 rw-0
r-0
r-0
rw-0
r-0
r-0
r-0
r-0
FWKEYx
FCTLx password. Always read as 096h. Must be written as 0A5h or a PUC will be generated. Reserved. Always read as 0. Marginal read 1 mode. This bit enables the marginal 1 read mode. The marginal read 1 bit is cleared if the CPU starts execution from the flash memory. If both MRG1 and MRG0 are set MRG1 is active and MRG0 is ignored. 0 Marginal 1 read mode is disabled. 1 Marginal 1 read mode is enabled. Marginal read 0 mode. This bit enables the marginal 0 read mode. The marginal mode 0 is cleared if the CPU starts execution from the flash memory. If both MRG1 and MRG0 are set MRG1 is active and MRG0 is ignored. 0 Marginal 0 read mode is disabled. 1 Marginal 0 read mode is enabled. Reserved. Always read as 0.
Reserved
MRG1
MRG0
Bit 4
Reserved
Bits 30
6-27
These bits may be used by other modules. See device-specific data sheet.
Bit 5
Flash memory access violation interrupt enable. This bit enables the ACCVIFG interrupt. Because other bits in IE1 may be used for other modules, it is recommended to set or clear this bit using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions. 0 Interrupt not enabled 1 Interrupt enabled
6-28
Chapter 7
Supply Voltage
Supervisor
This chapter describes the operation of the SVS. The SVS is implemented in all MSP430x4xx devices.
Topic
7.1 7.2 7.3
Page
SVS Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 SVS Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4 SVS Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7
7-1
SVS Introduction
The SVS block diagram is shown in Figure 71. Note: MSP430x412 and MSP430x413 Voltage Level Detect
The MSP430x412 and MSP430x413 devices implement only one voltage level detect setting. When VLDx = 0, the SVS is off. Any value greater than 0 for VLDx selects a voltage level detect of 1.9V.
7-2
SVS Introduction
~ 50us
D G S
Set SVSFG
7-3
SVS Operation
7.2.1
7.2.2
7-4
SVS Operation
7.2.3
7-5
SVS Operation
7.2.4
Brownout Region
BrownOut Region
t d(BOR)
t d(BOR)
td(SVSon)
td(SVSR)
undefined
7-6
SVS Registers
3 PORON
2 SVSON r
1 SVSOP r
0 SVSFG rw0
rw0
rw0
rw0
rw0
VLDx
Bits 7-4
Voltage level detect. These bits turn on the SVS and select the nominal SVS threshold voltage level. See the device-specific data sheet for parameters. 0000 SVS is off 0001 1.9 V 0010 2.1 V 0011 2.2 V 0100 2.3 V 0101 2.4 V 0110 2.5 V 0111 2.65 V 1000 2.8 V 1001 2.9 V 1010 3.05 1011 3.2 V 1100 3.35 V 1101 3.5 V 1110 3.7 V 1111 Compares external input voltage SVSIN to 1.2 V. POR on. This bit enables the SVSFG flag to cause a POR device reset. 0 SVSFG does not cause a POR 1 SVSFG causes a POR SVS on. This bit reflects the status of SVS operation. This bit DOES NOT turn on the SVS. The SVS is turned on by setting VLDx > 0. 0 SVS is Off 1 SVS is On SVS output. This bit reflects the output value of the SVS comparator. 0 SVS comparator output is low 1 SVS comparator output is high SVS flag. This bit indicates a low voltage condition. SVSFG remains set after a low voltage condition until reset by software. 0 No low voltage condition occurred 1 A low condition is present or has occurred
PORON
Bit 3
SVSON
Bit 2
SVSOP
Bit 1
SVSFG
Bit 0
7-7
7-8
Chapter 8
16-Bit
Hardware
Multiplier
This chapter describes the 16-bit hardware multiplier. The hardware multiplier is implemented in MSP430x44x, MSP430FE42x, MSP430FE42xA, MSP430FE42x2, and MSP430F42x, MSP430F42xA devices.
Topic
8.1 8.2 8.3
Page
Hardware Multiplier Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2 Hardware Multiplier Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3 Hardware Multiplier Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-7
8-1
MPY = 0000
32bit Multiplexer
SUMEXT 13Eh 15 r 0
S 31
RESHI 13Ch rw
RESLO 13Ah rw 0
8-2
8.2.1
Operand Registers
The operand one register OP1 has four addresses, shown in Table 81, used to select the multiply mode. Writing the first operand to the desired address selects the type of multiply operation but does not start any operation. Writing the second operand to the operand two register OP2 initiates the multiply operation. Writing OP2 starts the selected operation with the values stored in OP1 and OP2. The result is written into the three result registers RESLO, RESHI, and SUMEXT. Repeated multiply operations may be performed without reloading OP1 if the OP1 value is used for successive operations. It is not necessary to re-write the OP1 value to perform the operations.
8-3
8.2.2
Result Registers
The result low register RESLO holds the lower 16-bits of the calculation result. The result high register RESHI contents depend on the multiply operation and are listed in Table 82.
MAC MACS
The sum extension registers SUMEXT contents depend on the multiply operation and are listed in Table 83.
0000h 0001h
MACS
8-4
8.2.3
Software Examples
Examples for all multiplier modes follow. All 8x8 modes use the absolute address for the registers, because the assembler does not allow .B access to word registers when using the labels from the standard definitions file.
; 16x16 Unsigned Multiply MOV #01234h,&MPY ; Load first operand MOV #05678h,&OP2 ; Load second operand ; ... ; Process results ; 8x8 Unsigned Multiply. Absolute addressing. MOV.B #012h,&0130h ; Load first operand MOV.B #034h,&0138h ; Load 2nd operand ; ... ; Process results ; 16x16 Signed Multiply MOV #01234h,&MPYS ; Load first operand MOV #05678h,&OP2 ; Load 2nd operand ; ... ; Process results ; 8x8 Signed Multiply. Absolute addressing. MOV.B #012h,&0132h ; Load first operand SXT &MPYS ; Sign extend first operand MOV.B #034h,&0138h ; Load 2nd operand SXT &OP2 ; Sign extend 2nd operand ; (triggers 2nd multiplication) ; ... ; Process results ; 16x16 Unsigned Multiply Accumulate MOV #01234h,&MAC ; Load first operand MOV #05678h,&OP2 ; Load 2nd operand ; ... ; Process results ; 8x8 Unsigned Multiply MOV.B #012h,&0134h ; MOV.B #034h,&0138h ; ; ... ; Accumulate. Absolute addressing Load first operand Load 2nd operand Process results
; 16x16 Signed Multiply Accumulate MOV #01234h,&MACS ; Load first operand MOV #05678h,&OP2 ; Load 2nd operand ; ... ; Process results ; 8x8 Signed Multiply MOV.B #012h,&0136h SXT &MACS MOV.B #034h,R5 SXT R5 MOV R5,&OP2 ; ... Accumulate. Absolute addressing ; Load first operand ; Sign extend first operand ; Temp. location for 2nd operand ; Sign extend 2nd operand ; Load 2nd operand ; Process results
8-5
8.2.4
8.2.5
Using Interrupts
If an interrupt occurs after writing OP1 but before writing OP2, and the multiplier is used in servicing that interrupt, the original multiplier mode selection is lost and the results are unpredictable. To avoid this, disable interrupts before using the hardware multiplier or do not use the multiplier in interrupt service routines.
; Disable interrupts DINT ; NOP ; MOV #xxh,&MPY ; MOV #xxh,&OP2 ; EINT ; ; before using the hardware multiplier Disable interrupts Required for DINT Load 1st operand Load 2nd operand Interrupts may be enable before Process results
8-6
8-7
8-8
Chapter 9
32-Bit
Hardware
Multiplier
This chapter describes the 32-bit hardware multiplier (MPY32) of the MSP430x4xx family. The 32-bit hardware multiplier is implemented in MSP430F47x3/4 and MSP430F471xx devices.
Topic
9.1 9.2 9.3
Page
32-Bit Hardware Multiplier Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 9-2 32-Bit Hardware Multiplier Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-4 32-Bit Hardware Multiplier Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-21
9-1
9-2
MPY MPYS MAC MACS MPY32H MPYS32H MAC32H MACS32H 31 16 15 MPY32L MPYS32L MAC32L MACS32L 0 31 OP2H 16 15 OP2 OP2L 0
16 bit Multiplexer
16 bit Multiplexer
16 x 16 Multiplier OP1_32 OP2_32 MPYMx MPYSAT MPYFRAC MPYC 2 Control Logic 32 bit Adder
32 bit De Multiplexer
SUMEXT
RES3
RES2
RES1/RESHI
RES0/RESLO
32 bit Multiplexer
9-3
9-4
9.2.1
Operand Registers
Operand one OP1 has twelve registers, shown in Table 92, used to load data into the multiplier and also select the multiply mode. Writing the low-word of the first operand to a given address selects the type of multiply operation to be performed but does not start any operation. When writing a second word to a high-word register with suffix 32H the multiplier assumes a 32-bit wide OP1, otherwise 16-bits are assumed. The last address written prior to writing OP2 defines the width of the first operand. For example, if MPY32L is written first followed by MPY32H, all 32 bits are used and the data width of OP1 is set to 32 bits. If MPY32H is written first followed by MPY32L, the multiplication will ignore MPY32H and assume a 16bit wide OP1 using the data written into MPY32L. Repeated multiply operations may be performed without reloading OP1 if the OP1 value is used for successive operations. It is not necessary to rewrite the OP1 value to perform the operations.
Writing the second operand to the operand two register OP2 initiates the multiply operation. Writing OP2 starts the selected operation with a 16-bit wide second operand together with the values stored in OP1. Writing OP2L starts the selected operation with a 32-bit wide second operand and the multiplier expects a the high word to be written to OP2H. Writing to OP2H without a preceding write to OP2L is ignored.
9-5
OP2L
OP2H
For 8-bit or 24-bit operands the operand registers can be accessed with byte instructions. Accessing the multiplier with a byte instruction during a signed operation will automatically cause a sign extension of the byte within the multiplier module. For 24-bit operands only the high word should be written as byte. Whether or not the 24-bit operands are sign extended is defined by the register that is used to write the low word, because this register defines if the operation is unsigned or signed. The high word of a 32-bit operand remains unchanged when changing the size of the operand to 16 bit either by modifying the operand size bits or by writing to the respective operand register. During the execution of the 16-bit operation the content of the high word is ignored. Note: Changing of First or Second Operand During Multiplication Changing OP1 or OP2 while the selected multiply operation is being calculated will render any results invalid that are not ready at the time the new operand(s) are changed. Writing OP2 or OP2L will abort any ongoing calculation and start a new operation. Results that are not ready at that time are invalid also for following MAC or MACS operations. Refer to the tables Result Availability for the different modes on how many CPU cycles are needed until a certain result register is ready and valid.
9-6
9.2.2
Result Registers
The multiplication result is always 64-bits wide. It is accessible via registers RES0 to RES3. Used with a signed operation MPYS or MACS the results are appropriately sign extended. If the result registers are loaded with initial values before a MACS operation the user software must take care that the written value is properly sign extended to 64 bits. Note: Changing of Result Registers During Multiplication The result registers must not be modified by the user software after writing the second operand into OP2 or OP2L until the initiated operation is completed. In addition to RES0 to RES3, for compatibility with the 1616 hardware multiplier the 32-bit result of a 8-bit or 16-bit operation is accessible via RESLO, RESHI, and SUMEXT. In this case the result low register RESLO holds the lower 16-bits of the calculation result and the result high register RESHI holds the upper 16 bits. RES0 and RES1 are identical to RESLO and RESHI, respectively, in usage and access of calculated results. The sum extension registers SUMEXT contents depend on the multiply operation and are listed in Table 94. If all operands are 16 bits wide or less the 32-bit result is used to determine sign and carry. If one of the operands is larger than 16 bits the 64-bit result is used. The MPYC bit reflects the multipliers carry as listed in Table 94 and thus can be used as 33rd or 65th bit of the result if fractional or saturation mode is not selected. With MAC or MACS operations the MPYC bit reflects the carry of the 32-bit or 64-bit accumulation and is not taken into account for successive MAC and MACS operations as the 33rd or 65th bit.
SUMEXT contains the extended sign of the result 00000h Result was positive or zero 0FFFFh Result was negative
MPYC contains the carry of the result 0 1 No carry for result, Result has a carry
9-7
9-8
9.2.3
Software Examples
Examples for all multiplier modes follow. All 88 modes use the absolute address for the registers because the assembler will not allow .B access to word registers when using the labels from the standard definitions file. There is no sign extension necessary in software. Accessing the multiplier with a byte instruction during a signed operation will automatically cause a sign extension of the byte within the multiplier module.
; 32x32 Unsigned Multiply MOV #01234h,&MPY32L ; MOV #01234h,&MPY32H ; MOV #05678h,&OP2L ; MOV #05678h,&OP2H ; ; ... ;
Load low word of Load high word of Load low word of Load high word of Process results
; 16x16 Unsigned Multiply MOV #01234h,&MPY ; Load 1st operand MOV #05678h,&OP2 ; Load 2nd operand ; ... ; Process results ; 8x8 Unsigned Multiply. MOV.B #012h,&MPY_B MOV.B #034h,&OP2_B ; ... Absolute addressing. ; Load 1st operand ; Load 2nd operand ; Process results
; 32x32 Signed Multiply MOV #01234h,&MPYS32L ; Load low word of 1st operand MOV #01234h,&MPYS32H ; Load high word of 1st operand MOV #05678h,&OP2L ; Load low word of 2nd operand MOV #05678h,&OP2H ; Load high word of 2nd operand ; ... ; Process results ; 16x16 Signed Multiply MOV #01234h,&MPYS MOV #05678h,&OP2 ; ...
; 8x8 Signed Multiply. Absolute addressing. MOV.B #012h,&MPYS_B ; Load 1st operand MOV.B #034h,&OP2_B ; Load 2nd operand ; ... ; Process results
9-9
9.2.4
Fractional Numbers
The 32-bit multiplier provides support for fixed-point signal processing. In fixedpoint signal processing, fractional number are represented by using a fixed decimal point. To classify different ranges of decimal numbers, a Q-format is used. Different Q-formats represent different locations of the decimal point. Figure 92 shows the format of a signed Q15 number using 16 bits. Every bit after the decimal point has a resolution of 1/2, the most significant bit is used as the sign bit. The most negative number is 08000h and the maximum positive number is 07FFFh. This gives a range from 1.0 to 0.999969482 1.0 for the signed Q15 format with 16 bits.
The range can be increased by shifting the decimal point to the right as shown in Figure 93. The signed Q14 format with 16 bits gives a range from 2.0 to 1.999938965 2.0.
The benefit of using 16-bit signed Q15 or 32-bit signed Q31 numbers with multiplication is that the product of two number in the range from 1.0 to 1.0 is always in that same range.
9-10
on fractional mode 1st operand as Q15 2nd operand as Q15 result as Q15 to normal mode
9-11
Saturation Mode
The multiplier prevents overflow and underflow of signed operations in saturation mode. The saturation mode is enabled with MPYSAT = 1 in register MPY32CTL0. If an overflow occurs the result is set to the most positive value available. If an underflow occurs the result is set to the most negative value available. This is useful to reduce mathematical artifacts in control systems on overflow and underflow conditions. The saturation mode should only be enabled when required and disabled after use. The actual content of the result register(s) is not modified when MPYSAT = 1. When the result is accessed using software, the value is automatically adjusted providing the most positive or most negative result when an overflow or underflow has occurred. The adjusted result is also used for successive multiplyandaccumulate operations. This allows user software to switch between reading the saturated and the non-saturated result. With 16x16 operations the saturation mode only applies to the least significant 32 bits, i.e. the result registers RES0 and RES1. Using the saturation mode in MAC or MACS operations that mix 16x16 operations with 32x32, 16x32 or 32x16 operations will lead to unpredictable results. With 32x32, 16x32, and 32x16 operations the saturated result can only be calculated when RES3 is ready. In non-5xx devices, reading RES0 to RES2 prior to the complete result being ready will deliver the nonsaturated results, independent of the MPYSAT bit setting. Enabling the saturation mode does not affect the content of the SUMEXT register nor the content of the MPYC bit.
; Example using ; Fractional 16x16 multiply accumulate with Saturation ; Turn on fractional and saturation mode: BIS #MPYSAT+MPYFRAC,&MPY32CTL0 MOV &A1,&MPYS ; Load A1 for 1st term MOV &K1,&OP2 ; Load K1 to get A1*K1 MOV &A2,&MACS ; Load A2 for 2nd term MOV &K2,&OP2 ; Load K2 to get A2*K2 MOV &RES1,&PROD ; Save A1*K1+A2*K2 as result BIC #MPYSAT+MPYFRAC,&MPY32CTL0; turn back to normal
9-12
Figure 94 shows the flow for 32-bit saturation used for 1616 bit multiplications and the flow for 64-bit saturation used in all other cases. Primarily, the saturated results depends on the carry bit MPYC and the most significant bit of the result. Secondly, if the fractional mode is enabled it depends also on the two most significant bits of the unshift result; i.e., the result that is read with fractional mode disabled.
Yes
Yes
Yes
Yes
No MPYFRAC = 1 MPYFRAC = 1
No
Yes Yes Overflow: RES3 unchanged RES2 unchanged RES1 = 07FFFh RES0 = 0FFFFh
Yes Yes Overflow: RES3 = 07FFFh RES2 = 0FFFFh RES1 = 0FFFFh RES0 = 0FFFFh
Yes
Yes
Note: Saturation in Fractional Mode In case of multiplying 1.0 x 1.0 in fractional mode, the result of +1.0 is out of range, thus, the saturated result gives the most positive result.
9-13
The following example illustrates a special case showing the saturation function in fractional mode. It also uses the 8-bit functionality of the MPY32 module.
; Turn on fractional and saturation mode, ; clear all other bits in MPY32CTL0: MOV #MPYSAT+MPYFRAC,&MPY32CTL0 ;Preload result registers to demonstrate overflow MOV #0,&RES3 ; MOV #0,&RES2 ; MOV #07FFFh,&RES1 ; MOV #0FA60h,&RES0 ; MOV.B #050h,&MACS_B ; 8-bit signed MAC operation MOV.B #012h,&OP2_B ; Start 16x16 bit operation MOV &RES0,R6 ; R6 = 0FFFFh MOV &RES1,R7 ; R7 = 07FFFh
The result is saturated because already the result not converted into a fractional number shows an overflow. The multiplication of the two positive numbers 00050h and 00012h gives 005A0h. 005A0h added to 07FFF.FA60h results in 8000.059F without MPYC being set. Since the MSB of the unmodified result RES1 is 1 and MPYC = 0 the result is saturated according to the saturation flow chart in Figure 94. Note: Validity of Saturated Result The saturated result is only valid if the registers RES0 to RES3, the size of operands 1 and 2 and MPYC are not modified. If the saturation mode is used with a preloaded result, user software must ensure that MPYC in the MPY32CTL0 register is loaded with the sign bit of the written result otherwise the saturation mode erroneously saturates the result.
9-14
9.2.5
Yes 16x16 ? No MAC or MACS ? Yes MPYSAT=1 ? Clear Result: RES1 = 00000h RES0 = 00000h 32 bit Saturation No Yes
No
No
Clear Result: RES3 = 00000h RES2 = 00000h RES1 = 00000h RES0 = 00000h
Yes MPYFRAC=1 ? No Shift 64 bit result. Calculate SUMEXT based on MPYC and bit 15 of unshifted RES1.
Yes MPYFRAC=1 ? Shift 64 bit result. Calculate SUMEXT based on MPYC and bit 15 of unshifted RES3. No
Yes MPYSAT=1 ? No
Multiplication completed
9-15
Given the separation in processing of 16-bit operations (32-bit results) and 32-bit operations (64-bit results) by the module, it is important to understand the implications when using MAC/MACS operations and mixing 16-bit operands/results with 32-bit operands/results. User software must address these points during usage when mixing these operations. The following code illustrates the issue.
; Mixing 32x24 multiplication with 16x16 MACS operation MOV #MPYSAT,&MPY32CTL0; Saturation mode MOV #052C5h,&MPY32L ; Load low word of 1st operand MOV #06153h,&MPY32H ; Load high word of 1st operand MOV #001ABh,&OP2L ; Load low word of 2nd operand MOV.B #023h,&OP2H_B ; Load high word of 2nd operand ;... 5 NOPs required MOV &RES0,R6 ; R6 = 00E97h MOV &RES1,R7 ; R7 = 0A6EAh MOV &RES2,R8 ; R8 = 04F06h MOV &RES3,R9 ; R9 = 0000Dh ; Note that MPYC = 0! MOV #0CCC3h,&MACS ; Signed MAC operation MOV #0FFB6h,&OP2 ; 16x16 bit operation MOV &RESLO,R6 ; R6 = 0FFFFh MOV &RESHI,R7 ; R7 = 07FFFh
The second operation gives a saturated result because the 32-bit value used for the 16x16 bit MACS operation was already saturated when the operation was started: the carry bit MPYC was 0 from the previous operation but the most significant bit in result register RES1 is set. As one can see in the flow chart the content of the result registers are saturated for multiply-and-accumulate operations after starting a new operation based on the previous results but depending on the size of the result (32-bit or 64-bit) of the newly initiated operation. The saturation before the multiplication can cause issues if the MPYC bit is not properly set as the following code example illustrates.
;Preload result registers to demonstrate overflow MOV #0,&RES3 ; MOV #0,&RES2 ; MOV #0,&RES1 ; MOV #0,&RES0 ; ; Saturation mode and set MPYC: MOV #MPYSAT+MPYC,&MPY32CTL0 MOV.B #082h,&MACS_B ; 8-bit signed MAC operation MOV.B #04Fh,&OP2_B ; Start 16x16 bit operation MOV &RES0,R6 ; R6 = 00000h MOV &RES1,R7 ; R7 = 08000h
9-16
Even though the result registers were loaded with all zeros the final result is saturated. This is because the MPYC bit was set causing the result used for the multiply-and-accumulate to be saturated to 08000 0000h. Adding a negative number to it would again cause an underflow thus the final result is also saturated to 08000 0000h.
9.2.6
In case of a 32x16 multiplication there is also one instruction required between reading the first result register RES0 and the second result register RES1:
; Access MOV MOV MOV MOV NOP MOV NOP MOV MOV multiplier 32x16 results with indirect addressing #RES0,R5 ; RES0 address in R5 for indirect &OPER1L,&MPY32L ; Load low word of 1st operand &OPER1H,&MPY32H ; Load high word of 1st operand &OPER2,&OP2 ; Load 2nd operand (16 bits) ; Need one cycle @R5+,&xxx ; Move RES0 ; Need one additional cycle @R5,&xxx ; Move RES1 ; No additional cycles required! @R5,&xxx ; Move RES2
9-17
9.2.7
Using Interrupts
If an interrupt occurs after writing OP1, but before writing OP2, and the multiplier is used in servicing that interrupt, the original multiplier mode selection is lost and the results are unpredictable. To avoid this, disable interrupts before using the hardware multiplier, do not use the multiplier in interrupt service routines, or use the save and restore functionality of the 32-bit multiplier.
; Disable interrupts DINT ; NOP ; MOV #xxh,&MPY ; MOV #xxh,&OP2 ; EINT ; ; ; ; before using the hardware multiplier Disable interrupts Required for DINT Load 1st operand Load 2nd operand Interrupts may be enabled before processing results if result registers are stored and restored in interrupt service routines
9-18
9-19
9.2.8
Using DMA
In devices with a DMA controller the multiplier can trigger a transfer when the complete result is available. The DMA controller needs to start reading the result with MPY32RES0 successively up to MPY32RES3. Not all registers need to be read. The trigger timing is such that the DMA controller starts reading MPY32RES0 when its ready and that the MPY32RES3 can be read exactly in the clock cycle when it is available to allow fastest access via DMA. The signal into the DMA controller is Multiplier ready. Please refer to the DMA users guide chapter for details.
9-20
MPYS32H_B Read/write
MACS32H_B Read/write OP2L OP2H OP2H_B RES0 RES1 RES2 RES3 MPY32CTL0 Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write
9-21
9-22
7 MPY OP2_32 rw
6 MPY OP1_32 rw
5 MPYMx rw
3 MPYSAT
2 MPYFRAC rw0
1 Reserved rw0
0 MPYC rw
rw
rw0
Reserved
Reserved Multiplier bit-width of operand 2 0 16 bits 1 32 bits Multiplier bit-width of operand 1. 0 16 bits 1 32 bits Multiplier mode 00 MPY Multiply 01 MPYS Signed multiply 10 MAC Multiply accumulate 11 MACS Signed multiply accumulate Saturation mode 0 Saturation mode disabled 1 Saturation mode enabled Fractional mode 0 Fractional mode disabled 1 Fractional mode enabled Reserved Carry of the multiplier. It can be considered as 33rd or 65th bit of the result if fractional or saturation mode is not selected because the MPYC bit does not change when switching to saturation or fractional mode. It is used to restore the SUMEXT content in MAC mode. 0 No carry for result 1 Result has a carry
MPY OP2_32
MPY OP1_32
Bit 6
MPYMx
Bits 5-4
MPYSAT
Bit 3
MPYFRAC
Bit 2
Reserved MPYC
Bit 1 Bit 0
9-23
9-24
Chapter 10
DMA
Controller
The DMA controller module transfers data from one address to another without CPU intervention. This chapter describes the operation of the DMA controller. One DMA channel is implemented in MSP430FG43x and three DMA channels are implemented in the MSP430FG461x and MSP430F471xx devices.
Topic
Page
10.1 DMA Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2 10.2 DMA Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-4 10.3 DMA Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-21
DMA Controller
10-1
DMA Introduction
10-2
DMA Controller
DMA Introduction
JTAG Active
DMAEN
DMA1TSELx 4 DMAREQ TACCR2_CCIFG TBCCR2_CCIFG Serial data received Serial transmit ready DAC12_0IFG ADC12IFGx TACCR0_CCIFG TBCCR0_CCIFG USART1 data received USART1 transmit ready Multiplier ready Serial data received Serial transmit ready DMA0IFG DMAE0 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 DMADSTINCRx DMADTx DMADSTBYTE 3 DMA Channel 1 DMA1SA DMA1DA DMA1SZ 2 DMASRSBYTE DMASRCINCRx DT Address Space
DMAEN
DMA2TSELx 4 DMAREQ TACCR2_CCIFG TBCCR2_CCIFG Serial data received Serial transmit ready DAC12_0IFG ADC12IFGx TACCR0_CCIFG TBCCR0_CCIFG USART1 data received USART1 transmit ready Multiplier ready Serial data received Serial transmit ready DMA1IFG DMAE0 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 2
DMASRSBYTE DMASRCINCRx
DMAEN
DMA Controller
10-3
DMA Operation
The addressing modes are configured with the DMASRCINCRx and DMADSTINCRx control bits. The DMASRCINCRx bits select if the source address is incremented, decremented, or unchanged after each transfer. The DMADSTINCRx bits select if the destination address is incremented, decremented, or unchanged after each transfer. Transfers may be byte-to-byte, word-to-word, byte-to-word, or word-to-byte. When transferring word-to-byte, only the lower byte of the source-word transfers. When transferring byte-to-word, the upper byte of the destination-word is cleared when the transfer occurs.
DMA Controller
Address Space
DMA Controller
Address Space
DMA Controller
Address Space
DMA Controller
Address Space
10-4
DMA Controller
DMA Operation
001
Block transfer
010, 011
Burst-block transfer Repeated single transfer Repeated block transfer Repeated burst-block transfer
100
101
110, 111
DMA Controller
10-5
DMA Operation
Single Transfer
In single transfer mode, each byte/word transfer requires a separate trigger. The single transfer state diagram is shown in Figure 103. The DMAxSZ register is used to define the number of transfers to be made. The DMADSTINCRx and DMASRCINCRx bits select if the destination address and the source address are incremented or decremented after each transfer. If DMAxSZ = 0, no transfers occur. The DMAxSA, DMAxDA, and DMAxSZ registers are copied into temporary registers. The temporary values of DMAxSA and DMAxDA are incremented or decremented after each transfer. The DMAxSZ register is decremented after each transfer. When the DMAxSZ register decrements to zero it is reloaded from its temporary register and the corresponding DMAIFG flag is set. When DMADTx = 0, the DMAEN bit is cleared automatically when DMAxSZ decrements to zero and must be set again for another transfer to occur. In repeated single transfer mode, the DMA controller remains enabled with DMAEN = 1, and a transfer occurs every time a trigger occurs.
10-6
DMA Controller
DMA Operation
Idle
DMAABORT=0
DMAREQ = 0
2 x MCLK
[+Trigger AND DMALEVEL = 0 ] OR [Trigger=1 AND DMALEVEL=1] T_Size DMAxSZ DMAxSA T_SourceAdd DMAxDA T_DestAdd
Hold CPU, Transfer one word/byte [ENNMI = 1 AND NMI event] OR [DMALEVEL = 1 AND Trigger = 0] Decrement DMAxSZ Modify T_SourceAdd Modify T_DestAdd
DMA Controller
10-7
DMA Operation
Block Transfers
In block transfer mode, a transfer of a complete block of data occurs after one trigger. When DMADTx = 1, the DMAEN bit is cleared after the completion of the block transfer and must be set again before another block transfer can be triggered. After a block transfer has been triggered, further trigger signals occurring during the block transfer are ignored. The block transfer state diagram is shown in Figure 104. The DMAxSZ register is used to define the size of the block and the DMADSTINCRx and DMASRCINCRx bits select if the destination address and the source address are incremented or decremented after each transfer of the block. If DMAxSZ = 0, no transfers occur. The DMAxSA, DMAxDA, and DMAxSZ registers are copied into temporary registers. The temporary values of DMAxSA and DMAxDA are incremented or decremented after each transfer in the block. The DMAxSZ register is decremented after each transfer of the block and shows the number of transfers remaining in the block. When the DMAxSZ register decrements to zero it is reloaded from its temporary register and the corresponding DMAIFG flag is set. During a block transfer, the CPU is halted until the complete block has been transferred. The block transfer takes 2 x MCLK x DMAxSZ clock cycles to complete. CPU execution resumes with its previous state after the block transfer is complete. In repeated block transfer mode, the DMAEN bit remains set after completion of the block transfer. The next trigger after the completion of a repeated block transfer triggers another block transfer.
10-8
DMA Controller
DMA Operation
DMAABORT=0
2 x MCLK
Hold CPU, Transfer one word/byte [ENNMI = 1 AND NMI event] OR [DMALEVEL = 1 AND Trigger = 0] Decrement DMAxSZ Modify T_SourceAdd Modify T_DestAdd
DMAxSZ > 0
DMA Controller
10-9
DMA Operation
Burst-Block Transfers
In burst-block mode, transfers are block transfers with CPU activity interleaved. The CPU executes 2 MCLK cycles after every four byte/word transfers of the block resulting in 20% CPU execution capacity. After the burst-block, CPU execution resumes at 100% capacity and the DMAEN bit is cleared. DMAEN must be set again before another burst-block transfer can be triggered. After a burst-block transfer has been triggered, further trigger signals occurring during the burst-block transfer are ignored. The burst-block transfer state diagram is shown in Figure 105. The DMAxSZ register is used to define the size of the block and the DMADSTINCRx and DMASRCINCRx bits select if the destination address and the source address are incremented or decremented after each transfer of the block. If DMAxSZ = 0, no transfers occur. The DMAxSA, DMAxDA, and DMAxSZ registers are copied into temporary registers. The temporary values of DMAxSA and DMAxDA are incremented or decremented after each transfer in the block. The DMAxSZ register is decremented after each transfer of the block and shows the number of transfers remaining in the block. When the DMAxSZ register decrements to zero it is reloaded from its temporary register and the corresponding DMAIFG flag is set. In repeated burst-block mode the DMAEN bit remains set after completion of the burst-block transfer and no further trigger signals are required to initiate another burst-block transfer. Another burst-block transfer begins immediately after completion of a burst-block transfer. In this case, the transfers must be stopped by clearing the DMAEN bit, or by an NMI interrupt when ENNMI is set. In repeated burst-block mode the CPU executes at 20% capacity continuously until the repeated burst-block transfer is stopped.
10-10
DMA Controller
DMA Operation
DMAEN = 1
DMAxSZ T_Size [DMADTx = {2, 3} DMAxSA T_SourceAdd AND DMAxSZ = 0] DMAxDA T_DestAdd OR DMAEN = 0 DMAABORT = 1 Idle
DMAABORT=0
2 x MCLK
Hold CPU, Transfer one word/byte [ENNMI = 1 AND NMI event] OR [DMALEVEL = 1 AND Trigger = 0] Decrement DMAxSZ Modify T_SourceAdd Modify T_DestAdd DMAxSZ > 0
DMA Controller
10-11
DMA Operation
Edge-Sensitive Triggers
When DMALEVEL = 0, edge-sensitive triggers are used and the rising edge of the trigger signal initiates the transfer. In single-transfer mode, each transfer requires its own trigger. When using block or burst-block modes, only one trigger is required to initiate the block or burst-block transfer.
Level-Sensitive Triggers
When DMALEVEL = 1, level-sensitive triggers are used. For proper operation, level-sensitive triggers can only be used when external trigger DMAE0 is selected as the trigger. DMA transfers are triggered as long as the trigger signal is high and the DMAEN bit remains set. The trigger signal must remain high for a block or burst-block transfer to complete. If the trigger signal goes low during a block or burst-block transfer, the DMA controller is held in its current state until the trigger goes back high or until the DMA registers are modified by software. If the DMA registers are not modified by software, when the trigger signal goes high again, the transfer resumes from where it was when the trigger signal went low. When DMALEVEL = 1, transfer modes selected when DMADTx = {0, 1, 2, 3} are recommended because the DMAEN bit is automatically reset after the configured transfer.
10-12
DMA Controller
DMA Operation
0010
0011
0100
0101
0110
0111
1000
1001
Devices with USCI_A1: A transfer is triggered when the UCA1RXIFG flag is set. UCA1RXIFG is automatically reset when the transfer starts. If UCA1RXIE is set, the UCA1RXIFG flag will not trigger a transfer.
DMA Controller
10-13
DMA Operation
1111
10-14
DMA Controller
DMA Operation
When the ROUNDROBIN bit is cleared the channel priority returns to the default priority. DMA channel priorities are not applicable to MSP430FG43x devices.
DMA Controller
10-15
DMA Operation
Low-power mode LPM0/1 MCLK=DCOCLK Low-power mode LPM3/4 MCLK=DCOCLK Low-power mode LPM0/1 MCLK=LFXT1CLK Low-power mode LPM3 Low-power mode LPM4
MCLK=LFXT1CLK MCLK=LFXT1CLK
The additional 6 s are needed to start the DCOCLK. It is the t(LPMx) parameter in the data sheet.
10-16
DMA Controller
DMA Operation
DMA Controller
10-17
DMA Operation
DMAIV Software Example The following software example shows the recommended use of DMAIV and the handling overhead. The DMAIV value is added to the PC to automatically jump to the appropriate routine. The numbers at the right margin show the necessary CPU cycles for each instruction. The software overhead for different interrupt sources includes interrupt latency and return-from-interrupt cycles, but not the task handling itself.
;Interrupt handler for DMA0IFG, DMA1IFG, DMA2IFG Cycles DMA_HND ... ; Interrupt latency 6 ADD &DMAIV,PC ; Add offset to Jump table 3 RETI ; Vector 0: No interrupt 5 JMP DMA0_HND ; Vector 2: DMA channel 0 2 JMP DMA1_HND ; Vector 4: DMA channel 1 2 JMP DMA2_HND ; Vector 6: DMA channel 2 2 RETI ; Vector 8: Reserved 5 RETI ; Vector 10: Reserved 5 RETI ; Vector 12: Reserved 5 RETI ; Vector 14: Reserved 5 DMA2_HND ... RETI DMA1_HND ... RETI DMA0_HND ... RETI ; Vector 6: DMA channel 2 ; Task starts here ; Back to main program ; Vector 4: DMA channel 1 ; Task starts here ; Back to main program ; Vector 2: DMA channel 0 ; Task starts here ; Back to main program
10-18
DMA Controller
DMA Operation
10.2.10 Using the USCI_B I2C Module with the DMA Controller
The USCI_B I2C module provides two trigger sources for the DMA controller. The USCI_B I2C module can trigger a transfer when new I2C data is received and when data is needed for transmit. A transfer is triggered if UCB0RXIFG is set. The UCB0RXIFG is cleared automatically when the DMA controller acknowledges the transfer. If UCB0RXIE is set, UCB0RXIFG will not trigger a transfer. A transfer is triggered if UCB0TXIFG is set. The UCB0TXIFG is cleared automatically when the DMA controller acknowledges the transfer. If UCB0TXIE is set, UCB0TXIFG will not trigger a transfer.
DMA Controller
10-19
DMA Operation
10-20
DMA Controller
DMA Registers
DMA Controller
10-21
DMA Registers
6 DMA1TSELx
2 DMA0TSELx
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
Reserved DMA trigger select. These bits select the DMA transfer trigger. The trigger selection is device-specific. For MSP430FG43x and MSP430FG461x devices it is given below; for other devices, see the device-specific data sheet. 0000 DMAREQ bit (software trigger) 0001 TACCR2 CCIFG bit 0010 TBCCR2 CCIFG bit 0011 URXIFG0 (MSP430FG43x), UCA0RXIFG (MPS430FG461x) 0100 UTXIFG0 (MSP430FG43x), UCA0TXIFG (MSP430FG461x) 0101 DAC12_0CTL DAC12IFG bit 0110 ADC12 ADC12IFGx bit 0111 TACCR0 CCIFG bit 1000 TBCCR0 CCIFG bit 1001 URXIFG1 bit 1010 UTXIFG1 bit 1011 Multiplier ready 1100 No action (MSP430FG43x), UCB0RXIFG (MSP430FG461x) 1101 No action (MSP430FG43x), UCB0TXIFG (MSP430FG461x) 1110 DMA0IFG bit triggers DMA channel 1 DMA1IFG bit triggers DMA channel 2 DMA2IFG bit triggers DMA channel 0 1111 External trigger DMAE0 Same as DMA2TSELx Same as DMA2TSELx
Bits 74 Bits 30
10-22
DMA Controller
DMA Registers
7 0 r0
6 0 r0
5 0 r0
4 0 r0
3 0 r0
0 ENNMI rw(0)
Reserved. Read only. Always read as 0. DMA on fetch 0 The DMA transfer occurs immediately 1 The DMA transfer occurs on next instruction fetch after the trigger Round robin. This bit enables the round-robin DMA channel priorities. 0 DMA channel priority is DMA0 DMA1 DMA2 1 DMA channel priority changes with each transfer Enable NMI. This bit enables the interruption of a DMA transfer by an NMI interrupt. When an NMI interrupts a DMA transfer, the current transfer is completed normally, further transfers are stopped, and DMAABORT is set. 0 NMI interrupt does not interrupt DMA transfer 1 NMI interrupt interrupts a DMA transfer
Bit 1
Bit 0
DMA Controller
10-23
DMA Registers
5 DMALEVEL rw(0)
4 DMAEN rw(0)
3 DMAIFG rw(0)
2 DMAIE rw(0)
0 DMAREQ rw(0)
Reserved DMADTx
Reserved DMA Transfer mode. 000 Single transfer 001 Block transfer 010 Burst-block transfer 011 Burst-block transfer 100 Repeated single transfer 101 Repeated block transfer 110 Repeated burst-block transfer 111 Repeated burst-block transfer DMA destination increment. This bit selects automatic incrementing or decrementing of the destination address after each byte or word transfer. When DMADSTBYTE=1, the destination address increments/decrements by one. When DMADSTBYTE=0, the destination address increments/decrements by two. The DMAxDA is copied into a temporary register and the temporary register is incremented or decremented. DMAxDA is not incremented or decremented. 00 Destination address is unchanged 01 Destination address is unchanged 10 Destination address is decremented 11 Destination address is incremented DMA source increment. This bit selects automatic incrementing or decrementing of the source address for each byte or word transfer. When DMASRCBYTE=1, the source address increments/decrements by one. When DMASRCBYTE=0, the source address increments/decrements by two. The DMAxSA is copied into a temporary register and the temporary register is incremented or decremented. DMAxSA is not incremented or decremented. 00 Source address is unchanged 01 Source address is unchanged 10 Source address is decremented 11 Source address is incremented DMA destination byte. This bit selects the destination as a byte or word. 0 Word 1 Byte
DMA DSTINCRx
Bits 1110
DMA SRCINCRx
Bits 98
DMA DSTBYTE
Bit 7
10-24
DMA Controller
Bit 6
DMA source byte. This bit selects the source as a byte or word. 0 Word 1 Byte DMA level. This bit selects between edge-sensitive and level-sensitive triggers. 0 Edge sensitive (rising edge) 1 Level sensitive (high level) DMA enable 0 Disabled 1 Enabled DMA interrupt flag 0 No interrupt pending 1 Interrupt pending DMA interrupt enable 0 Disabled 1 Enabled DMA Abort. This bit indicates if a DMA transfer was interrupt by an NMI. 0 DMA transfer not interrupted 1 DMA transfer was interrupted by NMI DMA request. Software-controlled DMA start. DMAREQ is reset automatically. 0 No DMA start 1 Start DMA
DMA LEVEL
Bit 5
DMAEN
Bit 4
DMAIFG
Bit 3
DMAIE
Bit 2
DMA ABORT
Bit 1
DMAREQ
Bit 0
DMA Controller
10-25
DMA Registers
23
22 Reserved
21
20
19
18 DMAxSAx
17
16
r0
r0
r0
r0
rw
rw
rw
rw
15
14
13
12 DMAxSAx
11
10
rw
rw
rw
rw
rw
rw
rw
rw
4 DMAxSAx
rw
rw
rw
rw
rw
rw
rw
rw
Reserved
Reserved DMA source address. The source address register points to the DMA source address for single transfers or the first source address for block transfers. The source address register remains unchanged during block and burst-block transfers. Devices that have addressable memory range 64KB or below contain a single word for the DMAxSA. MSP430FG461x and MSP430F471xx devices implement two words for the DMAxSA register as shown. Bits 3120 are reserved and always read as zero. Reading or writing bits 19-16 requires the use of extended instructions. When writing to DMAxSA with word instructions, bits 19-16 are cleared.
DMAxSAx
10-26
DMA Controller
DMA Registers
23
22 Reserved
21
20
19
18 DMAxDAx
17
16
r0
r0
r0
r0
rw
rw
rw
rw
15
14
13
12 DMAxDAx
11
10
rw
rw
rw
rw
rw
rw
rw
rw
4 DMAxDAx
rw
rw
rw
rw
rw
rw
rw
rw
Reserved
Reserved DMA destination address. The destination address register points to the destination address for single transfers or the first address for block transfers. The DMAxDA register remains unchanged during block and burst-block transfers. Devices that have addressable memory range 64KB or below contain a single word for the DMAxDA. MSP430FG461x and MSP430F471xx devices implement two words for the DMAxDA register as shown. Bits 3120 are reserved and always read as zero. Reading or writing bits 19-16 requires the use of extended instructions. When writing to DMAxDA with word instructions, bits 19-16 are cleared.
DMAxDAx
DMA Controller
10-27
DMA Registers
4 DMAxSZx
rw
rw
rw
rw
rw
rw
rw
rw
DMAxSZx
Bits 150
DMA size. The DMA size register defines the number of byte/word data per block transfer. DMAxSZ register decrements with each word or byte transfer. When DMAxSZ decrements to 0, it is immediately and automatically reloaded with its previously initialized value. 00000h Transfer is disabled 00001h One byte or word to be transferred 00002h Two bytes or words have to be transferred : 0FFFFh 65535 bytes or words have to be transferred
10-28
DMA Controller
DMA Registers
7 0 r0
6 0 r0
5 0 r0
4 0 r0
2 DMAIVx
0 0
r(0)
r(0)
r(0)
r0
DMAIVx
Bits 15-0
DMAIV Contents 00h 02h 04h 06h 08h 0Ah 0Ch 0Eh
Interrupt Source No interrupt pending DMA channel 0 DMA channel 1 DMA channel 2 Reserved Reserved Reserved Reserved
Interrupt Priority
Highest
Lowest
DMA Controller
10-29
10-30
DMA Controller
Chapter 11
Digital I/O
This chapter describes the operation of the digital I/O ports.
Topic
Page
11.1 Digital I/O Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2 11.2 Digital I/O Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-3 11.3 Digital I/O Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-7
Digital I/O
11-1
11-2
Digital I/O
Writing to these read-only registers results in increased current consumption while the write attempt is active.
Digital I/O
11-3
11.2.4 Pullup/Pulldown Resistor Enable Registers PxREN (MSP430F47x3/4 and MSP430F471xx only)
In MSP430F47x3/4 and MSP430F471xx devices all port pins have a programmable pullup/pulldown resistor. Each bit in each PxREN register enables or disables the pullup/pulldown resistor of the corresponding I/O pin. The corresponding bit in the PxOUT register selects if the pin is pulled up or pulled down. Bit = 0: Pullup/pulldown resistor disabled Bit = 1: Pullup/pulldown resistor enabled
Note: P1 and P2 Interrupts Are Disabled When PxSEL = 1 When any P1SELx or P2SELx bit is set, the corresponding pins interrupt function is disabled. Therefore, signals on these pins do not generate P1 or P2 interrupts, regardless of the state of the corresponding P1IE or P2IE bit. When a port pin is selected as an input to a peripheral, the input signal to the peripheral is a latched representation of the signal at the device pin. While PxSELx = 1, the internal input signal follows the signal at the pin. However, if the PxSELx = 0, the input to the peripheral maintains the value of the input signal at the device pin before the PxSELx bit was reset.
11-4
Digital I/O
Writing to P1OUT, P1DIR, P2OUT, or P2DIR can result in setting the corresponding P1IFG or P2IFG flags.
Note:
Any external interrupt event should be at least 1.5 times MCLK or longer, to ensure that it is accepted and the corresponding interrupt flag is set.
Digital I/O
11-5
Writing to P1IES or P2IES can result in setting the corresponding interrupt flags. PxIESx 01 01 10 10 PxINx 0 1 0 1 PxIFGx May be set Unchanged Unchanged May be set
11-6
Digital I/O
Short Form P1IN P1OUT P1DIR P1IFG P1IES P1IE P1SEL P1REN P2IN P2OUT P2DIR P2IFG P2IES P2IE P2SEL P2REN P3IN P3OUT P3DIR P3SEL P3REN P4IN P4OUT P4DIR P4SEL P4REN P5IN P5OUT P5DIR P5SEL P5REN P6IN P6OUT P6DIR P6SEL P6REN
Address 020h 021h 022h 023h 024h 025h 026h 027h 028h 029h 02Ah 02Bh 02Ch 02Dh 02Eh 02Fh 018h 019h 01Ah 01Bh 010h 01Ch 01Dh 01Eh 01Fh 011h 030h 031h 032h 033h 012h 034h 035h 036h 037h 013h
Register Type Read only Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read only Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read only Read/write Read/write Read/write Read/write Read only Read/write Read/write Read/write Read/write Read only Read/write Read/write Read/write Read/write Read only Read/write Read/write Read/write Read/write
Initial State
Unchanged
Reset with PUC Reset with PUC Unchanged Reset with PUC Reset with PUC Reset with PUC Unchanged Reset with PUC Reset with PUC Unchanged Reset with PUC 0C0h with PUC Reset with PUC Unchanged Reset with PUC Reset with PUC Reset with PUC Unchanged Reset with PUC Reset with PUC Reset with PUC Unchanged Reset with PUC Reset with PUC Reset with PUC Unchanged Reset with PUC Reset with PUC Reset with PUC
Resistor enable registers RxREN only available in MSP430F47x3/4 and MSP430F471xx devices.
Digital I/O
11-7
Short Form P7IN P7OUT P7DIR P7SEL P7REN P8IN P8OUT P8DIR P8SEL P8REN P9IN P9OUT P9DIR P9SEL P9REN P10IN P10OUT P10DIR P10SEL P10REN
Address 038h 03Ah 03Ch 03Eh 014h 039h 03Bh 03Dh 03Fh 015h 008h 00Ah 00Ch 00Eh 016h 009h 00Bh 00Dh 00Fh 017h
Register Type Read only Read/write Read/write Read/write Read/write Read only Read/write Read/write Read/write Read/write Read only Read/write Read/write Read/write Read/write Read only Read/write Read/write Read/write Read/write
Initial State Unchanged Reset with PUC Reset with PUC Reset with PUC Unchanged Reset with PUC Reset with PUC Reset with PUC Unchanged Reset with PUC Reset with PUC Reset with PUC Unchanged Reset with PUC Reset with PUC Reset with PUC
Resistor enable registers RxREN only available in MSP430F47x3/4 and MSP430F471xx devices.
11-8
Digital I/O
Chapter 12
Topic
Page
12.1 Watchdog Timer Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-2 12.2 Watchdog Timer Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-4 12.3 Watchdog Timer Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-7
12-1
The WDT block diagram is shown in Figure 121. Note: Watchdog Timer Powers Up Active
After a PUC, the WDT module is automatically configured in the watchdog mode with an initial 32768 clock cycle reset interval using the DCOCLK. The user must setup or halt the WDT prior to the expiration of the initial reset interval.
12-2
MCLK
Fail-Safe Logic
EQU
SMCLK ACLK
1 1
12-3
12-4
Note:
The WDT interval should be changed together with WDTCNTCL = 1 in a single instruction to avoid an unexpected immediate PUC or interrupt. The WDT should be halted before changing the clock source to avoid a possible incorrect interval.
When using the WDT in the watchdog mode, the WDTIFG flag sources a reset vector interrupt. The WDTIFG can be used by the reset interrupt service routine to determine if the watchdog caused the device to reset. If the flag is set, then the watchdog timer initiated the reset condition either by timing out or by a security key violation. If WDTIFG is cleared, the reset was caused by a different source. When using the WDT in interval timer mode, the WDTIFG flag is set after the selected time interval and requests a WDT interval timer interrupt if the WDTIE and the GIE bits are set. The interval timer interrupt vector is different from the reset vector used in watchdog mode. In interval timer mode, the WDTIFG flag is reset automatically when the interrupt is serviced or can be reset with software.
12-5
12-6
Initial State 06900h with PUC Reset with PUC Reset with PUC
12-7
7 WDTHOLD rw0
6 WDTNMIES rw0
5 WDTNMI rw0
4 WDTTMSEL rw0
3 WDTCNTCL r0(w)
2 WDTSSEL rw0
1 WDTISx rw0
rw0
WDTPW
Watchdog timer password. Always read as 069h. Must be written as 05Ah, or a PUC is generated. Watchdog timer hold. This bit stops the watchdog timer. Setting WDTHOLD = 1 when the WDT is not in use conserves power. 0 Watchdog timer is not stopped 1 Watchdog timer is stopped Watchdog timer NMI edge select. This bit selects the interrupt edge for the NMI interrupt when WDTNMI = 1. Modifying this bit can trigger an NMI. Modify this bit when WDTNMI = 0 to avoid triggering an accidental NMI. 0 NMI on rising edge 1 NMI on falling edge Watchdog timer NMI select. This bit selects the function for the RST/NMI pin. 0 Reset function 1 NMI function Watchdog timer mode select 0 Watchdog mode 1 Interval timer mode Watchdog timer counter clear. Setting WDTCNTCL = 1 clears the count value to 0000h. WDTCNTCL is automatically reset. 0 No action 1 WDTCNT = 0000h Watchdog timer clock source select 0 SMCLK 1 ACLK Watchdog timer interval select. These bits select the watchdog timer interval to set the WDTIFG flag and/or generate a PUC. 00 Watchdog clock source / 32768 01 Watchdog clock source / 8192 10 Watchdog clock source / 512 11 Watchdog clock source / 64
WDTHOLD
WDTNMIES
Bit 6
WDTNMI
Bit 5
WDTTMSEL Bit 4
WDTCNTCL Bit 3
WDTSSEL
Bit 2
WDTISx
Bits 1-0
12-8
Bits 7-5
NMIIE
These bits may be used by other modules. See device-specific data sheet. NMI interrupt enable. This bit enables the NMI interrupt. Because other bits in IE1 may be used for other modules, it is recommended to set or clear this bit using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions. 0 Interrupt not enabled 1 Interrupt enabled These bits may be used by other modules. See device-specific data sheet. Watchdog timer interrupt enable. This bit enables the WDTIFG interrupt for interval timer mode. It is not necessary to set this bit for watchdog mode. Because other bits in IE1 may be used for other modules, it is recommended to set or clear this bit using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions. 0 Interrupt not enabled 1 Interrupt enabled
Bit 4
Bits 3-1
WDTIE
Bit 0
12-9
Bits 7-5
NMIIFG
These bits may be used by other modules. See device-specific data sheet. NMI interrupt flag. NMIIFG must be reset by software. Because other bits in IFG1 may be used for other modules, it is recommended to clear NMIIFG by using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions. 0 No interrupt pending 1 Interrupt pending These bits may be used by other modules. See device-specific data sheet. Watchdog timer interrupt flag. In watchdog mode, WDTIFG remains set until reset by software. In interval mode, WDTIFG is reset automatically by servicing the interrupt, or it can be reset by software. Because other bits in IFG1 may be used for other modules, it is recommended to clear WDTIFG by using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions. 0 No interrupt pending 1 Interrupt pending
Bit 4
Bits 3-1
WDTIFG
Bit 0
12-10
Chapter 13
Basic Timer1
The Basic Timer1 module is composed of two independent cascadable 8-bit timers. This chapter describes the Basic Timer1. Basic Timer1 is implemented in all MSP430x4xx devices.
Topic
Page
13.1 Basic Timer1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-2 13.2 Basic Timer1 Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-4 13.3 Basic Timer1 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-6
Basic Timer1
13-1
The Basic Timer1 block diagram is shown in Figure 131. Note: Basic Timer1 Initialization
The Basic Timer1 module registers have no initial condition. These registers must be configured by user software before use.
13-2
Basic Timer1
BTSSEL
00 ACLK:256 SMCLK 01 10 11
Basic Timer1
13-3
When the CPU clock and counter clock are asynchronous, any read from BTCNT1 or BTCNT2 may be unpredictable. Any write to BTCNT1 or BTCNT2 takes effect immediately.
13-4
Basic Timer1
The BTIFG flag is set after the selected time interval and requests a Basic Timer1 interrupt if the BTIE and the GIE bits are set. The BTIFG flag is reset automatically when the interrupt is serviced, or it can be reset with software.
Basic Timer1
13-5
Initial State Unchanged Unchanged Unchanged Reset with PUC Reset with PUC
The Basic Timer1 registers should be configured at power-up. There is no initial state for BTCTL, BTCNT1, or BTCNT2.
13-6
Basic Timer1
BTSSEL BTHOLD
Bit 7 Bit 6
BTCNT2 clock select. This bit, together with the BTDIV bit, selects the clock source for BTCNT2. See the description for BTDIV. Basic Timer1 hold 0 BTCNT1 and BTCNT2 are operational 1 BTCNT1 is held if BTDIV=1 BTCNT2 is held Basic Timer1 clock divide. This bit together with the BTSSEL bit, selects the clock source for BTCNT2.
BTSSEL 0 0 1 1 BTDIV 0 1 0 1 BTCNT2 Clock Source ACLK ACLK/256 SMCLK ACLK/256
BTDIV
Bit 5
BTFRFQx
Bits 43
fLCD frequency. These bits control the LCD update frequency. 00 fACLK/32 01 fACLK/64 10 fACLK/128 11 fACLK/256 Basic Timer1 interrupt interval 000 fCLK2/2 001 fCLK2/4 010 fCLK2/8 011 fCLK2/16 100 fCLK2/32 101 fCLK2/64 110 fCLK2/128 111 fCLK2/256
BTIPx
Bits 20
Basic Timer1
13-7
BTCNT1x
Bits 70
BTCNT2x
Bits 70
13-8
Basic Timer1
BTIE
Bit 7
Basic Timer1 interrupt enable. This bit enables the BTIFG interrupt. Because other bits in IE2 may be used for other modules, it is recommended to set or clear this bit using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions. 0 Interrupt not enabled 1 Interrupt enabled These bits may be used by other modules. See device-specific data sheet.
Bits 6-1
BTIFG
Bit 7
Basic Timer1 interrupt flag. Because other bits in IFG2 may be used for other modules, it is recommended to clear BTIFG automatically by servicing the interrupt, or by using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions. 0 No interrupt pending 1 Interrupt pending These bits may be used by other modules. See device-specific data sheet.
Bits 6-1
Basic Timer1
13-9
13-10
Basic Timer1
Chapter 14
Topic
Page
14.1 Real-Time Clock Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-2 14.2 Real-Time Clock Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-4 14.3 Real-Time Clock Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-7
14-1
RTC Introduction
The RTC block diagram is shown in Figure 141. Note: Real-Time Clock Initialization Most RTC module registers have no initial condition. These registers must be configured by user software before use.
14-2
RTC Introduction
RTCMODEx RTCBCD BCD 31 ... 24 23 ... 16 15 ... 8 7 ... RTCNT1/ RTCSEC RTCNT4/ RTCDOW RTCNT3/ RTCHOUR RTCNT2/ RTCMIN RTCHOLD Mode 0 RTCTEVx
8bit overflow / minute changed 16bit overflow / hour changed 24bit overflow / RTCHOUR = Midnight 32bit overflow / RTCHOUR = Noon
EN
Midnight
14-3
14-4
14-5
The Real-Time Clock module shares the Basic Timer1 interrupt flag and vector. When RTCIE = 0, the Basic Timer1 controls interrupt generation with the BTIPx bits. In this case, the RTCEVx bits select the interval for setting the RTCFG flag, but the RTCFG flag does not generate an interrupt. The RTCFG flag must be cleared with software when RTCIE = 0. When RTCIE = 1, the RTC controls interrupt generation and the Basic Timer1 BTIPx bits are ignored. In this case, the RTCFG and BTIFG flags are set at the interval selected with the RTCEVx bits, and an interrupt request is generated if the GIE bit is set. Both the RTCFG and BTIFG flags are reset automatically when the interrupt is serviced, or can be reset with software. The interrupt intervals are listed in Table 141.
14-6
Note: Modifying SFR bits To avoid modifying control bits of other modules, it is recommended to set or clear the IEx and IFGx bits using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions.
14-7
RTCBCD
Bit 7
BCD format select. This bit selects BCD format for the calendar registers when RTCMODEx = 11. 0 Hexadecimal format 1 BCD format Real-Time Clock hold 0 Real-Time Clock is operational 1 RTCMODEx < 11: The RTC module is stopped RTCMODEx = 11: The RTC and the Basic Timer1 are stopped Real-Time Clock mode and clock source select
RTCHOLD
Bit 6
RTCMODEx
Bits 5-4
RTCMODEx 00 01 10 11 RTCTEVx
Counter Mode 32-bit counter 32-bit counter 32-bit counter Calendar mode ACLK
Clock Source
Bits 3-2
Real-Time Clock interrupt event. These bits select the event for setting RTCFG.
RTC Mode Counter Mode RTCTEVx 00 01 10 11 Calendar Mode 00 01 10 11 Interrupt Interval 8-bit overflow 16-bit overflow 24-bit overflow 32-bit overflow Minute changed Hour changed Every day at midnight (00:00) Every day at noon (12:00)
RTCIE
Bit 1
Real-Time Clock interrupt enable 0 Interrupt not enabled 1 Interrupt enabled Real-Time Clock interrupt flag 0 No time event occurred 1 Time event occurred
RTCFG
Bit 0
14-8
RTCNT1x
Bits 70
RTCNT2x
Bits 70
RTCNT3x
Bits 70
RTCNT4x
Bits 70
14-9
Seconds (0...59) rw rw rw rw
Minutes (0...59) rw rw rw rw
14-10
14-11
Day-of-Month (1...28,29,30,31) rw rw rw rw
14-12
RTCYEARL, RTC Year Low-Byte Register, Calendar Mode with Hexadecimal Format
7 6 5 4 3 2 1 0
RTCYEARL, RTC Year Low-Byte Register, Calendar Mode with BCD Format
7 6 5 4 3 2 1 0
Decade (0...9) rw rw rw rw rw
RTCYEARH, RTC Year High-Byte Register, Calendar Mode with Hexadecimal Format
7 0 r-0 6 0 r-0 5 0 r-0 4 0 r-0 rw 3 2 1 0
RTCYEARH, RTC Year High-Byte Register, Calendar Mode with BCD Format
7 0 r-0 rw 6 5 Century high digit (0...4) rw rw rw 4 3 2 1 0
14-13
BTIE
Bit 7
Basic Timer1 interrupt enable. This bit enables the BTIFG interrupt. Because other bits in IE2 may be used for other modules, it is recommended to set or clear this bit using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions. 0 Interrupt not enabled 1 Interrupt enabled These bits may be used by other modules. See device-specific data sheet.
Bits 6-1
BTIFG
Bit 7
Basic Timer1 interrupt flag. Because other bits in IFG2 may be used for other modules, it is recommended to clear BTIFG automatically by servicing the interrupt, or by using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions. 0 No interrupt pending 1 Interrupt pending These bits may be used by other modules. See device-specific data sheet.
Bits 6-1
14-14
Chapter 15
Timer_A
Timer_A is a 16-bit timer/counter with multiple capture/compare registers. This chapter describes Timer_A. This chapter describes the operation of the Timer_A of the MSP430x4xx device family.
Topic
Page
15.1 Timer_A Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-2 15.2 Timer_A Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-4 15.3 Timer_A Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-19
Timer_A
15-1
Timer_A Introduction
The block diagram of Timer_A is shown in Figure 151. Note: Use of the Word Count
Count is used throughout this chapter. It means the counter must be in the process of counting for the action to take place. If a particular value is directly written to the counter, then an associated action does not take place.
Note:
MSP430x415, MSP430x417, and MSP430xW42x devices implement a second Timer_A with five capture/compare registers. On these devices, both Timer_A modules are identical in function, except for the additional capture/compare registers.
15-2
Timer_A
Timer_A Introduction
TASSELx
IDx
00 01 10 11
Divider 1/2/4/8
Count Mode
EQU0
CCISx
CMx
logic
COV SCS
00 01 10 11 CCI
15 0 1 TACCR4
SCCI
A EN
EQU0
D Set Q Reset
OUT4 Signal
POR OUTMODx
Timer_A
15-3
Timer_A Operation
It is recommended to stop the timer before modifying its operation (with exception of the interrupt enable, interrupt flag, and TACLR) to avoid errant operating conditions. When the timer clock is asynchronous to the CPU clock, any read from TAR should occur while the timer is not operating or the results may be unpredictable. Alternatively, the timer may be read multiple times while operating, and a majority vote taken in software to determine the correct reading. Any write to TAR takes effect immediately.
15-4
Timer_A
Timer_A Operation
by writing 0 to TACCR0. The timer may then be restarted by writing a nonzero value to TACCR0. In this scenario, the timer starts incrementing in the up direction from zero.
Timer_A
15-5
Timer_A Operation
Up Mode
The up mode is used if the timer period must be different from 0FFFFh counts. The timer repeatedly counts up to the value of compare register TACCR0, which defines the period, as shown in Figure 152. The number of timer counts in the period is TACCR0+1. When the timer value equals TACCR0 the timer restarts counting from zero. If up mode is selected when the timer value is greater than TACCR0, the timer immediately restarts counting from zero.
0FFFFh TACCR0
0h
The TACCR0 CCIFG interrupt flag is set when the timer counts to the TACCR0 value. The TAIFG interrupt flag is set when the timer counts from TACCR0 to zero. Figure 153 shows the flag set cycle.
Timer Clock Timer Set TAIFG Set TACCR0 CCIFG CCR01 CCR0 0h 1h CCR01 CCR0 0h
Changing the Period Register TACCR0 When changing TACCR0 while the timer is running, if the new period is greater than or equal to the old period or greater than the current count value, the timer counts up to the new period. If the new period is less than the current count value, the timer rolls to zero. However, one additional count may occur before the counter rolls to zero.
15-6
Timer_A
Timer_A Operation
Continuous Mode
In the continuous mode, the timer repeatedly counts up to 0FFFFh and restarts from zero as shown in Figure 154. The capture/compare register TACCR0 works the same way as the other capture/compare registers.
0FFFFh
0h
The TAIFG interrupt flag is set when the timer counts from 0FFFFh to zero. Figure 155 shows the flag set cycle.
Timer_A
15-7
Timer_A Operation
TACCR1d
t0
t0
t0
t1
t1
t1
Time intervals can be produced with other modes as well, where TACCR0 is used as the period register. Their handling is more complex since the sum of the old TACCRx data and the new period can be higher than the TACCR0 value. When the previous TACCRx value plus tx is greater than the TACCR0 data, the TACCR0 value must be subtracted to obtain the correct time interval.
15-8
Timer_A
Timer_A Operation
Up/Down Mode
The up/down mode is used if the timer period must be different from 0FFFFh counts, and if symmetrical pulse generation is needed. The timer repeatedly counts up to the value of compare register TACCR0 and back down to zero, as shown in Figure 157. The period is twice the value in TACCR0.
0h
The count direction is latched. This allows the timer to be stopped and then restarted in the same direction it was counting before it was stopped. If this is not desired, the TACLR bit must be set to clear the direction. The TACLR bit also clears the TAR value and the clock divider. In up/down mode, the TACCR0 CCIFG interrupt flag and the TAIFG interrupt flag are set only once during a period, separated by 1/2 the timer period. The TACCR0 CCIFG interrupt flag is set when the timer counts from TACCR0 1 to TACCR0, and TAIFG is set when the timer completes counting down from 0001h to 0000h. Figure 158 shows the flag set cycle.
Timer Clock Timer Up/Down Set TAIFG Set TACCR0 CCIFG CCR01 CCR0 CCR01 CCR02 1h 0h
Timer_A
15-9
Timer_A Operation
Changing the Period Register TACCR0 When changing TACCR0 while the timer is running and counting in the down direction, the timer continues its descent until it reaches zero. The value in TACCR0 is latched into TACL0 immediately; however, the new period takes effect after the counter counts down to zero. When the timer is counting in the up direction and the new period is greater than or equal to the old period or greater than the current count value, the timer counts up to the new period before counting down. When the timer is counting in the up direction, and the new period is less than the current count value, the timer begins counting down. However, one additional count may occur before the counter begins counting down.
TACCRx Content of capture/compare register x The TACCRx registers are not buffered. They update immediately when written to. Therefore, any required dead time is not maintained automatically.
Output Mode 2: Toggle/Reset EQU1 EQU1 EQU1 EQU1 TAIFG EQU0 EQU0 EQU2 EQU2 EQU2 EQU2
TAIFG
Interrupt Events
15-10
Timer_A
Timer_A Operation
Capture Mode
The capture mode is selected when CAP = 1. Capture mode is used to record time events. It can be used for speed computations or time measurements. The capture inputs CCIxA and CCIxB are connected to external pins or internal signals and are selected with the CCISx bits. The CMx bits select the capture edge of the input signal as rising, falling, or both. A capture occurs on the selected edge of the input signal. If a capture occurs:
- The timer value is copied into the TACCRx register - The interrupt flag CCIFG is set
The input signal level can be read at any time via the CCI bit. MSP430x4xx family devices may have different signals connected to CCIxA and CCIxB. See the device-specific data sheet for the connections of these signals. The capture signal can be asynchronous to the timer clock and cause a race condition. Setting the SCS bit synchronizes the capture with the next timer clock. Setting the SCS bit to synchronize the capture signal with the timer clock is recommended. This is illustrated in Figure 1510.
Timer Clock Timer CCI Capture Set TACCRx CCIFG n2 n1 n n+1 n+2 n+3 n+4
Overflow logic is provided in each capture/compare register to indicate if a second capture was performed before the value from the first capture was read. Bit COV is set when this occurs as shown in Figure 1511. COV must be reset with software.
Timer_A
15-11
Timer_A Operation
Capture Clear Bit COV in Register TACCTLx Second Capture Taken COV = 1 Idle
Capture
Capture Initiated by Software Captures can be initiated by software. The CMx bits can be set for capture on both edges. Software then sets CCIS1 = 1 and toggles bit CCIS0 to switch the capture signal between VCC and GND, initiating a capture each time CCIS0 changes state:
MOV XOR #CAP+SCS+CCIS1+CM_3,&TACCTLx ; Setup TACCTLx #CCIS0,&TACCTLx ; TACCTLx = TAR
Compare Mode
The compare mode is selected when CAP = 0. The compare mode is used to generate PWM output signals or interrupts at specific time intervals. When TAR counts to the value in a TACCRx:
- Interrupt flag CCIFG is set - Internal signal EQUx = 1 - EQUx affects the output according to the output mode - The input signal CCI is latched into SCCI
15-12
Timer_A
Timer_A Operation
Output Modes
The output modes are defined by the OUTMODx bits and are described in Table 152. The OUTx signal is changed with the rising edge of the timer clock for all modes except mode 0. Output modes 2, 3, 6, and 7 are not useful for output unit 0, because EQUx = EQU0.
001
Set
010
Toggle/Reset
011
Set/Reset
100
Toggle
101
Reset
110
Toggle/Set
111
Reset/Set
Timer_A
15-13
Timer_A Operation
Output ExampleTimer in Up Mode The OUTx signal is changed when the timer counts up to the TACCRx value, and rolls from TACCR0 to zero, depending on the output mode. An example is shown in Figure 1512 using TACCR0 and TACCR1.
Output Mode 7: Reset/Set EQU0 TAIFG EQU1 EQU0 TAIFG EQU1 EQU0 TAIFG Interrupt Events
15-14
Timer_A
Timer_A Operation
Output ExampleTimer in Continuous Mode The OUTx signal is changed when the timer reaches the TACCRx and TACCR0 values, depending on the output mode. An example is shown in Figure 1513 using TACCR0 and TACCR1.
Output Mode 7: Reset/Set TAIFG EQU1 EQU0 TAIFG EQU1 EQU0 Interrupt Events
Timer_A
15-15
Timer_A Operation
Output ExampleTimer in Up/Down Mode The OUTx signal changes when the timer equals TACCRx in either count direction and when the timer equals TACCR0, depending on the output mode. An example is shown in Figure 1514 using TACCR0 and TACCR2.
Output Mode 7: Reset/Set TAIFG EQU2 EQU2 EQU2 EQU2 EQU0 TAIFG EQU0 Interrupt Events
Note:
When switching between output modes, one of the OUTMODx bits should remain set during the transition, unless switching to mode 0. Otherwise, output glitching can occur because a NOR gate decodes output mode 0. A safe method for switching between output modes is to use output mode 7 as a transition state:
BIS BIC #OUTMOD_7,&TACCTLx ; Set output mode=7 #OUTMODx,&TACCTLx ; Clear unwanted bits
15-16
Timer_A
Timer_A Operation
In capture mode any CCIFG flag is set when a timer value is captured in the associated TACCRx register. In compare mode, any CCIFG flag is set if TAR counts to the associated TACCRx value. Software may also set or clear any CCIFG flag. All CCIFG flags request an interrupt when their corresponding CCIE bit and the GIE bit are set.
TACCR0 Interrupt
The TACCR0 CCIFG flag has the highest Timer_A interrupt priority and has a dedicated interrupt vector as shown in Figure 1515. The TACCR0 CCIFG flag is automatically reset when the TACCR0 interrupt request is serviced.
Capture CCIE Q
Set
Timer_A
15-17
Timer_A Operation
TAIV Software Example The following software example shows the recommended use of TAIV and the handling overhead. The TAIV value is added to the PC to automatically jump to the appropriate routine. The numbers at the right margin show the necessary CPU cycles for each instruction. The software overhead for different interrupt sources includes interrupt latency and return-from-interrupt cycles, but not the task handling itself. The latencies are:
- Capture/compare block TACCR0 - Capture/compare blocks TACCR1, TACCR2 - Timer overflow TAIFG
; Interrupt handler for TACCR0 CCIFG. Cycles CCIFG_0_HND ; ... ; Start of handler Interrupt latency 6 RETI 5 ; Interrupt handler for TAIFG, TACCR1 and TACCR2 CCIFG. TA_HND ... ADD RETI JMP JMP RETI RETI ; &TAIV,PC ; ; CCIFG_1_HND ; CCIFG_2_HND ; ; ; Interrupt latency Add offset to Jump table Vector 0: No interrupt Vector 2: TACCR1 Vector 4: TACCR2 Vector 6: Reserved Vector 8: Reserved 6 3 5 2 2 5 5
; Vector 10: TAIFG Flag ; Task starts here 5 ; Vector 4: TACCR2 ; Task starts here ; Back to main program ; Vector 2: TACCR1 ; Task starts here ; Back to main program
15-18
Timer_A
Timer_A Registers
Timer_A
15-19
Timer_A Registers
7 IDx rw(0)
5 MCx
3 Unused
2 TACLR w(0)
1 TAIE rw(0)
0 TAIFG rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
Unused
Unused Timer_A clock source select 00 TACLK 01 ACLK 10 SMCLK 11 Inverted TACLK Input divider. These bits select the divider for the input clock. 00 /1 01 /2 10 /4 11 /8 Mode control. Setting MCx = 00h when Timer_A is not in use conserves power. 00 Stop mode: the timer is halted 01 Up mode: the timer counts up to TACCR0 10 Continuous mode: the timer counts up to 0FFFFh 11 Up/down mode: the timer counts up to TACCR0 then down to 0000h Unused Timer_A clear. Setting this bit resets TAR, the clock divider, and the count direction. The TACLR bit is automatically reset and is always read as zero. Timer_A interrupt enable. This bit enables the TAIFG interrupt request. 0 Interrupt disabled 1 Interrupt enabled Timer_A interrupt flag 0 No interrupt pending 1 Interrupt pending
TASSELx
IDx
Bits 7-6
MCx
Bits 5-4
Unused TACLR
TAIE
TAIFG
Bit 0
15-20
Timer_A
Timer_A Registers
4 TARx
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
TARx
Bits 15-0
4 TACCRx
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
TACCRx
Bits 15-0
Timer_A capture/compare register. Compare mode: TACCRx holds the data for the comparison to the timer value in the Timer_A Register, TAR. Capture mode: The Timer_A Register, TAR, is copied into the TACCRx register when a capture is performed.
Timer_A
15-21
Timer_A Registers
6 OUTMODx
4 CCIE
3 CCI r
2 OUT rw(0)
1 COV rw(0)
0 CCIFG rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
CMx
Bit 15-14
Capture mode 00 No capture 01 Capture on rising edge 10 Capture on falling edge 11 Capture on both rising and falling edges Capture/compare input select. These bits select the TACCRx input signal. See the device-specific data sheet for specific signal connections. 00 CCIxA 01 CCIxB 10 GND 11 VCC Synchronize capture source. This bit is used to synchronize the capture input signal with the timer clock. 0 Asynchronous capture 1 Synchronous capture Synchronized capture/compare input. The selected CCI input signal is latched with the EQUx signal and can be read via this bit. Unused. Read only. Always read as 0. Capture mode 0 Compare mode 1 Capture mode Output mode. Modes 2, 3, 6, and 7 are not useful for TACCR0 because EQUx = EQU0. 000 OUT bit value 001 Set 010 Toggle/reset 011 Set/reset 100 Toggle 101 Reset 110 Toggle/set 111 Reset/set
CCISx
Bit 13-12
SCS
Bit 11
SCCI
Unused CAP
OUTMODx
Bits 7-5
15-22
Timer_A
Bit 4
Capture/compare interrupt enable. This bit enables the interrupt request of the corresponding CCIFG flag. 0 Interrupt disabled 1 Interrupt enabled Capture/compare input. The selected input signal can be read by this bit. Output. For output mode 0, this bit directly controls the state of the output. 0 Output low 1 Output high Capture overflow. This bit indicates a capture overflow occurred. COV must be reset with software. 0 No capture overflow occurred 1 Capture overflow occurred Capture/compare interrupt flag 0 No interrupt pending 1 Interrupt pending
CCI OUT
Bit 3 Bit 2
COV
Bit 1
CCIFG
Bit 0
7 0 r0
6 0 r0
5 0 r0
4 0 r0
2 TAIVx
0 0
r(0)
r(0)
r(0)
r0
TAIVx
Bits 15-0
TAIV Contents 00h 02h 04h 06h 08h 0Ah 0Ch 0Eh
Interrupt Source No interrupt pending Capture/compare 1 Capture/compare 2 Capture/compare 3 Capture/compare Timer overflow Reserved Reserved 4
Interrupt Flag TACCR1 CCIFG TACCR2 CCIFG TACCR3 CCIFG TACCR4 CCIFG TAIFG
Interrupt Priority
Highest
Lowest
Timer1_A5 only
Timer_A
15-23
15-24
Timer_A
Chapter 16
Timer_B
Timer_B is a 16-bit timer/counter with multiple capture/compare registers. This chapter describes the operation of the Timer_B of the MSP430x4xx device family.
Topic
Page
16.1 Timer_B Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-2 16.2 Timer_B Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-4 16.3 Timer_B Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-20
Timer_B
16-1
Timer_B Introduction
selectable lengths
- Selectable and configurable clock source - Three or seven configurable capture/compare registers - Configurable outputs with PWM capability - Double-buffered compare latches with synchronized loading - Interrupt vector register for fast decoding of all Timer_B interrupts
The block diagram of Timer_B is shown in Figure 161. Note: Use of the Word Count
Count is used throughout this chapter. It means the counter must be in the process of counting for the action to take place. If a particular value is directly written to the counter, then an associated action does not take place.
- Timer_B TBCCRx registers are double-buffered and can be grouped. - All Timer_B outputs can be put into a high-impedance state. - The SCCI bit function is not implemented in Timer_B.
16-2
Timer_B
Timer_B Introduction
IDx
Clear
CCR0 CCR1 CCR2 CCR3 CCR4 CCR5 CCISx CMx logic COV SCS CCI6A CCI6B GND VCC 00 01 10 11 CLLDx CCI VCC TBR=0 EQU0 UP/DOWN 00 01 10 11 CCR5 CCR4 CCR1 0 1 OUT EQU0 Output Unit6 Timer Clock D Set Q Reset OUT6 Signal Set TBCCR6 CCIFG Compararator 6 EQU6 CAP Group Load Logic Load Compare Latch TBCL6 Capture Mode Timer Clock Sync 15 0 1 TBCCR6 0 CCR6
POR OUTMODx
Timer_B
16-3
Timer_B Operation
It is recommended to stop the timer before modifying its operation (with exception of the interrupt enable, interrupt flag, and TBCLR) to avoid errant operating conditions. When the timer clock is asynchronous to the CPU clock, any read from TBR should occur while the timer is not operating, or the results may be unpredictable. Alternatively, the timer may be read multiple times while operating, and a majority vote taken in software to determine the correct reading. Any write to TBR takes effect immediately.
TBR Length
Timer_B is configurable to operate as an 8-, 10-, 12-, or 16-bit timer with the CNTLx bits. The maximum count value, TBR(max), for the selectable lengths is 0FFh, 03FFh, 0FFFh, and 0FFFFh, respectively. Data written to the TBR register in 8-, 10-, and 12-bit modes is right-justified with leading zeros.
16-4
Timer_B
Timer_B Operation
by loading 0 to TBCL0. The timer may then be restarted by loading a nonzero value to TBCL0. In this scenario, the timer starts incrementing in the up direction from zero.
Timer_B
16-5
Timer_B Operation
Up Mode
The up mode is used if the timer period must be different from TBR(max) counts. The timer repeatedly counts up to the value of compare latch TBCL0, which defines the period, as shown in Figure 162. The number of timer counts in the period is TBCL0+1. When the timer value equals TBCL0 the timer restarts counting from zero. If up mode is selected when the timer value is greater than TBCL0, the timer immediately restarts counting from zero.
TBR(max) TBCL0
0h
The TBCCR0 CCIFG interrupt flag is set when the timer counts to the TBCL0 value. The TBIFG interrupt flag is set when the timer counts from TBCL0 to zero. Figure 153 shows the flag set cycle.
Timer Clock Timer Set TBIFG Set TBCCR0 CCIFG TBCL01 TBCL0 0h 1h TBCL01 TBCL0 0h
Changing the Period Register TBCL0 When changing TBCL0 while the timer is running and when the TBCL0 load event is immediate, CLLD0 = 00, if the new period is greater than or equal to the old period, or greater than the current count value, the timer counts up to the new period. If the new period is less than the current count value, the timer rolls to zero. However, one additional count may occur before the counter rolls to zero.
16-6
Timer_B
Timer_B Operation
Continuous Mode
In continuous mode the timer repeatedly counts up to TBR(max) and restarts from zero as shown in Figure 164. The compare latch TBCL0 works the same way as the other capture/compare registers.
0h
The TBIFG interrupt flag is set when the timer counts from TBR(max) to zero. Figure 165 shows the flag set cycle.
Timer_B
16-7
Timer_B Operation
TBCL1d
0h EQU0 Interrupt
t0
t0
t0
EQU1 Interrupt
t1
t1
t1
Time intervals can be produced with other modes as well, where TBCL0 is used as the period register. Their handling is more complex since the sum of the old TBCLx data and the new period can be higher than the TBCL0 value. When the sum of the previous TBCLx value plus tx is greater than the TBCL0 data, TBCL0 + 1 must be subtracted to obtain the correct time interval.
16-8
Timer_B
Timer_B Operation
Up/Down Mode
The up/down mode is used if the timer period must be different from TBR(max) counts, and if a symmetrical pulse generation is needed. The timer repeatedly counts up to the value of compare latch TBCL0, and back down to zero, as shown in Figure 167. The period is twice the value in TBCL0. Note: TBCL0 > TBR(max)
If TBCL0 > TBR(max), the counter operates as if it were configured for continuous mode. It does not count down from TBR(max) to zero.
TBCL0
0h
The count direction is latched. This allows the timer to be stopped and then restarted in the same direction it was counting before it was stopped. If this is not desired, the TBCLR bit must be used to clear the direction. The TBCLR bit also clears the TBR value and the clock divider. In up/down mode, the TBCCR0 CCIFG interrupt flag and the TBIFG interrupt flag are set only once during the period, separated by 1/2 the timer period. The TBCCR0 CCIFG interrupt flag is set when the timer counts from TBCL01 to TBCL0, and TBIFG is set when the timer completes counting down from 0001h to 0000h. Figure 168 shows the flag set cycle.
Timer Clock Timer Up/Down Set TBIFG Set TBCCR0 CCIFG TBCL01 TBCL0 TBCL01 TBCL02 1h 0h 1h
Timer_B
16-9
Timer_B Operation
Changing the Value of Period Register TBCL0 When changing TBCL0 while the timer is running and counting in the down direction, and when the TBCL0 load event is immediate, the timer continues its descent until it reaches zero. The value in TBCCR0 is latched into TBCL0 immediately; however, the new period takes effect after the counter counts down to zero. If the timer is counting in the up direction when the new period is latched into TBCL0, and the new period is greater than or equal to the old period, or greater than the current count value, the timer counts up to the new period before counting down. When the timer is counting in the up direction, and the new period is less than the current count value when TBCL0 is loaded, the timer begins counting down. However, one additional count may occur before the counter begins counting down.
TBCLx Content of compare latch x The ability to simultaneously load grouped compare latches assures the dead times.
Output Mode 2: Toggle/Reset EQU1 EQU1 EQU1 EQU1 TBIFG EQU0 EQU0 EQU3 EQU3 EQU3 EQU3
TBIFG
Interrupt Events
16-10
Timer_B
Timer_B Operation
Capture Mode
The capture mode is selected when CAP = 1. Capture mode is used to record time events. It can be used for speed computations or time measurements. The capture inputs CCIxA and CCIxB are connected to external pins or internal signals and are selected with the CCISx bits. The CMx bits select the capture edge of the input signal as rising, falling, or both. A capture occurs on the selected edge of the input signal. If a capture is performed:
- The timer value is copied into the TBCCRx register - The interrupt flag CCIFG is set
The input signal level can be read at any time via the CCI bit. MSP430x4xx family devices may have different signals connected to CCIxA and CCIxB. Refer to the device-specific data sheet for the connections of these signals. The capture signal can be asynchronous to the timer clock and cause a race condition. Setting the SCS bit synchronizes the capture with the next timer clock. Setting the SCS bit to synchronize the capture signal with the timer clock is recommended. This is illustrated in Figure 1610.
Timer Clock Timer CCI Capture Set TBCCRx CCIFG n2 n1 n n+1 n+2 n+3 n+4
Overflow logic is provided in each capture/compare register to indicate if a second capture was performed before the value from the first capture was read. Bit COV is set when this occurs as shown in Figure 1611. COV must be reset with software.
Timer_B
16-11
Timer_B Operation
No Capture Taken
Capture Taken
Capture
Capture
Capture
Capture Initiated by Software Captures can be initiated by software. The CMx bits can be set for capture on both edges. Software then sets bit CCIS1 = 1 and toggles bit CCIS0 to switch the capture signal between VCC and GND, initiating a capture each time CCIS0 changes state:
MOV XOR #CAP+SCS+CCIS1+CM_3,&TBCCTLx ; Setup TBCCTLx #CCIS0,&TBCCTLx ; TBCCTLx = TBR
Compare Mode
The compare mode is selected when CAP = 0. Compare mode is used to generate PWM output signals or interrupts at specific time intervals. When TBR counts to the value in a TBCLx:
- Interrupt flag CCIFG is set - Internal signal EQUx = 1 - EQUx affects the output according to the output mode
16-12
Timer_B
Timer_B Operation
Compare Latch TBCLx The TBCCRx compare latch, TBCLx, holds the data for the comparison to the timer value in compare mode. TBCLx is buffered by TBCCRx. The buffered compare latch gives the user control over when a compare period updates. The user cannot directly access TBCLx. Compare data is written to each TBCCRx and automatically transferred to TBCLx. The timing of the transfer from TBCCRx to TBCLx is user-selectable with the CLLDx bits as described in Table 162.
11
Grouping Compare Latches Multiple compare latches may be grouped together for simultaneous updates with the TBCLGRPx bits. When using groups, the CLLDx bits of the lowest numbered TBCCRx in the group determine the load event for each compare latch of the group, except when TBCLGRP = 3, as shown in Table 163. The CLLDx bits of the controlling TBCCRx must not be set to zero. When the CLLDx bits of the controlling TBCCRx are set to zero, all compare latches update immediately when their corresponding TBCCRx is written; no compare latches are grouped. Two conditions must exist for the compare latches to be loaded when grouped. First, all TBCCRx registers of the group must be updated, even when new TBCCRx data equals old TBCCRx data. Second, the load event must occur.
10 11
Timer_B
16-13
Timer_B Operation
Output Modes
The output modes are defined by the OUTMODx bits and are described in Table 164. The OUTx signal is changed with the rising edge of the timer clock for all modes except mode 0. Output modes 2, 3, 6, and 7 are not useful for output unit 0, because EQUx = EQU0.
001
Set
010
Toggle/Reset
011
Set/Reset
100
Toggle
101
Reset
110
Toggle/Set
111
Reset/Set
16-14
Timer_B
Timer_B Operation
Output ExampleTimer in Up Mode The OUTx signal is changed when the timer counts up to the TBCLx value, and rolls from TBCL0 to zero, depending on the output mode. An example is shown in Figure 1612 using TBCL0 and TBCL1.
Output Mode 7: Reset/Set EQU0 TBIFG EQU1 EQU0 TBIFG EQU1 EQU0 TBIFG Interrupt Events
Timer_B
16-15
Timer_B Operation
Output ExampleTimer in Continuous Mode The OUTx signal is changed when the timer reaches the TBCLx and TBCL0 values, depending on the output mode, An example is shown in Figure 1613 using TBCL0 and TBCL1.
Output Mode 7: Reset/Set TBIFG EQU1 EQU0 TBIFG EQU1 EQU0 Interrupt Events
16-16
Timer_B
Timer_B Operation
Output Example Timer in Up/Down Mode The OUTx signal changes when the timer equals TBCLx in either count direction and when the timer equals TBCL0, depending on the output mode. An example is shown in Figure 1614 using TBCL0 and TBCL3.
Output Mode 7: Reset/Set TBIFG EQU3 EQU3 EQU3 EQU3 EQU0 EQU0 TBIFG Interrupt Events
Note:
When switching between output modes, one of the OUTMODx bits should remain set during the transition, unless switching to mode 0. Otherwise, output glitching can occur because a NOR gate decodes output mode 0. A safe method for switching between output modes is to use output mode 7 as a transition state:
BIS BIC #OUTMOD_7,&TBCCTLx ; Set output mode=7 #OUTMODx,&TBCCTLx ; Clear unwanted bits
Timer_B
16-17
Timer_B Operation
In capture mode, any CCIFG flag is set when a timer value is captured in the associated TBCCRx register. In compare mode, any CCIFG flag is set when TBR counts to the associated TBCLx value. Software may also set or clear any CCIFG flag. All CCIFG flags request an interrupt when their corresponding CCIE bit and the GIE bit are set. TBCCR0 Interrupt Vector The TBCCR0 CCIFG flag has the highest Timer_B interrupt priority and has a dedicated interrupt vector as shown in Figure 1615. The TBCCR0 CCIFG flag is automatically reset when the TBCCR0 interrupt request is serviced.
Capture CCIE Q
Set
16-18
Timer_B
Timer_B Operation
The following software example shows the recommended use of TBIV for Timer_B3.
; Interrupt handler for TBCCR0 CCIFG. Cycles CCIFG_0_HND ... ; Start of handler Interrupt latency 6 RETI 5
; Interrupt handler for TBIFG, TBCCR1 and TBCCR2 CCIFG. TB_HND ... ; Interrupt latency ADD &TBIV,PC ; Add offset to Jump table RETI ; Vector 0: No interrupt JMP CCIFG_1_HND ; Vector 2: Module 1 JMP CCIFG_2_HND ; Vector 4: Module 2 RETI ; Vector 6 RETI ; Vector 8 RETI ; Vector 10 RETI ; Vector 12 TBIFG_HND ... RETI CCIFG_2_HND ... RETI ; The Module 1 ; interrupt is ; 9 cycles may CCIFG_1_HND ... JMP ; Vector 14: TIMOV Flag ; Task starts here
6 3 5 2 2
handler shows a way to look if any other pending: 5 cycles have to be spent, but be saved if another interrupt is pending ; Vector 6: Module 3 ; Task starts here TB_HND ; Look for pending ints 2
Timer_B
16-19
Timer_B Registers
16-20
Timer_B
Timer_B Registers
7 IDx rw(0)
5 MCx
3 Unused
2 TBCLR w(0)
1 TBIE rw(0)
0 TBIFG rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
Unused TBCLGRP
Unused TBCLx group 00 Each TBCLx latch loads independently 01 TBCL1+TBCL2 (TBCCR1 CLLDx bits control the update) TBCL3+TBCL4 (TBCCR3 CLLDx bits control the update) TBCL5+TBCL6 (TBCCR5 CLLDx bits control the update) TBCL0 independent 10 TBCL1+TBCL2+TBCL3 (TBCCR1 CLLDx bits control the update) TBCL4+TBCL5+TBCL6 (TBCCR4 CLLDx bits control the update) TBCL0 independent 11 TBCL0+TBCL1+TBCL2+TBCL3+TBCL4+TBCL5+TBCL6 (TBCCR1 CLLDx bits control the update) Counter length 00 16-bit, TBR(max) = 0FFFFh 01 12-bit, TBR(max) = 0FFFh 10 10-bit, TBR(max) = 03FFh 11 8-bit, TBR(max) = 0FFh Unused Timer_B clock source select 00 TBCLK 01 ACLK 10 SMCLK 11 Inverted TBCLK Input divider. These bits select the divider for the input clock. 00 /1 01 /2 10 /4 11 /8 Mode control. Setting MCx = 00h when Timer_B is not in use conserves power. 00 Stop mode: the timer is halted 01 Up mode: the timer counts up to TBCL0 10 Continuous mode: the timer counts up to the value set by TBCNTLx 11 Up/down mode: the timer counts up to TBCL0 and down to 0000h
CNTLx
Bits 12-11
Unused TBSSELx
IDx
Bits 7-6
MCx
Bits 5-4
Timer_B
16-21
Unused Timer_B clear. Setting this bit resets TBR, the clock divider, and the count direction. The TBCLR bit is automatically reset and is always read as zero. Timer_B interrupt enable. This bit enables the TBIFG interrupt request. 0 Interrupt disabled 1 Interrupt enabled Timer_B interrupt flag. 0 No interrupt pending 1 Interrupt pending
TBIE
TBIFG
Bit 0
4 TBRx
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
TBRx
Bits 15-0
16-22
Timer_B
Timer_B Registers
4 TBCCRx
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
TBCCRx
Bits 15-0
Timer_B capture/compare register Compare mode: Compare data is written to each TBCCRx and automatically transferred to TBCLx. TBCLx holds the data for the comparison to the timer value in the Timer_B Register, TBR. Capture mode: The Timer_B Register, TBR, is copied into the TBCCRx register when a capture is performed.
Timer_B
16-23
Timer_B Registers
6 OUTMODx
4 CCIE
3 CCI r
2 OUT rw(0)
1 COV rw(0)
0 CCIFG rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
CMx
Bit 15-14
Capture mode 00 No capture 01 Capture on rising edge 10 Capture on falling edge 11 Capture on both rising and falling edges Capture/compare input select. These bits select the TBCCRx input signal. See the device-specific data sheet for specific signal connections. 00 CCIxA 01 CCIxB 10 GND 11 VCC Synchronize capture source. This bit is used to synchronize the capture input signal with the timer clock. 0 Asynchronous capture 1 Synchronous capture Compare latch load. These bits select the compare latch load event. 00 TBCLx loads on write to TBCCRx 01 TBCLx loads when TBR counts to 0 10 TBCLx loads when TBR counts to 0 (up or continuous mode) TBCLx loads when TBR counts to TBCL0 or to 0 (up/down mode) 11 TBCLx loads when TBR counts to TBCLx Capture mode 0 Compare mode 1 Capture mode Output mode. Modes 2, 3, 6, and 7 are not useful for TBCL0, because EQUx = EQU0. 000 OUT bit value 001 Set 010 Toggle/reset 011 Set/reset 100 Toggle 101 Reset 110 Toggle/set 111 Reset/set
CCISx
Bit 13-12
SCS
Bit 11
CLLDx
Bit 10-9
CAP
Bit 8
OUTMODx
Bits 7-5
16-24
Timer_B
Bit 4
Capture/compare interrupt enable. This bit enables the interrupt request of the corresponding CCIFG flag. 0 Interrupt disabled 1 Interrupt enabled Capture/compare input. The selected input signal can be read by this bit. Output. For output mode 0, this bit directly controls the state of the output. 0 Output low 1 Output high Capture overflow. This bit indicates a capture overflow occurred. COV must be reset with software. 0 No capture overflow occurred 1 Capture overflow occurred Capture/compare interrupt flag 0 No interrupt pending 1 Interrupt pending
CCI OUT
Bit 3 Bit 2
COV
Bit 1
CCIFG
Bit 0
Timer_B
16-25
Timer_B Registers
7 0 r0
6 0 r0
5 0 r0
4 0 r0
2 TBIVx
0 0
r(0)
r(0)
r(0)
r0
TBIVx
Bits 15-0
TBIV Contents 00h 02h 04h 06h 08h 0Ah 0Ch 0Eh
Interrupt Source No interrupt pending Capture/compare 1 Capture/compare 2 Capture/compare 3 Capture/compare 4 Capture/compare Capture/compare Timer overflow 5 6
Interrupt Flag TBCCR1 CCIFG TBCCR2 CCIFG TBCCR3 CCIFG TBCCR4 CCIFG TBCCR5 CCIFG TBCCR6 CCIFG TBIFG
Interrupt Priority
Highest
Lowest
16-26
Timer_B
Chapter 17
USART
The universal synchronous/asynchronous receive/transmit (USART) peripheral interface supports two serial modes with one hardware module. This chapter discusses the operation of the asynchronous UART mode. USART0 is implemented on the MSP430x42x and MSP430x43x devices. In addition to USART0, the MSP430x44x devices implement a second identical USART module, USART1. USART1 is also implemented in MSP430FG461x devices.
Topic
Page
17.1 USART Introduction: UART Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-2 17.2 USART Operation: UART Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-4 17.3 USART Registers: UART Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-21
17-1
communication
protocols
for
- Receiver start-edge detection for auto-wake up from LPMx modes - Programmable baud rate with modulation for fractional baud rate support - Status flags for error detection and suppression and address detection - Independent interrupt capability for receive and transmit
Figure 171 shows the USART when configured for UART mode.
17-2
Receive Status
LISTEN 0
MM 1
SYNC 1
RXERR
RXWAKE
SOMI
SSEL1 SSEL0
SPB
CHAR
PEV
PENA UCLKS
0 1
URXD
00 01 10 11 SPB
0 STE
UTXD
WUT
SIMO
TXWAKE
UTXIFGx* Transmit Control SYNC CKPH CKPL SWRST UTXEx* UCLKI TXEPT STC Clock Phase and Polarity UCLK
17-3
2) Initialize all USART registers with SWRST = 1 (including UxCTL) 3) Enable USART module via the MEx SFRs (URXEx and/or UTXEx) 4) Clear SWRST via software (BIC.B #SWRST,&UxCTL)
5) Enable interrupts (optional) via the IEx SFRs (URXIEx and/or UTXIEx) Failure to follow this process may result in unpredictable USART behavior.
17-4
UTXDx/URXDx
First Character Within Block Is Address. It Follows Idle Period of 10 Bits or More
17-5
The URXWIE bit is used to control data reception in the idle-line multiprocessor format. When the URXWIE bit is set, all non-address characters are assembled but not transferred into the UxRXBUF, and interrupts are not generated. When an address character is received, the receiver is temporarily activated to transfer the character to UxRXBUF and sets the URXIFGx interrupt flag. Any applicable error flag is also set. The user can then validate the received address. If an address is received, user software can validate the address and must reset URXWIE to continue receiving data. If URXWIE remains set, only address characters are received. The URXWIE bit is not modified by the USART hardware automatically. For address transmission in idle-line multiprocessor format, a precise idle period can be generated by the USART to generate address character identifiers on UTXDx. The wake-up temporary (WUT) flag is an internal flag double-buffered with the user-accessible TXWAKE bit. When the transmitter is loaded from UxTXBUF, WUT is also loaded from TXWAKE resetting the TXWAKE bit. The following procedure sends out an idle frame to indicate an address character follows: 1) Set TXWAKE, then write any character to UxTXBUF. UxTXBUF must be ready for new data (UTXIFGx = 1). The TXWAKE value is shifted to WUT and the contents of UxTXBUF are shifted to the transmit shift register when the shift register is ready for new data. This sets WUT, which suppresses the start, data, and parity bits of a normal transmission, then transmits an idle period of exactly 11 bits. When two stop bits are used for the idle line, the second stop bit is counted as the first mark bit of the idle period. TXWAKE is reset automatically. 2) Write desired address character to UxTXBUF. UxTXBUF must be ready for new data (UTXIFGx = 1). The new character representing the specified address is shifted out following the address-identifying idle period on UTXDx. Writing the first dont care character to UxTXBUF is necessary in order to shift the TXWAKE bit to WUT and generate an idle-line condition. This data is discarded and does not appear on UTXDx.
17-6
UTXDx/URXDx
For address transmission in address-bit multiprocessor mode, the address bit of a character can be controlled by writing to the TXWAKE bit. The value of the TXWAKE bit is loaded into the address bit of the character transferred from UxTXBUF to the transmit shift register, automatically clearing the TXWAKE bit. TXWAKE must not be cleared by software. It is cleared by USART hardware after it is transferred to WUT or by setting SWRST.
17-7
Framing error
Parity error
Break condition
When URXEIE = 0 and a framing error, parity error, or break condition is detected, no character is received into UxRXBUF. When URXEIE = 1, characters are received into UxRXBUF and any applicable error bit is set. When any of the FE, PE, OE, BRK, or RXERR bits are set, the bit remains set until user software resets it or UxRXBUF is read.
17-8
URXEx = 1 URXEx = 0
Note:
When the receiver is disabled (URXEx = 0), re-enabling the receiver (URXEx = 1) is asynchronous to any data stream that may be present on URXDx at the time. Synchronization can be performed by testing for an idle line condition before receiving a valid character (see URXWIE).
17-9
UTXEx = 0
Not Completed
Transmission Active
UTXEx = 1
When the transmitter is enabled (UTXEx = 1), data should not be written to UxTXBUF unless it is ready for new data indicated by UTXIFGx = 1. Violation can result in an erroneous transmission if data in UxTXBUF is modified as it is being moved into the TX shift register. It is recommended that the transmitter be disabled (UTXEx = 0) only after any active transmission is complete. This is indicated by a set transmitter empty bit (TXEPT = 1). Any data written to UxTXBUF while the transmitter is disabled are held in the buffer but are not moved to the transmit shift register or transmitted. Once UTXEx is set, the data in the transmit buffer is immediately loaded into the transmit shift register and character transmission resumes.
17-10
+0 or 1 Compare (0 or 1)
Timing for each bit is shown in Figure 178. For each bit received, a majority vote is taken to determine the bit value. These samples occur at the N/21, N/2, and N/2+1 BRCLK periods, where N is the number of BRCLKs per BITCLK.
(m= 0) (m= 1)
1 1
N/2 0
1 1
N/2 0
N/21 N/2
BITCLK INT(N/2) + m(= 0) INT(N/2) + m(= 1) Bit Period m: corresponding modulation bit R: Remainder from N/2 division NEVEN: INT(N/2) NODD : INT(N/2) + R(= 1)
17-11
The division factor N is often a non-integer value of which the integer portion can be realized by the prescaler/divider. The second stage of the baud rate generator, the modulator, is used to meet the fractional part as closely as possible. The factor N is then defined as:
n*1 N + UxBR ) 1 n S mi i+0
Where: N: UxBR: i: n: mi : Target division factor 16-bit representation of registers UxBR0 and UxBR1 Bit position in the character Total number of bits in the character Data of each corresponding modulation bit (1 or 0)
The BITCLK can be adjusted from bit to bit with the modulator to meet timing requirements when a non-integer divisor is needed. Timing of each bit is expanded by one BRCLK clock cycle if the modulator bit mi is set. Each time a bit is received or transmitted, the next bit in the modulation control register determines the timing for that bit. A set modulation bit increases the division factor by one while a cleared modulation bit maintains the division factor given by UxBR. The timing for the start bit is determined by UxBR plus m0, the next bit is determined by UxBR plus m1, and so on. The modulation sequence begins with the LSB. When the character is greater than 8 bits, the modulation sequence restarts with m0 and continues until all bits are processed.
17-12
(j ) 1)
UxBR ) S m i * ( j ) 1 )
i+0
100%
With: baud rate: Desired baud rate BRCLK: Input frequency UCLKI, ACLK, or SMCLK j: Bit position - 0 for the start bit, 1 for data bit D0, and so on UxBR: Division factor in registers UxBR1 and UxBR0 For example, the transmit errors for the following conditions are calculated: Baud rate = BRCLK = UxBR = UxMCTL = 2400 32,768 Hz (ACLK) 13, since the ideal division factor is 13.65 6Bh: m7= 0, m6= 1, m5= 1, m4= 0, m3= 1, m2= 0, m1= 1, and m0= 1. The LSB of UxMCTL is used first.
Start bit Error [%] + baud rate ((0 ) 1) UxBR ) 1)1 100% + 2.54% BRCLK Data bit D0 Error [%] + baud rate ((1 ) 1) UxBR ) 2)2 100% + 5.08% BRCLK
Data bit D1 Error [%] + baud rate ((2 ) 1) UxBR ) 2)3 BRCLK Data bit D2 Error [%] + baud rate ((3 ) 1) UxBR ) 3)4 BRCLK baud rate ((4 ) 1) UxBR ) 3)5 Data bit D3 Error [%] + BRCLK Data bit D4 Error [%] + baud rate ((5 ) 1) UxBR ) 4)6 BRCLK Data bit D5 Error [%] + baud rate ((6 ) 1) UxBR ) 5)7 BRCLK Data bit D6 Error [%] + baud rate ((7 ) 1) UxBR ) 5)8 BRCLK Data bit D7 Error [%] + baud rate ((8 ) 1) UxBR ) 6)9 BRCLK Parity bit Error [%] + baud rate ((9 ) 1) UxBR ) 7)10 BRCLK Stop bit 1 Error [%] + baud rate ((10 ) 1) UxBR ) 7)11 BRCLK
100% + 0.29% 100% + 2.83% 100% +*1.95% 100% + 0.59% 100% + 3.13% 100% + *1.66% 100% + 0.88% 100% + 3.42% 100% + *1.37%
The results show the maximum per-bit error to be 5.08% of a BITCLK period.
17-13
i tideal
BRCLK URXDx URXDS
0 t0
1 t1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 8
9 10 11 12 13 14 1 2 3 4 5 6 7
ST ST
t0 Synchronization Error 0.5x BRCLK
D0 D0
t1
D1 D1
t2
tactual
Sample URXDS
The ideal start bit timing tideal(0) is half the baud-rate timing tbaudrate, because the bit is tested in the middle of its period. The ideal baud-rate timing tideal(i) for the remaining character bits is the baud rate timing tbaudrate. The individual bit errors can be calculated by: Error [%] + baud rate BRCLK Where: baud rate is the required baud rate BRCLK is the input frequencyselected for UCLK, ACLK, or SMCLK j = 0 for the start bit, 1 for data bit D0, and so on UxBR is the division factor in registers UxBR1 and UxBR0
m0 ) int UxBR ) i 2
UxBR ) S m i
i+1
* 1 * j
100%
17-14
For example, the receive errors for the following conditions are calculated: Baud rate = 2400 BRCLK = 32,768 Hz (ACLK) UxBR = 13, since the ideal division factor is 13.65 UxMCTL = 6B:m7= 0, m6= 1, m5= 1, m4= 0, m3= 1, m2= 0, m1= 1 and m0= 1 The LSB of UxMCTL is used first.
Start bit Error [%] + baud rate BRCLK
[2x(1 ) 6) ) (0
UxBR ) 0)] * 1 * 0
100% + 2.54%
[2x(1 ) 6) ) (1 Data bit D1 Error [%] + baud rate [2x(1 ) 6) ) (2 BRCLK Data bit D2 Error [%] + baud rate [2x(1 ) 6) ) (3 BRCLK Data bit D3 Error [%] + baud rate [2x(1 ) 6) ) (4 BRCLK Data bit D4 Error [%] + baud rate [2x(1 ) 6) ) (5 BRCLK Data bit D5 Error [%] + baud rate [2x(1 ) 6) ) (6 BRCLK Data bit D6 Error [%] + baud rate [2x(1 ) 6) ) (7 BRCLK baud rate [2x(1 ) 6) ) (8 Data bit D7 Error [%] + BRCLK Parity bit Error [%] + baud rate [2x(1 ) 6) ) (9 BRCLK Stop bit 1 Error [%] + baud rate [2x(1 ) 6) ) (10 BRCLK
Data bit D0 Error [%] + baud rate BRCLK
100% + 5.08% UxBR ) 1)] * 1 * 2 100% + 0.29% UxBR ) 2)] * 1 * 3 100% + 2.83% UxBR ) 2)] * 1 * 4 100% + 1.95% UxBR ) 3)] * 1 * 5 100% + 0.59% UxBR ) 4)] * 1 * 6 100% + 3.13% UxBR ) 4)] * 1 * 7 100% + 1.66% UxBR ) 5)] * 1 * 8 100% + 0.88% UxBR ) 6)] * 1 * 9 100% + 3.42% UxBR ) 6)] * 1 * 10 100% + 1.37%
UxBR ) 1)] * 1 * 1
The results show the maximum per-bit error to be 5.08% of a BITCLK period.
17-15
Table 172.Commonly Used Baud Rates, Baud Rate Data, and Errors
Divide by
Baud Rate
A:
B:
UxBR1
UxBR0
UxMCTL
UxBR1
UxBR0
UxMCTL
0 0 0 0
1B 0D 06 03
03 6B 6F 4A
2 4 7 15
03 01 0 0 0 0 0 0
69 B4 DA 6D 36 1B 0D 09
FF FF 55 03 6B 03 6B 08
2 2 2 2 2 2 4 7
17-16
UTXIEx
Clear
17-17
URXS S
Clear
URXEIE is used to enable or disable erroneous characters from setting URXIFGx. When using multiprocessor addressing modes, URXWIE is used to auto-detect valid address characters and reject unwanted data characters. Two types of characters do not set URXIFGx:
- Erroneous characters when URXEIE = 0 - Non-address characters when URXWIE = 1
When URXEIE = 1 a break condition sets the BRK bit and the URXIFGx flag.
17-18
BIC.B #URXSE,&U0TCTL ; Clear URXS signal BIS.B #URXSE,&U0TCTL ; Re-enable edge detect BIC #SCG0+SCG1,0(SP) ; Enable BRCLK = DCO RETI ;
Note:
When using the receive start-edge detect feature, a break condition cannot be detected when the BRCLK source is off.
17-19
Receive-Start Edge Detect Conditions When URXSE = 1, glitch suppression prevents the USART from being accidentally started. Any low-level on URXDx shorter than the deglitch time t (approximately 300 ns) is ignored by the USART and no interrupt request is generated (see Figure 1712). See the device-specific data sheet for parameters.
URXDx URXS t
When a glitch is longer than t or a valid start bit occurs on URXDx, the USART receive operation is started and a majority vote is taken as shown in Figure 1713. If the majority vote fails to detect a start bit, the USART halts character reception. If character reception is halted, an active BRCLK is not necessary. A time-out period longer than the character receive duration can be used by software to indicate that a character was not received in the expected time, and the software can disable BRCLK.
URXDx URXS t
17-20
Note: Modifying SFR bits To avoid modifying control bits of other modules, it is recommended to set or clear the IEx and IFGx bits using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions.
17-21
PENA
Bit 7
Parity enable 0 Parity disabled 1 Parity enabled. Parity bit is generated (UTXDx) and expected (URXDx). In address-bit multiprocessor mode, the address bit is included in the parity calculation. Parity select. PEV is not used when parity is disabled. 0 Odd parity 1 Even parity Stop bit select. Number of stop bits transmitted. The receiver always checks for one stop bit. 0 One stop bit 1 Two stop bits Character length. Selects 7-bit or 8-bit character length. 0 7-bit data 1 8-bit data Listen enable. The LISTEN bit selects loopback mode. 0 Disabled 1 Enabled. UTXDx is internally fed back to the receiver. Synchronous mode enable 0 UART mode 1 SPI Mode Multiprocessor mode select 0 Idle-line multiprocessor protocol 1 Address-bit multiprocessor protocol Software reset enable 0 Disabled. USART reset released for operation 1 Enabled. USART logic held in reset state
PEV
Bit 6
SPB
Bit 5
CHAR
Bit 4
LISTEN
Bit 3
SYNC
Bit 2
MM
Bit 1
SWRST
Bit 0
17-22
Unused CKPL
Bit 7 Bit 6
Unused Clock polarity select 0 UCLKI = UCLK 1 UCLKI = inverted UCLK Source select. These bits select the BRCLK source clock. 00 UCLKI 01 ACLK 10 SMCLK 11 SMCLK UART receive start-edge. The bit enables the UART receive start-edge feature. 0 Disabled 1 Enabled Transmitter wake 0 Next frame transmitted is data 1 Next frame transmitted is an address Unused Transmitter empty flag 0 UART is transmitting data and/or data is waiting in UxTXBUF 1 Transmitter shift register and UxTXBUF are empty or SWRST = 1
SSELx
Bits 5-4
URXSE
Bit 3
TXWAKE
Bit 2
Unused TXEPT
Bit 1 Bit 0
17-23
FE
Bit 7
Framing error flag 0 No error 1 Character received with low stop bit Parity error flag. When PENA = 0, PE is read as 0. 0 No error 1 Character received with parity error Overrun error flag. This bit is set when a character is transferred into UxRXBUF before the previous character was read. 0 No error 1 Overrun error occurred Break detect flag 0 No break condition 1 Break condition occurred Receive erroneous-character interrupt-enable 0 Erroneous characters rejected and URXIFGx is not set 1 Erroneous characters received set URXIFGx Receive wake-up interrupt-enable. This bit enables URXIFGx to be set when an address character is received. When URXEIE = 0, an address character does not set URXIFGx if it is received with errors. 0 All received characters set URXIFGx 1 Only received address characters set URXIFGx Receive wake-up flag 0 Received character is data 1 Received character is an address Receive error flag. This bit indicates a character was received with error(s). When RXERR = 1, on or more error flags (FE,PE,OE, BRK) is also set. RXERR is cleared when UxRXBUF is read. 0 No receive errors detected 1 Receive error detected
PE
Bit 6
OE
Bit 5
BRK
Bit 4
URXEIE
Bit 3
URXWIE
Bit 2
RXWAKE
Bit 1
RXERR
Bit 0
17-24
UxBRx
The valid baud-rate control range is 3 UxBR < 0FFFFh, where UxBR = {UxBR1+UxBR0}. Unpredictable receive and transmit timing occurs if UxBR < 3.
UxMCTLx
Bits 70
17-25
UxRXBUFx
Bits 70
The receive-data buffer is user accessible and contains the last received character from the receive shift register. Reading UxRXBUF resets the receive-error bits, the RXWAKE bit, and URXIFGx. In 7-bit data mode, UxRXBUF is LSB justified and the MSB is always reset.
UxTXBUFx
Bits 70
The transmit data buffer is user accessible and holds the data waiting to be moved into the transmit shift register and transmitted on UTXDx. Writing to the transmit data buffer clears UTXIFGx. The MSB of UxTXBUF is not used for 7-bit data and is reset.
17-26
UTXE0
Bit 7
USART0 transmit enable. This bit enables the transmitter for USART0. 0 Module not enabled 1 Module enabled USART0 receive enable. This bit enables the receiver for USART0. 0 Module not enabled 1 Module enabled These bits may be used by other modules. See device-specific data sheet.
URXE0
Bit 6
Bits 5-0
Bits 7-6
UTXE1
These bits may be used by other modules. See device-specific data sheet. USART1 transmit enable. This bit enables the transmitter for USART1. 0 Module not enabled 1 Module enabled USART1 receive enable. This bit enables the receiver for USART1. 0 Module not enabled 1 Module enabled These bits may be used by other modules. See device-specific data sheet.
Bit 5
URXE1
Bit 4
Bits 3-0
17-27
UTXIE0
Bit 7
USART0 transmit interrupt enable. This bit enables the UTXIFG0 interrupt. 0 Interrupt not enabled 1 Interrupt enabled USART0 receive interrupt enable. This bit enables the URXIFG0 interrupt. 0 Interrupt not enabled 1 Interrupt enabled These bits may be used by other modules. See device-specific data sheet.
URXIE0
Bit 6
Bits 5-0
Bits 7-6
UTXIE1
These bits may be used by other modules. See device-specific data sheet. USART1 transmit interrupt enable. This bit enables the UTXIFG1 interrupt. 0 Interrupt not enabled 1 Interrupt enabled USART1 receive interrupt enable. This bit enables the URXIFG1 interrupt. 0 Interrupt not enabled 1 Interrupt enabled These bits may be used by other modules. See device-specific data sheet.
Bit 5
URXIE1
Bit 4
Bits 3-0
17-28
UTXIFG0
Bit 7
USART0 transmit interrupt flag. UTXIFG0 is set when U0TXBUF is empty. 0 No interrupt pending 1 Interrupt pending USART0 receive interrupt flag. URXIFG0 is set when U0RXBUF has received a complete character. 0 No interrupt pending 1 Interrupt pending These bits may be used by other modules. See device-specific data sheet.
URXIFG0
Bit 6
Bits 5-0
Bits 7-6
UTXIFG1
These bits may be used by other modules. See device-specific data sheet. USART1 transmit interrupt flag. UTXIFG1 is set when U1TXBUF empty. 0 No interrupt pending 1 Interrupt pending USART1 receive interrupt flag. URXIFG1 is set when U1RXBUF has received a complete character. 0 No interrupt pending 1 Interrupt pending These bits may be used by other modules. See device-specific data sheet.
Bit 5
URXIFG1
Bit 4
Bits 3-0
17-29
17-30
Chapter 18
Topic
Page
18.1 USART Introduction: SPI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-2 18.2 USART Operation: SPI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-4 18.3 USART Registers: SPI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-13
18-1
Figure 181 shows the USART when configured for SPI mode.
18-2
Receive Status
LISTEN 0
MM 1
SYNC 1
RXERR
RXWAKE
SOMI
SSEL1 SSEL0
SPB
CHAR
PEV
PENA UCLKS
0 1
URXD
00 01 10 11 SPB
0 STE
UTXD
WUT
SIMO
TXWAKE
UTXIFGx* Transmit Control SYNC CKPH CKPL SWRST USPIEx* TXEPT UCLKI STC Clock Phase and Polarity UCLK
18-3
Slave in, master out Master mode: SIMO is the data output line. Slave mode: SIMO is the data input line. Slave out, master in Master mode: SOMI is the data input line. Slave mode: SOMI is the data output line. USART SPI clock Master mode: UCLK is an output. Slave mode: UCLK is an input. Slave transmit enable. Used in 4-pin mode to allow multiple masters on a single bus. Not used in 3-pin mode. 4-Pin master mode: When STE is high, SIMO and UCLK operate normally. When STE is low, SIMO and UCLK are set to the input direction. 4-pin slave mode: When STE is high, RX/TX operation of the slave is disabled and SOMI is forced to the input direction. When STE is low, RX/TX operation of the slave is enabled and SOMI operates normally.
- SOMI
- UCLK
- STE
18-4
18.2.2 Master Mode Figure 182. USART Master and External Slave
MASTER
SIMO
SIMO
SLAVE
SOMI
SCLK
Figure 182 shows the USART as a master in both 3-pin and 4-pin configurations. The USART initiates a data transfer when data is moved to the transmit data buffer UxTXBUF. The UxTXBUF data is moved to the TX shift register when the TX shift register is empty, initiating data transfer on SIMO starting with the most significant bit. Data on SOMI is shifted into the receive shift register on the opposite clock edge, starting with the most significant bit. When the character is received, the receive data is moved from the RX shift register to the received data buffer UxRXBUF and the receive interrupt flag, URXIFGx, is set, indicating the RX/TX operation is complete. A set transmit interrupt flag, UTXIFGx, indicates that data has moved from UxTXBUF to the TX shift register and UxTXBUF is ready for new data. It does not indicate RX/TX completion. In master mode, the completion of an active transmission is indicated by a set transmitter empty bit TXEPT = 1. To receive data into the USART in master mode, data must be written to UxTXBUF because receive and transmit operations operate concurrently.
handled by the user A low STE signal does not reset the USART module. The STE input signal is not used in 3-pin master mode.
18-5
18.2.3 Slave Mode Figure 183. USART Slave and External Master
MASTER
SIMO
SIMO
SLAVE
SOMI
UCLK
Figure 183 shows the USART as a slave in both 3-pin and 4-pin configurations. UCLK is used as the input for the SPI clock and must be supplied by the external master. The data transfer rate is determined by this clock and not by the internal baud rate generator. Data written to UxTXBUF and moved to the TX shift register before the start of UCLK is transmitted on SOMI. Data on SIMO is shifted into the receive shift register on the opposite edge of UCLK and moved to UxRXBUF when the set number of bits are received. When data is moved from the RX shift register to UxRXBUF, the URXIFGx interrupt flag is set, indicating that data has been received. The overrun error bit, OE, is set when the previously received data is not read from UxRXBUF before new data is moved to UxRXBUF.
A high STE signal does not reset the USART module. The STE input signal is not used in 3-pin slave mode.
18-6
Transmit Enable
When USPIEx = 0, any further write to UxTXBUF does not transmit. Data written to UxTXBUF begin to transmit when USPIEx = 1 and the BRCLK source is active. Figure 184 and Figure 185 show the transmit enable state diagrams.
USPIEx = 0
Not Completed
USPIEx = 1 Transmit Disable USPIEx = 0 SWRST PUC USPIEx = 0 And Last Buffer Entry Is Transmitted
Transmission Active
USPIEx = 1 USPIEx = 0
Not Completed
Transmission Active
USPIEx = 0
18-7
Receive Enable
The SPI receive enable state diagrams are shown in Figure 186 and Figure 187. When USPIEx = 0, UCLK is disabled from shifting data into the RX shift register.
USPIEx = 0
Not Completed
USPIEx = 1 USPIEx = 0
USPIEx = 0
Not Completed
USPIEx = 0
18-8
... UxBR1
... UxBR0 8
00 01 10 11 BRCLK
R Q0 Toggle FF R BITCLK
Compare (0 or 1)
The 16-bit value of UxBR0+UxBR1 is the division factor of the USART clock source, BRCLK. The maximum baud rate that can be generated in master mode is BRCLK/2. The maximum baud rate that can be generated in slave mode is BRCLK The modulator in the USART baud rate generator is not used for SPI mode and is recommended to be set to 000h. The UCLK frequency is given by: Baud rate = BRCLK with UxBR= [UxBR1, UxBR0] UxBR
18-9
CKPH CKPL 0 0 1 1 0 1 0 1
0 1
X X
MSB MSB
LSB LSB
18-10
UTXIEx SYNC = 1
Clear
Note:
Data written to UxTXBUF when UTXIFGx = 0 and USPIEx = 1 may result in erroneous data transmission.
18-11
URXS
SYNC = 1
SWRST = 1 USPIEx = 0 USPIEx = 1 and URXIEx = 1 and GIE = 1 and Priority Valid Interrupt Service Started, GIE = 0 URXIFGx = 0
PUC
GIE = 0
18-12
Note:
To avoid modifying control bits for other modules, it is recommended to set or clear the IEx and IFGx bits using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions.
18-13
Unused I2C
Bits 76 Bit 5
Unused I2C mode enable. This bit selects I2C or SPI operation when SYNC = 1. 0 SPI mode 1 I2C mode Character length 0 7-bit data 1 8-bit data Listen enable. The LISTEN bit selects the loopback mode 0 Disabled 1 Enabled. The transmit signal is internally fed back to the receiver Synchronous mode enable 0 UART mode 1 SPI mode Master mode 0 USART is slave 1 USART is master Software reset enable 0 Disabled. USART reset released for operation 1 Enabled. USART logic held in reset state
CHAR
Bit 4
LISTEN
Bit 3
SYNC
Bit 2
MM
Bit 1
SWRST
Bit 0
18-14
CKPH
Bit 7
Clock phase select. 0 Data is changed on the first UCLK edge and captured on the following edge. 1 Data is captured on the first UCLK edge and changed on the following edge. Clock polarity select 0 The inactive state is low. 1 The inactive state is high. Source select. These bits select the BRCLK source clock. 00 External UCLK (valid for slave mode only) 01 ACLK (valid for master mode only) 10 SMCLK (valid for master mode only) 11 SMCLK (valid for master mode only) Unused Unused Slave transmit control. 0 4-pin SPI mode: STE enabled. 1 3-pin SPI mode: STE disabled. Transmitter empty flag. The TXEPT flag is not used in slave mode. 0 Transmission active and/or data waiting in UxTXBUF 1 UxTXBUF and TX shift register are empty
CKPL
Bit 6
SSELx
Bits 5-4
TXEPT
Bit 0
18-15
FE
Bit 7
Framing error flag. This bit indicates a bus conflict when MM = 1 and STC = 0. FE is unused in slave mode. 0 No conflict detected 1 A negative edge occurred on STE, indicating bus conflict Unused Overrun error flag. This bit is set when a character is transferred into UxRXBUF before the previous character was read. OE is automatically reset when UxRXBUF is read, when SWRST = 1, or can be reset by software. 0 No error 1 Overrun error occurred Unused Unused Unused Unused Unused
Undefined OE
Bit 6 Bit 5
18-16
UxBRx
The baud-rate generator uses the content of {UxBR1+UxBR0} to set the baud rate. Unpredictable SPI operation occurs if UxBR < 2.
UxMCTLx
Bits 70
The modulation control register is not used for SPI mode and should be set to 000h.
18-17
UxRXBUFx
Bits 70
The receive-data buffer is user accessible and contains the last received character from the receive shift register. Reading UxRXBUF resets the OE bit and URXIFGx flag. In 7-bit data mode, UxRXBUF is LSB justified and the MSB is always reset.
UxTXBUFx
Bits 70
The transmit data buffer is user accessible and contains current data to be transmitted. When seven-bit character-length is used, the data should be MSB justified before being moved into UxTXBUF. Data is transmitted MSB first. Writing to UxTXBUF clears UTXIFGx.
18-18
Bit 7
USPIE0
This bit may be used by other modules. See device-specific data sheet. USART0 SPI enable. This bit enables the SPI mode for USART0. 0 Module not enabled 1 Module enabled These bits may be used by other modules. See device-specific data sheet.
Bit 6
Bits 5-0
Bits 7-5
USPIE1
These bits may be used by other modules. See device-specific data sheet. USART1 SPI enable. This bit enables the SPI mode for USART1. 0 Module not enabled 1 Module enabled These bits may be used by other modules. See device-specific data sheet.
Bit 4
Bits 3-0
18-19
UTXIE0
Bit 7
USART0 transmit interrupt enable. This bit enables the UTXIFG0 interrupt. 0 Interrupt not enabled 1 Interrupt enabled USART0 receive interrupt enable. This bit enables the URXIFG0 interrupt. 0 Interrupt not enabled 1 Interrupt enabled These bits may be used by other modules. See device-specific data sheet.
URXIE0
Bit 6
Bits 5-0
Bits 7-6
UTXIE1
These bits may be used by other modules. See device-specific data sheet. USART1 transmit interrupt enable. This bit enables the UTXIFG1 interrupt. 0 Interrupt not enabled 1 Interrupt enabled USART1 receive interrupt enable. This bit enables the URXIFG1 interrupt. 0 Interrupt not enabled 1 Interrupt enabled These bits may be used by other modules. See device-specific data sheet.
Bit 5
URXIE1
Bit 4
Bits 3-0
18-20
UTXIFG0
Bit 7
USART0 transmit interrupt flag. UTXIFG0 is set when U0TXBUF is empty. 0 No interrupt pending 1 Interrupt pending USART0 receive interrupt flag. URXIFG0 is set when U0RXBUF has received a complete character. 0 No interrupt pending 1 Interrupt pending These bits may be used by other modules. See device-specific data sheet.
URXIFG0
Bit 6
Bits 5-0
Bits 7-6
UTXIFG1
These bits may be used by other modules. See device-specific data sheet. USART1 transmit interrupt flag. UTXIFG1 is set when U1TXBUF is empty. 0 No interrupt pending 1 Interrupt pending USART1 receive interrupt flag. URXIFG1 is set when U1RXBUF has received a complete character. 0 No interrupt pending 1 Interrupt pending These bits may be used by other modules. See device-specific data sheet.
Bit 5
URXIFG1
Bit 4
Bits 3-0
18-21
18-22
Chapter 19
Universal
The universal serial communication interface (USCI) supports multiple serial communication modes with one hardware module. This chapter discusses the operation of the asynchronous UART mode.
Topic
Page
19.1 USCI Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-2 19.2 USCI Introduction: UART Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-3 19.3 USCI Operation: UART Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-5 19.4 USCI Registers: UART Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-27
19-1
USCI Overview
UART mode Pulse shaping for IrDA communications Automatic baud rate detection for LIN communications SPI mode
19-2
communication
protocols
for
- Receiver start-edge detection for auto-wake up from LPMx modes - Programmable baud rate with modulation for fractional baud rate support - Status flags for error detection and suppression - Status flags for address detection - Independent interrupt capability for receive and transmit
Figure 191 shows the USCI_Ax when configured for UART mode.
19-3
Receive Shift Register UCPEN UCPAR UCABEN UCSSELx Receive Baudrate Generator UC0BRx UC0CLK ACLK SMCLK SMCLK 00 01 10 11 4 BRCLK 16 Prescaler/Divider Modulator 3 UCMSB UC7BIT
Receive Clock
Transmit Clock
UCPEN UCPAR
UCMSB UC7BIT
UCIREN
Transmit Shift Register IrDA Encoder Transmit Buffer UC 0TXBUF 6 UCIRTXPLx Transmit State Machine Set UC0TXIFG UCTXBRK UCTXADDR 2 UCMODEx UCSPB
0 1 UC0TX
19-4
19-5
UCAxTXD/RXD
UCAxTXD/RXD
ST
Address
SP ST
Data
SP
ST
Data
SP
First Character Within Block Is Address. It Follows Idle Period of 10 Bits or More
19-6
The UCDORM bit is used to control data reception in the idle-line multiprocessor format. When UCDORM = 1, all non-address characters are assembled but not transferred into the UCAxRXBUF, and interrupts are not generated. When an address character is received, the character is transferred into UCAxRXBUF, UCAxRXIFG is set, and any applicable error flag is set when UCRXEIE = 1. When UCRXEIE = 0 and an address character is received but has a framing error or parity error, the character is not transferred into UCAxRXBUF and UCAxRXIFG is not set. If an address is received, user software can validate the address and must reset UCDORM to continue receiving data. If UCDORM remains set, only address characters will be received. When UCDORM is cleared during the reception of a character the receive interrupt flag will be set after the reception completed. The UCDORM bit is not modified by the USCI hardware automatically. For address transmission in idle-line multiprocessor format, a precise idle period can be generated by the USCI to generate address character identifiers on UCAxTXD. The double-buffered UCTXADDR flag indicates if the next character loaded into UCAxTXBUF is preceded by an idle line of 11 bits. UCTXADDR is automatically cleared when the start bit is generated.
19-7
19-8
UCAxTXD/UCAxRXD
ST
Address
1 SP ST
Data
SP
ST
Data
0 SP
19-9
For LIN conformance the character format should be set to 8 data bits, LSB first, no parity and one stop bit. No address bit is available. The synch field consists of the data 055h inside a byte field as shown in Figure 196. The synchronization is based on the time measurement between the first falling edge and the last falling edge of the pattern. The transmit baud rate generator is used for the measurement if automatic baud rate detection is enabled by setting UCABDEN. Otherwise, the pattern is received but not measured. The result of the measurement is transferred into the baud rate control registers UCAxBR0, UCAxBR1, and UCAxMCTL. If the length of the synch field exceeds the measurable time the synch timeout error flag UCSTOE is set.
Start 0 Bit
Stop Bit
The UCDORM bit is used to control data reception in this mode. When UCDORM is set, all characters are received but not transferred into the UCAxRXBUF, and interrupts are not generated. When a break/synch field is detected the UCBRK flag is set. The character following the break/synch field is transferred into UCAxRXBUF and the UCAxRXIFG interrupt flag is set. Any applicable error flag is also set. If the UCBRKIE bit is set, reception of the break/synch sets the UCAxRXIFG. The UCBRK bit is reset by user software or by reading the receive buffer UCAxRXBUF.
19-10
When a break/synch field is received, user software must reset UCDORM to continue receiving data. If UCDORM remains set, only the character after the next reception of a break/synch field will be received. The UCDORM bit is not modified by the USCI hardware automatically. When UCDORM = 0 all received characters will set the receive interrupt flag UCAxRXIFG. If UCDORM is cleared during the reception of a character the receive interrupt flag will be set after the reception is complete. The counter used to detect the baud rate is limited to 07FFFh (32767) counts. This means the minimum baud rate detectable is 488 Baud in oversampling mode and 30 Baud in low-frequency mode. The automatic baud rate detection mode can be used in a full-duplex communication system with some restrictions. The USCI can not transmit data while receiving the break/sync field and if a 0h byte with framing error is received any data transmitted during this time gets corrupted. The latter case can be discovered by checking the received data and the UCFE bit.
19-11
IrDA Encoding
The encoder sends a pulse for every zero bit in the transmit bit stream coming from the UART as shown in Figure 197. The pulse duration is defined by UCIRTXPLx bits specifying the number of half clock periods of the clock selected by UCIRTXCLK.
UART
IrDA
To set the pulse time of 3/16 bit period required by the IrDA standard the BITCLK16 clock is selected with UCIRTXCLK = 1 and the pulse length is set to 6 half clock cycles with UCIRTXPLx = 6 1 = 5. When UCIRTXCLK = 0, the pulse length tPULSE is based on BRCLK and is calculated as follows: UCIRTXPLx + t PULSE 2 f BRCLK * 1
When the pulse length is based on BRCLK the prescaler UCBRx must to be set to a value greater or equal to 5.
IrDA Decoding
The decoder detects high pulses when UCIRRXPL = 0. Otherwise it detects low pulses. In addition to the analog deglitch filter an additional programmable digital filter stage can be enabled by setting UCIRRXFE. When UCIRRXFE is set, only pulses longer than the programmed filter length are passed. Shorter pulses are discarded. The equation to program the filter length UCIRRXFLx is: UCIRRXFLx + (t PULSE * t WAKE) where: tPULSE: tWAKE: Minimum receive pulse width Wake time from any low power mode. Zero when MSP430 is in active mode. 2 f BRCLK * 4
19-12
Framing error
UCFE
A framing error occurs when a low stop bit is detected. When two stop bits are used, both stop bits are checked for framing error. When a framing error is detected, the UCFE bit is set. A parity error is a mismatch between the number of 1s in a character and the value of the parity bit. When an address bit is included in the character, it is included in the parity calculation. When a parity error is detected, the UCPE bit is set. An overrun error occurs when a character is loaded into UCAxRXBUF before the prior character has been read. When an overrun occurs, the UCOE bit is set. When not using automatic baud rate detection, a break is detected when all data, parity, and stop bits are low. When a break condition is detected, the UCBRK bit is set. A break condition can also set the interrupt flag UCAxRXIFG if the break interrupt enable UCBRKIE bit is set.
Parity error
UCPE
Receive overrun
UCOE
Break condition
UCBRK
When UCRXEIE = 0 and a framing error, or parity error is detected, no character is received into UCAxRXBUF. When UCRXEIE = 1, characters are received into UCAxRXBUF and any applicable error bit is set. When UCFE, UCPE, UCOE, UCBRK, or UCRXERR is set, the bit remains set until user software resets it or UCAxRXBUF is read. UCOE must be reset by reading UCAxRXBUF. Otherwise it will not function properly. To detect overflows reliably the following flow is recommended. After a character was received and UCAxRXIFG is set, first read UCAxSTAT to check the error flags including the overflow flag UCOE. Read UCAxRXBUF next. This will clear all
19-13
error flags except UCOE if UCAxRXBUF was overwritten between the read access to UCAxSTAT and to UCAxRXBUF. So the UCOE flag should be checked after reading UCAxRXBUF to detect this condition. Note, in this case the UCRXERR flag is not set.
URXDx URXS t
When a glitch is longer than t, or a valid start bit occurs on UCAxRXD, the USCI receive operation is started and a majority vote is taken as shown in Figure 199. If the majority vote fails to detect a start bit the USCI halts character reception.
19-14
URXDx URXS t
19-15
BITCLK INT(N/2) + m(= 0) INT(N/2) + m(= 1) Bit Period m: corresponding modulation bit R: Remainder from N/2 division NEVEN: INT(N/2) NODD : INT(N/2) + R(= 1)
Modulation is based on the UCBRSx setting as shown in Table 192. A 1 in the table indicates that m = 1 and the corresponding BITCLK period is one BRCLK period longer than a BITCLK period with m = 0. The modulation wraps around after 8 bits but restarts with each new start bit.
19-16
generation. In this mode, the maximum USCI baud rate is 1/16 the UART source clock frequency BRCLK. When UCBRx is set to 0 or 1 the first prescaler and modulator stage is bypassed and BRCLK is equal to BITCLK16. Modulation for BITCLK16 is based on the UCBRFx setting as shown in Table 193. A 1 in the table indicates that the corresponding BITCLK16 period is one BRCLK period longer than the periods m=0. The modulation restarts with each new bit timing. Modulation for BITCLK is based on the UCBRSx setting as shown in Table 192 as previously described.
19-17
The division factor N is often a non-integer value thus at least one divider and one modulator stage is used to meet the factor as closely as possible. If N is equal or greater than 16 the oversampling baud rate generation mode can be chosen by setting UCOS16.
19-18
16 ) m UCBRSx[i] @ UCBRx )
m
15 j+0
UCBRFx
[j]
m
15 j+0
UCBRFx
[j]:
Sum of ones from the corresponding row in Table 193 Modulation of bit i from Table 192
m UCBRSx[i]:
This results in an end-of-bit time tbit,TX[i] equal to the sum of all previous and the current bit times: t bit,TX[i] +
T
i j+0
bit,TX
[j]
To calculate bit error, this time is compared to the ideal bit time tbit,ideal,TX[i]: t bit,ideal,TX[i] + 1 (i ) 1) Baudrate
This results in an error normalized to one ideal bit time (1/baudrate): ErrorTX[i] + t bit,TX[i] * t bit,ideal,TX[i] @ Baudrate @ 100%
19-19
i tideal
BRCLK UCAxRXD RXD synch.
0 t0
1 t1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 8
9 10 11 12 13 14 1 2 3 4 5 6 7
ST ST
t0 Synchronization Error 0.5x BRCLK
D0 D0
t1
D1 D1
t2
tactual
Sample RXD synch. Majority Vote Taken Majority Vote Taken Majority Vote Taken
The ideal sampling time t bit,ideal,RX[i] is in the middle of a bit period: t bit,ideal,RX[i] + 1 (i ) 0.5) Baudrate
The real sampling time t bit,RX[i] is equal to the sum of all previous bits according to the formulas shown in the transmit timing section, plus one half BITCLK for the current bit i, plus the synchronization error tSYNC. This results in the following t bit,RX[i] for the low-frequency baud rate mode t bit,RX[i] + t SYNC ) where: T bit,RX[i] + m UCBRSx[i]: 1 UCBRx ) m UCBRSx[i] f BRCLK Modulation of bit i from Table 192
T
i*1 j+0
bit,RX
[j] )
19-20
For the oversampling baud rate mode the sampling time t bit,RX[i] of bit i is calculated by: t bit,RX[i] + t SYNC ) ) 1 f BRCLK
T
i*1 j+0
bit,RX
[j]
7)m UCBRSx
8 ) m UCBRSx[i] @ UCBRx )
j+0
[i]
m UCBRFx[j]
where: T bit,RX[i] +
7)m [i] UCBRSx
1 f BRCLK
16 ) m UCBRSx[i] @ UCBRx )
m
15 j+0
UCBRFx
[j]
j+0
m UCBRFx[j]:
Sum of ones from columns 0 7 ) m UCBRSx[i] from the corresponding row in Table 193
m UCBRSx[i]:
This results in an error normalized to one ideal bit time (1/baudrate) according to the following formula: ErrorRX[i] + t bit,RX[i] * t bit,ideal,RX[i] @ Baudrate @ 100%
19-21
UCBRx 27 13 6 3 104 52 26 17 8 109 54 27 18 9 416 208 104 69 34 17 833 416 208 138 69 34 17 1250 625 312 208 104 52 26
UCBRSx 2 6 7 3 1 0 0 3 6 2 5 2 1 1 6 3 1 4 6 3 2 6 3 7 4 6 3 0 0 4 2 1 0 0
UCBRFx 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Max TX Error [%] 2.8 4.8 12.1 21.1 0.5 1.8 1.8 2.1 7.8 0.2 1.1 2.8 4.6 1.1 0.2 0.2 0.5 0.6 2.1 2.1 0.1 0.2 0.2 0.7 0.6 2.1 2.1 0 0 0.2 0.5 0.5 1.8 1.8 1.4 6.0 5.7 15.2 0.6 0 0 4.8 6.4 0.7 1.0 1.4 3.3 10.7 0.2 0.5 0.6 0.8 0.6 4.8 0 0.2 0.5 0 0.8 0.6 4.8 0 0 0 0.2 0.6 0 0
Max RX Error [%] 5.9 9.7 13.4 44.3 0.9 2.6 3.6 6.8 9.7 1.0 1.5 5.9 6.8 11.5 0.2 0.3 0.9 1.8 2.5 6.8 0.2 0.2 0.3 0.8 1.8 2.5 6.8 0.05 0.2 0.2 0.6 0.9 2.6 3.6 2.0 8.3 19.0 21.3 1.2 0.9 1.8 5.8 16.1 0.8 2.5 2.0 6.6 11.3 0.4 0.8 1.2 1.1 3.1 5.8 0.1 0.4 0.8 0.6 1.1 3.1 5.8 0.05 0 0.2 0.5 1.2 0.9 1.8
19-22
Table 194.Commonly Used Baud Rates, Settings, and Errors, UCOS16 = 0 (Continued)
BRCLK Frequency [Hz] 16,000,000 16,000,000 16,000,000 16,000,000 16,000,000 16,000,000 16,000,000 Baud Rate [Baud] 9600 19200 38400 57600 115200 230400 460800
UCBRSx 6 2 6 7 7 4 6
UCBRFx 0 0 0 0 0 0 0
Max TX Error [%] 0.05 0.1 0.2 0.3 0.7 0.6 2.1 0.05 0.05 0.2 0.3 0 0.8 0.6
Max RX Error [%] 0.05 0.2 0.2 0.5 0.8 1.8 2.5 0.1 0.1 0.4 0.4 0.6 1.1 3.1
19-23
UCBRx 6 3 6 3 26 13 6 4 2 52 26 13 8 4 2 78 39 19 13 6 3 104 52 26 17 8 4 2
UCBRSx 0 0 0 1 0 0 0 5 3 0 0 0 0 5 3 0 0 0 0 0 0 0 0 0 0 0 5 3
UCBRFx 8 4 13 6 1 0 8 3 2 1 1 0 11 3 2 2 1 8 0 8 4 3 1 1 6 11 3 2
Max. TX Error [%] 1.8 1.8 2.3 4.6 0 1.8 1.8 3.5 2.1 0.4 0 1.8 0 3.5 2.1 0 0 1.8 1.8 1.8 1.8 0 0.4 0 0 0 3.5 2.1 0 0 0 3.2 0.9 0 0 3.2 4.8 0 0.9 0 0.88 3.2 4.8 0 0 0 0 0 0 0.2 0 0.9 0.9 0.9 3.2 4.8
Max. RX Error [%] 2.2 2.6 2.2 5.0 0 1.9 2.2 1.8 2.5 0.4 0 1.9 0 1.8 2.5 0.05 0 1.8 1.9 2.2 2.6 0 0.4 0 0.1 0 1.8 2.5 0.4 0.9 0.8 4.7 1.1 0.2 0.4 6.4 7.3 0.1 1.1 0.2 1.6 6.4 7.3 0.05 0.2 0.1 0.2 0.4 0.9 0.3 0.1 1.1 1.0 1.6 6.4 7.3
19-24
19.3.15 Using the USCI Module in UART Mode with Low-Power Modes
The USCI module provides automatic clock activation for SMCLK for use with low-power modes. When SMCLK is the USCI clock source, and is inactive because the device is in a low-power mode, the USCI module automatically activates it when needed, regardless of the control-bit settings for the clock source. The clock remains active until the USCI module returns to its idle condition. After the USCI module returns to the idle condition, control of the clock source reverts to the settings of its control bits. Automatic clock activation is not provided for ACLK. When the USCI module activates an inactive clock source, the clock source becomes active for the whole device and any peripheral configured to use the clock source may be affected. For example, a timer using SMCLK will increment while the USCI module forces SMCLK active.
UCAxRXIFG flag.
19-25
The following software example shows an extract of an interrupt service routine to handle data transmit interrupts from USCI_A0 in either UART or SPI mode and USCI_B0 in SPI mode.
USCIA0_TX_USCIB0_TX_ISR BIT.B #UCA0TXIFG, &IFG2 ; USCI_A0 Transmit Interrupt? JNZ USCIA0_TX_ISR USCIB0_TX_ISR ; Write UCB0TXBUF (clears UCB0TXIFG) ... RETI USCIA0_TX_ISR ; Write UCA0TXBUF (clears UCA0TXIFG) ... RETI
19-26
Note: Modifying SFR bits To avoid modifying control bits of other modules, it is recommended to set or clear the IEx and IFGx bits using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions.
19-27
UCPEN
Bit 7
Parity enable 0 Parity disabled. 1 Parity enabled. Parity bit is generated (UCAxTXD) and expected (UCAxRXD). In address-bit multiprocessor mode, the address bit is included in the parity calculation. Parity select. UCPAR is not used when parity is disabled. 0 Odd parity 1 Even parity MSB first select. Controls the direction of the receive and transmit shift register. 0 LSB first 1 MSB first Character length. Selects 7-bit or 8-bit character length. 0 8-bit data 1 7-bit data Stop bit select. Number of stop bits. 0 One stop bit 1 Two stop bits USCI mode. The UCMODEx bits select the asynchronous mode when UCSYNC = 0. 00 UART Mode. 01 Idle-Line Multiprocessor Mode. 10 Address-Bit Multiprocessor Mode. 11 UART Mode with automatic baud rate detection. Synchronous mode enable 0 Asynchronous mode 1 Synchronous Mode
UCPAR
Bit 6
UCMSB
Bit 5
UC7BIT
Bit 4
UCSPB
Bit 3
UCMODEx
Bits 21
UCSYNC
Bit 0
19-28
UCSSELx
Bits 7-6
USCI clock source select. These bits select the BRCLK source clock. 00 UCLK 01 ACLK 10 SMCLK 11 SMCLK Receive erroneous-character interrupt-enable 0 Erroneous characters rejected and UCAxRXIFG is not set 1 Erroneous characters received will set UCAxRXIFG Receive break character interrupt-enable 0 Received break characters do not set UCAxRXIFG. 1 Received break characters set UCAxRXIFG. Dormant. Puts USCI into sleep mode. 0 Not dormant. All received characters will set UCAxRXIFG. 1 Dormant. Only characters that are preceded by an idle-line or with address bit set will set UCAxRXIFG. In UART mode with automatic baud rate detection only the combination of a break and synch field will set UCAxRXIFG. Transmit address. Next frame to be transmitted will be marked as address depending on the selected multiprocessor mode. 0 Next frame transmitted is data 1 Next frame transmitted is an address Transmit break. Transmits a break with the next write to the transmit buffer. In UART mode with automatic baud rate detection 055h must be written into UCAxTXBUF to generate the required break/synch fields. Otherwise 0h must be written into the transmit buffer. 0 Next frame transmitted is not a break 1 Next frame transmitted is a break or a break/synch Software reset enable 0 Disabled. USCI reset released for operation. 1 Enabled. USCI logic held in reset state.
UCRXEIE
Bit 5
UCBRKIE
Bit 4
UCDORM
Bit 3
UCTXADDR
Bit 2
UCTXBRK
Bit 1
UCSWRST
Bit 0
19-29
UCBRx
Clock prescaler setting of the Baud rate generator. The 16-bit value of (UCAxBR0 + UCAxBR1 256) forms the prescaler value UCBRx.
UCBRFx
First modulation stage select. These bits determine the modulation pattern for BITCLK16 when UCOS16 = 1. Ignored with UCOS16 = 0. Table 193 shows the modulation pattern. Second modulation stage select. These bits determine the modulation pattern for BITCLK. Table 192 shows the modulation pattern. Oversampling mode enabled 0 Disabled 1 Enabled
UCBRSx UCOS16
19-30
UCLISTEN
Bit 7
Listen enable. The UCLISTEN bit selects loopback mode. 0 Disabled 1 Enabled. UCAxTXD is internally fed back to the receiver. Framing error flag 0 No error 1 Character received with low stop bit Overrun error flag. This bit is set when a character is transferred into UCAxRXBUF before the previous character was read. UCOE is cleared automatically when UCxRXBUF is read, and must not be cleared by software. Otherwise, it will not function correctly. 0 No error 1 Overrun error occurred Parity error flag. When UCPEN = 0, UCPE is read as 0. 0 No error 1 Character received with parity error Break detect flag 0 No break condition 1 Break condition occurred Receive error flag. This bit indicates a character was received with error(s). When UCRXERR = 1, on or more error flags (UCFE, UCPE, UCOE) is also set. UCRXERR is cleared when UCAxRXBUF is read. 0 No receive errors detected 1 Receive error detected Address received in address-bit multiprocessor mode. 0 Received character is data 1 Received character is an address Idle line detected in idle-line multiprocessor mode. 0 No idle line detected 1 Idle line detected
UCFE
Bit 6
UCOE
Bit 5
UCPE
Bit 4
UCBRK
Bit 3
UCRXERR
Bit 2
UCADDR
Bit 1
UCIDLE
UCBUSY
Bit 0
USCI busy. This bit indicates if a transmit or receive operation is in progress. 0 USCI inactive 1 USCI transmitting or receiving
19-31
UCRXBUFx
Bits 70
The receive-data buffer is user accessible and contains the last received character from the receive shift register. Reading UCAxRXBUF resets the receive-error bits, the UCADDR or UCIDLE bit, and UCAxRXIFG. In 7-bit data mode, UCAxRXBUF is LSB justified and the MSB is always reset.
UCTXBUFx
Bits 70
The transmit data buffer is user accessible and holds the data waiting to be moved into the transmit shift register and transmitted on UCAxTXD. Writing to the transmit data buffer clears UCAxTXIFG. The MSB of UCAxTXBUF is not used for 7-bit data and is reset.
19-32
UCIRTXPLx
Bits 72 Bit 1
Transmit pulse length Pulse Length tPULSE = (UCIRTXPLx + 1) / (2 fIRTXCLK) IrDA transmit pulse clock select 0 BRCLK 1 BITCLK16 when UCOS16 = 1. Otherwise, BRCLK IrDA encoder/decoder enable. 0 IrDA encoder/decoder disabled 1 IrDA encoder/decoder enabled
UCIRTXCLK
UCIREN
Bit 0
UCIRRXFLx
Bits 72 Bit 1
Receive filter length. The minimum pulse length for receive is given by: tMIN = (UCIRRXFLx + 4) / (2 fBRCLK) IrDA receive input UCAxRXD polarity 0 IrDA transceiver delivers a high pulse when a light pulse is seen 1 IrDA transceiver delivers a low pulse when a light pulse is seen IrDA receive filter enabled 0 Receive filter disabled 1 Receive filter enabled
UCIRRXPL
UCIRRXFE
Bit 0
19-33
Reserved
Reserved Break/synch delimiter length 00 1 bit time 01 2 bit times 10 3 bit times 11 4 bit times Synch field time out error 0 No error 1 Length of synch field exceeded measurable time. Break time out error 0 No error 1 Length of break field exceeded 22 bit times. Reserved Automatic baud rate detect enable 0 Baud rate detection disabled. Length of break and synch field is not measured. 1 Baud rate detection enabled. Length of break and synch field is measured and baud rate settings are changed accordingly.
UCDELIMx
UCSTOE
Bit 3
UCBTOE
Bit 2
Reserved UCABDEN
Bit 1 Bit 0
19-34
Bits 7-2
UCA0TXIE
These bits may be used by other modules. See device-specific data sheet. USCI_A0 transmit interrupt enable 0 Interrupt disabled 1 Interrupt enabled USCI_A0 receive interrupt enable 0 Interrupt disabled 1 Interrupt enabled
Bit 1
UCA0RXIE
Bit 0
Bits 7-2
UCA0 TXIFG
These bits may be used by other modules (see the device-specific data sheet). USCI_A0 transmit interrupt flag. UCA0TXIFG is set when UCA0TXBUF is empty. 0 No interrupt pending 1 Interrupt pending USCI_A0 receive interrupt flag. UCA0RXIFG is set when UCA0RXBUF has received a complete character. 0 No interrupt pending 1 Interrupt pending
Bit 1
UCA0 RXIFG
Bit 0
19-35
Unused
Unused These bits may be used by other USCI modules (see the device-specific data sheet). USCI_A1 transmit interrupt enable 0 Interrupt disabled 1 Interrupt enabled USCI_A1 receive interrupt enable 0 Interrupt disabled 1 Interrupt enabled
UCA1TXIE
Bit 1
UCA1RXIE
Bit 0
Unused
Unused These bits may be used by other USCI modules (see the device-specific data sheet). USCI_A1 transmit interrupt flag. UCA1TXIFG is set when UCA1TXBUF is empty. 0 No interrupt pending 1 Interrupt pending USCI_A1 receive interrupt flag. UCA1RXIFG is set when UCA1RXBUF has received a complete character. 0 No interrupt pending 1 Interrupt pending
UCA1 TXIFG
Bit 1
UCA1 RXIFG
Bit 0
19-36
Chapter 20
Universal
The universal serial communication interface (USCI) supports multiple serial communication modes with one hardware module. This chapter discusses the operation of the synchronous peripheral interface or SPI mode.
Topic
Page
20.1 USCI Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-2 20.2 USCI Introduction: SPI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-3 20.3 USCI Operation: SPI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-5 20.4 USCI Registers: SPI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-14
20-1
USCI Overview
UART mode Pulse shaping for IrDA communications Automatic baud rate detection for LIN communications SPI mode
20-2
Figure 201 shows the USCI when configured for SPI mode.
20-3
0 1
UCSSELx Bit Clock Generator UCxBRx N/A ACLK SMCLK SMCLK 00 01 10 11 BRCLK 16 Prescaler/Divider Clock Direction, Phase and Polarity UCCKPH UCCKPL UCxCLK
UCMSB UC7BIT UCxSIMO Transmit Shift Register UCMODEx 2 Transmit Buffer UC xTXBUF Transmit Enable Control Transmit State Machine Set UCxTXIFG UCxSTE Set UCFE
20-4
Slave in, master out Master mode: UCxSIMO is the data output line. Slave mode: UCxSIMO is the data input line. Slave out, master in Master mode: UCxSOMI is the data input line. Slave mode: UCxSOMI is the data output line. USCI SPI clock Master mode: UCxCLK is an output. Slave mode: UCxCLK is an input. Slave transmit enable. Used in 4-pin mode to allow multiple masters on a single bus. Not used in 3-pin mode. Table 201 describes the UCxSTE operation.
- UCxSOMI
- UCxCLK
- UCxSTE
20-5
Note: Character Format for Figures Figures throughout this chapter use MSB first format.
20-6
20.3.3 Master Mode Figure 202. USCI Master and External Slave
UCxSIMO
SIMO
SLAVE
SPI Receive Buffer Px.x UCxSTE UCx SOMI STE SS Port.x SOMI
Figure 202 shows the USCI as a master in both 3-pin and 4-pin configurations. The USCI initiates data transfer when data is moved to the transmit data buffer UCxTXBUF. The UCxTXBUF data is moved to the TX shift register when the TX shift register is empty, initiating data transfer on UCxSIMO starting with either the most-significant or least-significant bit depending on the UCMSB setting. Data on UCxSOMI is shifted into the receive shift register on the opposite clock edge. When the character is received, the receive data is moved from the RX shift register to the received data buffer UCxRXBUF and the receive interrupt flag, UCxRXIFG, is set, indicating the RX/TX operation is complete. A set transmit interrupt flag, UCxTXIFG, indicates that data has moved from UCxTXBUF to the TX shift register and UCxTXBUF is ready for new data. It does not indicate RX/TX completion. To receive data into the USCI in master mode, data must be written to UCxTXBUF because receive and transmit operations operate concurrently.
20-7
If data is written into UCxTXBUF while the master is held inactive by UCxSTE, it will be transmit as soon as UCxSTE transitions to the master-active state. If an active transfer is aborted by UCxSTE transitioning to the master-inactive state, the data must be re-written into UCxTXBUF to be transferred when UCxSTE transitions back to the master-active state. The UCxSTE input signal is not used in 3-pin master mode.
20-8
20.3.4 Slave Mode Figure 203. USCI Slave and External Master
MASTER
SIMO
SOMI
Figure 203 shows the USCI as a slave in both 3-pin and 4-pin configurations. UCxCLK is used as the input for the SPI clock and must be supplied by the external master. The data-transfer rate is determined by this clock and not by the internal bit clock generator. Data written to UCxTXBUF and moved to the TX shift register before the start of UCxCLK is transmitted on UCxSOMI. Data on UCxSIMO is shifted into the receive shift register on the opposite edge of UCxCLK and moved to UCxRXBUF when the set number of bits are received. When data is moved from the RX shift register to UCxRXBUF, the UCxRXIFG interrupt flag is set, indicating that data has been received. The overrun error bit, UCOE, is set when the previously received data is not read from UCxRXBUF before new data is moved to UCxRXBUF.
transmit active state. The UCxSTE input signal is not used in 3-pin slave mode.
20-9
empty. A PUC or set UCSWRST bit disables the USCI immediately and any active transfer is terminated.
Transmit Enable
In master mode, writing to UCxTXBUF activates the bit clock generator and the data will begin to transmit. In slave mode, transmission begins when a master provides a clock and, in 4-pin mode, when the UCxSTE is in the slave-active state.
Receive Enable
The SPI receives data when a transmission is active. Receive and transmit operations operate concurrently.
20-10
0 1
X X
MSB MSB
LSB LSB
20-11
Data written to UCxTXBUF when UCxTXIFG = 0 may result in erroneous data transmission.
20-12
The following software example shows an extract of an interrupt service routine to handle data transmit interrupts from USCI_A0 in either UART or SPI mode and USCI_B0 in SPI mode.
USCIA0_TX_USCIB0_TX_ISR BIT.B #UCA0TXIFG, &IFG2 ; USCI_A0 Transmit Interrupt? JNZ USCIA0_TX_ISR USCIB0_TX_ISR ; Write UCB0TXBUF (clears UCB0TXIFG) ... RETI USCIA0_TX_ISR ; Write UCA0TXBUF (clears UCA0TXIFG) ... RETI
20-13
Note: Modifying SFR bits To avoid modifying control bits of other modules, it is recommended to set or clear the IEx and IFGx bits using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions.
20-14
20-15
UCCKPH
Bit 7
Clock phase select. 0 Data is changed on the first UCLK edge and captured on the following edge. 1 Data is captured on the first UCLK edge and changed on the following edge. Clock polarity select. 0 The inactive state is low. 1 The inactive state is high. MSB first select. Controls the direction of the receive and transmit shift register. 0 LSB first 1 MSB first Character length. Selects 7-bit or 8-bit character length. 0 8-bit data 1 7-bit data Master mode select 0 Slave mode 1 Master mode USCI Mode. The UCMODEx bits select the synchronous mode when UCSYNC = 1. 00 3-Pin SPI 01 4-Pin SPI with UCxSTE active high: slave enabled when UCxSTE = 1 10 4-Pin SPI with UCxSTE active low: slave enabled when UCxSTE = 0 11 I2C Mode Synchronous mode enable 0 Asynchronous mode 1 Synchronous Mode
UCCKPL
Bit 6
UCMSB
Bit 5
UC7BIT
Bit 4
UCMST
Bit 3
UCMODEx
Bits 2-1
UCSYNC
Bit 0
20-16
rw-0
rw-0
rw-0
rw-0
rw-0
rw-0
rw-1
UCSSELx
Bits 7-6
USCI clock source select. These bits select the BRCLK source clock in master mode. UCxCLK is always used in slave mode. 00 NA 01 ACLK 10 SMCLK 11 SMCLK Unused in synchronous mode (UCSYNC=1). Software reset enable 0 Disabled. USCI reset released for operation. 1 Enabled. USCI logic held in reset state.
Unused UCSWRST
20-17
UCAxBR0, USCI_Ax Bit Rate Control Register 0 UCBxBR0, USCI_Bx Bit Rate Control Register 0
7 6 5 4 3 2 1 0
UCAxBR1, USCI_Ax Bit Rate Control Register 1 UCBxBR1, USCI_Bx Bit Rate Control Register 1
7 6 5 4 3 2 1 0
UCBRx
Bit clock prescaler setting. The 16-bit value of (UCxxBR0+UCxxBR1256) form the prescaler value UCBRx.
20-18
rw-0
rw-0
rw-0
rw-0
rw-0
rw-0
r-0
UCLISTEN
Bit 7
Listen enable. The UCLISTEN bit selects loopback mode. 0 Disabled 1 Enabled. The transmitter output is internally fed back to the receiver. Framing error flag. This bit indicates a bus conflict in 4-wire master mode. UCFE is not used in 3-wire master or any slave mode. 0 No error 1 Bus conflict occurred Overrun error flag. This bit is set when a character is transferred into UCxRXBUF before the previous character was read. UCOE is cleared automatically when UCxRXBUF is read, and must not be cleared by software. Otherwise, it will not function correctly. 0 No error 1 Overrun error occurred Unused in synchronous mode (UCSYNC=1). USCI busy. This bit indicates if a transmit or receive operation is in progress. 0 USCI inactive 1 USCI transmitting or receiving
UCFE
Bit 6
UCOE
Bit 5
Unused UCBUSY
Bits 41 Bit 0
20-19
UCAxRXBUF, USCI_Ax Receive Buffer Register UCBxRXBUF, USCI_Bx Receive Buffer Register
7 6 5 4 UCRXBUFx r r r r r r r r 3 2 1 0
UCRXBUFx
Bits 7-0
The receive-data buffer is user accessible and contains the last received character from the receive shift register. Reading UCxRXBUF resets the receive-error bits, and UCxRXIFG. In 7-bit data mode, UCxRXBUF is LSB justified and the MSB is always reset.
UCAxTXBUF, USCI_Ax Transmit Buffer Register UCBxTXBUF, USCI_Bx Transmit Buffer Register
7 6 5 4 UCTXBUFx rw rw rw rw rw rw rw rw 3 2 1 0
UCTXBUFx
Bits 7-0
The transmit data buffer is user accessible and holds the data waiting to be moved into the transmit shift register and transmitted. Writing to the transmit data buffer clears UCxTXIFG. The MSB of UCxTXBUF is not used for 7-bit data and is reset.
20-20
Bits 7-4
UCB0TXIE
These bits may be used by other modules. See device-specific data sheet. USCI_B0 transmit interrupt enable 0 Interrupt disabled 1 Interrupt enabled USCI_B0 receive interrupt enable 0 Interrupt disabled 1 Interrupt enabled USCI_A0 transmit interrupt enable 0 Interrupt disabled 1 Interrupt enabled USCI_A0 receive interrupt enable 0 Interrupt disabled 1 Interrupt enabled
Bit 3
UCB0RXIE
Bit 2
UCA0TXIE
Bit 1
UCA0RXIE
Bit 0
20-21
Bits 7-4
UCB0 TXIFG
These bits may be used by other modules. See device-specific data sheet. USCI_B0 transmit interrupt flag. UCB0TXIFG is set when UCB0TXBUF is empty. 0 No interrupt pending 1 Interrupt pending USCI_B0 receive interrupt flag. UCB0RXIFG is set when UCB0RXBUF has received a complete character. 0 No interrupt pending 1 Interrupt pending USCI_A0 transmit interrupt flag. UCA0TXIFG is set when UCA0TXBUF empty. 0 No interrupt pending 1 Interrupt pending USCI_A0 receive interrupt flag. UCA0RXIFG is set when UCA0RXBUF has received a complete character. 0 No interrupt pending 1 Interrupt pending
Bit 3
UCB0 RXIFG
Bit 2
UCA0 TXIFG
Bit 1
UCA0 RXIFG
Bit 0
20-22
Unused
Unused USCI_B1 transmit interrupt enable 0 Interrupt disabled 1 Interrupt enabled USCI_B1 receive interrupt enable 0 Interrupt disabled 1 Interrupt enabled USCI_A1 transmit interrupt enable 0 Interrupt disabled 1 Interrupt enabled USCI_A1 receive interrupt enable 0 Interrupt disabled 1 Interrupt enabled
UCB1TXIE
UCB1RXIE
Bit 2
UCA1TXIE
Bit 1
UCA1RXIE
Bit 0
20-23
Unused
Unused USCI_B1 transmit interrupt flag. UCB1TXIFG is set when UCB1TXBUF is empty. 0 No interrupt pending 1 Interrupt pending USCI_B1 receive interrupt flag. UCB1RXIFG is set when UCB1RXBUF has received a complete character. 0 No interrupt pending 1 Interrupt pending USCI_A1 transmit interrupt flag. UCA1TXIFG is set when UCA1TXBUF empty. 0 No interrupt pending 1 Interrupt pending USCI_A1 receive interrupt flag. UCA1RXIFG is set when UCA1RXBUF has received a complete character. 0 No interrupt pending 1 Interrupt pending
UCB1 TXIFG
UCB1 RXIFG
Bit 2
UCA1 TXIFG
Bit 1
UCA1 RXIFG
Bit 0
20-24
Chapter 21
Universal
The universal serial communication interface (USCI) supports multiple serial communication modes with one hardware module. This chapter discusses the operation of the I2C mode.
Topic
Page
21.1 USCI Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-2 21.2 USCI Introduction: I2C Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-3 21.3 USCI Operation: I2C Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-5 21.4 USCI Registers: I2C Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-26
21-1
USCI Overview
UART mode Pulse shaping for IrDA communications Automatic baud rate detection for LIN communications SPI mode
21-2
21-3
UCxSDA
Slave Address UC 1SA UCSLA10 UCxSCL UCSSELx Bit Clock Generator UCxBRx UC1CLK ACLK SMCLK SMCLK 00 01 10 11 BRCLK 16 UCMST Prescaler/Divider
21-4
Device B
Device C
Note:
The MSP430 SDA and SCL pins must not be pulled up above the MSP430 VCC level.
21-5
I2C communication stops SDA and SCL are high impedance UCBxI2CSTAT, bits 6-0 are cleared UCBxTXIE and UCBxRXIE are cleared UCBxTXIFG and UCBxRXIFG are cleared All other bits and registers remain unchanged.
Note: Initializing or Reconfiguring the USCI Module The recommended USCI initialization/re-configuration process is: 1) Set UCSWRST (BIS.B #UCSWRST,&UCxCTL1) 2) Initialize all USCI registers with UCSWRST=1 (including UCxCTL1) 3) Configure ports. 4) Clear UCSWRST via software (BIC.B #UCSWRST,&UCxCTL1) 5) Enable interrupts (optional) via UCxRXIE and/or UCxTXIE
21-6
SDA MSB SCL 1 START Condition (S) 2 7 8 R/W 9 ACK 1 2 8 9 ACK STOP Condition (P) Acknowledgement Signal From Receiver Acknowledgement Signal From Receiver
START and STOP conditions are generated by the master and are shown in Figure 213. A START condition is a high-to-low transition on the SDA line while SCL is high. A STOP condition is a low-to-high transition on the SDA line while SCL is high. The bus busy bit, UCBBUSY, is set after a START and cleared after a STOP. Data on SDA must be stable during the high period of SCL as shown in Figure 214. The high and low state of SDA can only change when SCL is low, otherwise START or STOP conditions will be generated.
SCL
21-7
7-Bit Addressing
In the 7-bit addressing format, shown in Figure 215, the first byte is the 7-bit slave address and the R/W bit. The ACK bit is sent from the receiver after each byte.
Slave Address
R/W
ACK
Data
ACK
Data
ACK P
10-Bit Addressing
In the 10-bit addressing format, shown in Figure 216, the first byte is made up of 11110b plus the two MSBs of the 10-bit slave address and the R/W bit. The ACK bit is sent from the receiver after each byte. The next byte is the remaining 8 bits of the 10-bit slave address, followed by the ACK bit and the 8-bit data.
R/W
Data
ACK P
Slave Address
1
R/W ACK
Data
Slave Address
1
R/W ACK
Data
Any Number
Any Number
21-8
Other Slave
USCI Master
USCI Slave
...
...
21-9
Slave Mode
The USCI module is configured as an I2C slave by selecting the I2C mode with UCMODEx = 11 and UCSYNC = 1 and clearing the UCMST bit. Initially the USCI module must be configured in receiver mode by clearing the UCTR bit to receive the I2C address. Afterwards, transmit and receive operations are controlled automatically depending on the R/W bit received together with the slave address. The USCI slave address is programmed with the UCBxI2COA register. When UCA10 = 0, 7-bit addressing is selected. When UCA10 = 1, 10-bit addressing is selected. The UCGCEN bit selects if the slave responds to a general call. When a START condition is detected on the bus, the USCI module will receive the transmitted address and compare it against its own address stored in UCBxI2COA. The UCSTTIFG flag is set when address received matches the USCI slave address.
21-10
UCBxTXIFG= 0
UCBxTXIFG= 1
UCSTPIFG= 1 UCSTTIFG= 0
Bus stalled (SCL held low) until data available Write data to UCBxTXBUF Repeated start continue as slave transmitter DATA A S SLA/R
UCBxTXIFG=0
DATA
SLA/W
21-11
21-12
UCBxRXIFG= 1 UCTR= 0(Receiver) UCSTTIFG= 1 UCSTPIFG= 0 Bus stalled (SCL held low) if UCBxRXBUF not read Read data from UCBxRXBUF
DATA
P or S
UCTXNACK= 1 Bus not stalled even if UCBxRXBUF not read Reception of the general call address. Gen Call A
UCTXNACK= 0
UCALIFG= 1 UCMST= 0 UCTR= 0 (Receiver) UCSTTIFG= 1 (UCGC= 1if general call) UCBxTXIFG= 0 UCSTPIFG= 0
21-13
11110 xx/W
SLA (2.)
DATA
DATA
P or S
Gen Call
DATA
DATA
P or S
UCBxRXIFG= 1
Slave Transmitter
11110 xx/W
SLA (2.)
11110 xx/R
DATA
P or S
UCSTTIFG= 0
21-14
Master Mode
The USCI module is configured as an I2C master by selecting the I2C mode with UCMODEx = 11 and UCSYNC = 1 and setting the UCMST bit. When the master is part of a multi-master system, UCMM must be set and its own address must be programmed into the UCBxI2COA register. When UCA10 = 0, 7-bit addressing is selected. When UCA10 = 1, 10-bit addressing is selected. The UCGCEN bit selects if the USCI module responds to a general call.
21-15
Setting UCTXSTT will generate a repeated START condition. In this case, UCTR may be set or cleared to configure transmitter or receiver, and a different slave address may be written into UCBxI2CSA if desired. If the slave does not acknowledge the transmitted data the not-acknowledge interrupt flag UCNACKIFG is set. The master must react with either a STOP condition or a repeated START condition. If data was already written into UCBxTXBUF it will be discarded. If this data should be transmitted after a repeated START it must be written into UCBxTXBUF again. Any set UCTXSTT is discarded, too. To trigger a repeated start, UCTXSTT needs to be set again. Figure 2112 illustrates the I2C master transmitter operation.
21-16
1) UCTR= 1(Transmitter) 2) UCTXSTT= 1 UCBxTXIFG= 1 UCBxTXBUF discarded Next transfer started with a repeated start condition
UCTXSTP= 0
Bus stalled (SCL held low) until data available Write data to UCBxTXBUF DATA A S SLA/W
DATA
SLA/R
UCTXSTP= 1
SLA/W
SLA/R
Other master continues UCALIFG= 1 UCMST= 0 (UCSTTIFG= 0) Arbitration lost and addressed as slave A Other master continues
UCALIFG= 1 UCMST= 0 UCTR= 0(Receiver) UCSTTIFG= 1 (UCGC= 1if general call) UCBxTXIFG= 0 UCSTPIFG= 0 USCI continues as Slave Receiver
21-17
Setting UCTXSTT will generate a repeated START condition. In this case, UCTR may be set or cleared to configure transmitter or receiver, and a different slave address may be written into UCBxI2CSA if desired. Figure 2113 illustrates the I2C master receiver operation. Note: Consecutive Master Transactions Without Repeated Start When performing multiple consecutive I2C master transactions without the repeated start feature, the current transaction must be completed before the next one is initiated. This can be done by ensuring that the transmit stop condition flag UCTXSTP is cleared before the next I2C transaction is initiated with setting UCTXSTT = 1. Otherwise, the current transaction might be affected.
21-18
UCTXSTT =0
UCBxRXIFG= 1
UCTXSTP= 1
UCTXSTP= 0
DATA
SLA/W
DATA
SLA/R
UCTXSTP= 1
UCTXSTP= 0
SLA/R
Other master continues UCALIFG= 1 UCMST= 0 (UCSTTIFG= 0) Arbitration lost and addressed as slave A Other master continues
UCALIFG= 1 UCMST= 0 UCTR= 1( Transmitter ) UCSTTIFG= 1 UCBxTXIFG= 1 UCSTPIFG= 0 USCI continues as Slave Transmitter
21-19
11110 xx/W
SLA (2.)
DATA
DATA
UCTXSTP= 0
Master Receiver
11110 xx/W
SLA (2.)
11110 xx/R
DATA
DATA
UCTXSTT= 0
UCBxRXIFG= 1 UCTXSTP= 1
UCTXSTP= 0
21-20
Arbitration
If two or more master transmitters simultaneously start a transmission on the bus, an arbitration procedure is invoked. Figure 2115 illustrates the arbitration procedure between two devices. The arbitration procedure uses the data presented on SDA by the competing transmitters. The first master transmitter that generates a logic high is overruled by the opposing master generating a logic low. The arbitration procedure gives priority to the device that transmits the serial data stream with the lowest binary value. The master transmitter that lost arbitration switches to the slave receiver mode, and sets the arbitration lost flag UCALIFG. If two or more devices send identical first bytes, arbitration continues on the subsequent bytes.
Bus Line SCL Data From Device #1 1 Data From Device #2 1 Bus Line SDA 1 0 0 1 0 0 1 0 1 0 1 n Device #1 Lost Arbitration and Switches Off
If the arbitration procedure is in progress when a repeated START condition or STOP condition is transmitted on SDA, the master transmitters involved in arbitration must send the repeated START condition or STOP condition at the same position in the format frame. Arbitration is not allowed between:
- A repeated START condition and a data bit - A STOP condition and a data bit - A repeated START condition and a STOP condition
21-21
The USCI clock source frequency and the prescaler setting UCBRx must to be chosen such that the minimum low and high period times of the I2C specification are met. During the arbitration procedure the clocks from the different masters must be synchronized. A device that first generates a low period on SCL overrules the other devices forcing them to start their own low periods. SCL is then held low by the device with the longest low period. The other devices must wait for SCL to be released before starting their high periods. Figure 2116 illustrates the clock synchronization. This allows a slow slave to slow down a fast master.
21-22
Clock Stretching
The USCI module supports clock stretching and also makes use of this feature as described in the operation mode sections. The UCSCLLOW bit can be used to observe if another device pulls SCL low while the USCI module already released SCL due to the following conditions:
- USCI is acting as master and a connected slave drives SCL low. - USCI is acting as master and another master drives SCL low during
arbitration. The UCSCLLOW bit is also active if the USCI holds SCL low because it is waiting as transmitter for data being written into UCBxTXBUF or as receiver for the data being read from UCBxRXBUF. The UCSCLLOW bit might get set for a short time with each rising SCL edge because the logic observes the external SCL and compares it to the internally generated SCL.
21.3.6 Using the USCI Module in I2C Mode With Low-Power Modes
The USCI module provides automatic clock activation for SMCLK for use with low-power modes. When SMCLK is the USCI clock source, and is inactive because the device is in a low-power mode, the USCI module automatically activates it when needed, regardless of the control-bit settings for the clock source. The clock remains active until the USCI module returns to its idle condition. After the USCI module returns to the idle condition, control of the clock source reverts to the settings of its control bits. Automatic clock activation is not provided for ACLK. When the USCI module activates an inactive clock source, the clock source becomes active for the whole device and any peripheral configured to use the clock source may be affected. For example, a timer using SMCLK will increment while the USCI module forces SMCLK active. In I2C slave mode no internal clock source is required because the clock is provided by the external master. It is possible to operate the USCI in I2C slave mode while the device is in LPM4 and all internal clock sources are disabled. The receive or transmit interrupts can wake up the CPU from any low power mode.
21-23
UCNACKIFG
UCSTTIFG
UCSTPIFG
21-24
The following software example shows an extract of the interrupt service routine that handles data transmit interrupts from USCI_A0 in either UART or SPI mode and the data transfer interrupts from USCI_B0 in I2C mode.
USCIA0_TX_USCIB0_I2C_DATA_ISR BIT.B #UCA0TXIFG, &IFG2 ; USCI_A0 Transmit Interrupt? JNZ USCIA0_TX_ISR USCIB0_I2C_DATA_ISR BIT.B #UCB0RXIFG, &IFG2 JNZ USCIB0_I2C_RX USCIB0_I2C_TX ; Write UCB0TXBUF... clears UCB0TXIFG ... RETI USCIB0_I2C_RX ; Read UCB0RXBUF... clears UCB0RXIFG ... RETI USCIA0_TX_ISR ; Write UCA0TXBUF ... clears UCA0TXIFG ... RETI
21-25
Note: Modifying SFR bits To avoid modifying control bits of other modules, it is recommended to set or clear the IEx and IFGx bits using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions.
21-26
UCA10
Bit 7
Own addressing mode select 0 Own address is a 7-bit address 1 Own address is a 10-bit address Slave addressing mode select 0 Address slave with 7-bit address 1 Address slave with 10-bit address Multi-master environment select 0 Single master environment. There is no other master in the system. The address compare unit is disabled. 1 Multi master environment Unused Master mode select. When a master looses arbitration in a multi-master environment (UCMM = 1) the UCMST bit is automatically cleared and the module acts as slave. 0 Slave mode 1 Master mode USCI Mode. The UCMODEx bits select the synchronous mode when UCSYNC = 1. 00 3-pin SPI 01 4Pin SPI (master/slave enabled if STE = 1) 10 4Pin SPI (master/slave enabled if STE = 0) 11 I2C mode Synchronous mode enable 0 Asynchronous mode 1 Synchronous mode
UCSLA10
Bit 6
UCMM
Bit 5
Unused UCMST
Bit 4 Bit 3
UCMODEx
Bits 21
UCSYNC
Bit 0
21-27
UCSSELx
Bits 7-6
USCI clock source select. These bits select the BRCLK source clock. 00 UCLKI 01 ACLK 10 SMCLK 11 SMCLK Unused Transmitter/Receiver 0 Receiver 1 Transmitter Transmit a NACK. UCTXNACK is automatically cleared after a NACK is transmitted. 0 Acknowledge normally 1 Generate NACK Transmit STOP condition in master mode. Ignored in slave mode. In master receiver mode the STOP condition is preceded by a NACK. UCTXSTP is automatically cleared after STOP is generated. 0 No STOP generated 1 Generate STOP Transmit START condition in master mode. Ignored in slave mode. In master receiver mode a repeated START condition is preceded by a NACK. UCTXSTT is automatically cleared after START condition and address information is transmitted. Ignored in slave mode. 0 Do not generate START condition 1 Generate START condition Software reset enable 0 Disabled. USCI reset released for operation. 1 Enabled. USCI logic held in reset state.
Unused UCTR
Bit 5 Bit 4
UCTXNACK
Bit 3
UCTXSTP
Bit 2
UCTXSTT
Bit 1
UCSWRST
Bit 0
21-28
UCBRx
Bit clock prescaler setting. The 16-bit value of (UCBxBR0 + UCBxBR1 256} forms the prescaler value.
21-29
Bit 7 Bit 6
Unused. SCL low 0 SCL is not held low 1 SCL is held low General call address received. UCGC is automatically cleared when a START condition is received. 0 No general call address received 1 General call address received Bus busy 0 Bus inactive 1 Bus busy Not-acknowledge received interrupt flag. UCNACKIFG is automatically cleared when a START condition is received. 0 No interrupt pending 1 Interrupt pending Stop condition interrupt flag. UCSTPIFG is automatically cleared when a START condition is received. 0 No interrupt pending 1 Interrupt pending Start condition interrupt flag. UCSTTIFG is automatically cleared if a STOP condition is received. 0 No interrupt pending 1 Interrupt pending Arbitration lost interrupt flag 0 No interrupt pending 1 Interrupt pending
Bit 5
UCBBUSY
Bit 4
UCNACK IFG
Bit 3
UCSTPIFG
Bit 2
UCSTTIFG
Bit 1
UCALIFG
Bit 0
21-30
UCRXBUFx
Bits 70
The receive-data buffer is user accessible and contains the last received character from the receive shift register. Reading UCBxRXBUF resets UCBxRXIFG.
UCTXBUFx
Bits 70
The transmit data buffer is user accessible and holds the data waiting to be moved into the transmit shift register and transmitted. Writing to the transmit data buffer clears UCBxTXIFG.
21-31
4 I2COAx
rw0
rw0
rw0
rw0
rw0
rw0
rw0
rw0
UCGCEN
Bit 15
General call response enable 0 Do not respond to a general call 1 Respond to a general call I2C own address. The I2COAx bits contain the local address of the USCI_Bx I2C controller. The address is right-justified. In 7-bit addressing mode Bit 6 is the MSB, Bits 9-7 are ignored. In 10-bit addressing mode Bit 9 is the MSB.
I2COAx
Bits 9-0
4 I2CSAx
rw0
rw0
rw0
rw0
rw0
rw0
rw0
rw0
I2CSAx
Bits 9-0
I2C slave address. The I2CSAx bits contain the slave address of the external device to be addressed by the USCI_Bx module. It is only used in master mode. The address is right-justified. In 7-bit slave addressing mode Bit 6 is the MSB, Bits 9-7 are ignored. In 10-bit slave addressing mode Bit 9 is the MSB.
21-32
Reserved UCNACKIE
Bits 74 Bit 3
Reserved Not-acknowledge interrupt enable 0 Interrupt disabled 1 Interrupt enabled Stop condition interrupt enable 0 Interrupt disabled 1 Interrupt enabled Start condition interrupt enable 0 Interrupt disabled 1 Interrupt enabled Arbitration lost interrupt enable 0 Interrupt disabled 1 Interrupt enabled
UCSTPIE
Bit 2
UCSTTIE
Bit 1
UCALIE
Bit 0
21-33
Bits 7-4
UCB0TXIE
These bits may be used by other modules (see the device-specific data sheet). USCI_B0 transmit interrupt enable 0 Interrupt disabled 1 Interrupt enabled USCI_B0 receive interrupt enable 0 Interrupt disabled 1 Interrupt enabled These bits may be used by other modules (see the device-specific data sheet).
Bit 3
UCB0RXIE
Bit 2
Bits 1-0
Bits 7-4
UCB0 TXIFG
These bits may be used by other modules (see the device-specific data sheet). USCI_B0 transmit interrupt flag. UCB0TXIFG is set when UCB0TXBUF is empty. 0 No interrupt pending 1 Interrupt pending USCI_B0 receive interrupt flag. UCB0RXIFG is set when UCB0RXBUF has received a complete character. 0 No interrupt pending 1 Interrupt pending These bits may be used by other modules (see the device-specific data sheet).
Bit 3
UCB0 RXIFG
Bit 2
Bits 1-0
21-34
Unused
Unused USCI_B1 transmit interrupt enable 0 Interrupt disabled 1 Interrupt enabled USCI_B1 receive interrupt enable 0 Interrupt disabled 1 Interrupt enabled These bits may be used by other USCI modules (see the device-specific data sheet).
UCB1TXIE
UCB1RXIE
Bit 2
Bits 1-0
Unused
Unused. USCI_B1 transmit interrupt flag. UCB1TXIFG is set when UCB1TXBUF is empty. 0 No interrupt pending 1 Interrupt pending USCI_B1 receive interrupt flag. UCB1RXIFG is set when UCB1RXBUF has received a complete character. 0 No interrupt pending 1 Interrupt pending These bits may be used by other modules (see the device-specific data sheet).
UCB1 TXIFG
UCB1 RXIFG
Bit 2
Bits 1-0
21-35
21-36
Chapter 22
OA
The OA is a general purpose operational amplifier. This chapter describes the OA. Three OA modules are implemented in the MSP430FG43x and MSP430xG461x devices. Two OA modules are implemented in the MSP430FG42x0 and MSP430FG47x devices.
Topic
Page
22.1 OA Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-2 22.2 OA Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-4 22.3 OA Modules in MSP430FG42x0 Devices . . . . . . . . . . . . . . . . . . . . . . . 22-11 22.4 OA Modules in MSP430FG47x Devices . . . . . . . . . . . . . . . . . . . . . . . . 22-16 22.5 OA Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-24 22.6 OA Registers in MSP430FG42x0 Devices . . . . . . . . . . . . . . . . . . . . . . 22-27 22.7 OA Registers in MSP430FG47x Devices . . . . . . . . . . . . . . . . . . . . . . . 22-31
OA
22-1
OA Introduction
22.1 OA Introduction
The OA op amps support front-end analog signal conditioning prior to analog-to-digital conversion. Features of the OA include:
- Single supply, low-current operation - Rail-to-rail output - Software selectable rail-to-rail input - Programmable settling time vs power consumption - Software selectable configurations - Software selectable feedback resistor ladder for PGA implementations
Note: Multiple OA Modules Some devices may integrate more than one OA module. If more than one OA module is present on a device, the multiple OA modules operate identically. Throughout this chapter, nomenclature appears such as OAxCTL0 to describe register names. When this occurs, the x is used to indicate which OA module is being discussed. In cases where operation is identical, the register is simply referred to as OAxCTL0. The block diagram of the OA module is shown in Figure 221.
22-2
OA
OA Introduction
OAADC0 A12 ext. (OA0) A13 ext. (OA1) A14 ext. (OA2)
0 1
OAPx
A12 int. (OA0) A13 int. (OA1) A14 int. (OA2) OAADC1 OAFCx=0
00 01 10 11 0 1
OAPMx
+ OAx
OAxOUT
OA1TAP (OA0) OA2TAP (OA1) OANx OA0TAP (OA2) OAxI0 OAxI1 Int. DAC12_0OUT Int. DAC12_1OUT
0 1 1
00 01 10 11 RBOTTOM NA 00 01 10 11 OAFCx={2,4,5,6}
OAADC1
OANx = 0 OAFCx = 7 OA1RBOTTOM (OA0) OA2RBOTTOM (OA1) OA0RBOTTOM (OA2) OAFCx = {0,1,3} 1
OAFCx=1 OAFCx={2 7} OAFBRx 3 000 4R 001 4R 010 2R 011 OAxTAP 100 R 101 R 110 R 111 R RBOTTOM 000 001 010 011 100 101 110 111 unused reserved 00 01 10 11 OAxI0 OAxI1 OA2OUT (OA0) OA0OUT (OA1) OA1OUT (OA2) unused OAxOUT reserved OAFBRx > 0 AV CC 2R 3 OAFCx RTOP
OANx
OA
22-3
OA Operation
22.2 OA Operation
The OA module is configured with user software. The setup and operation of the OA is discussed in the following sections.
22.2.1 OA Amplifier
The OA is a configurable low-current rail-to-rail operational amplifier. It can be configured as an inverting amplifier or a non-inverting amplifier, or it can be combined with other OA modules to form differential amplifiers. The output slew rate of the OA can be configured for optimized settling time vs power consumption with the OAPMx bits. When OAPMx = 00, the OA is off, and the output is high-impedance. When OAPMx > 0, the OA is on. See the device-specific data sheet for parameters.
22.2.2 OA Input
The OA has configurable input selection. The signals for the + and inputs are individually selected with the OANx and OAPx bits and can be selected as external signals or internal signals from one of the DAC12 modules. One of the non-inverting inputs is tied together internally for all OA modules. The OA input signal swing is software selectable with the OARRIP bit. When OARRIP = 0, rail-to-rail input mode is selected, and the OA uses higher quiescent current. See the device data sheet for parameters.
22.2.3 OA Output
The OA has configurable output selection. The OA output signals can be routed to ADC12 inputs A12 (OA0), A13 (OA1), or A14 (OA2) with the OAADC0 bit. When OAADC0 = 1 and OAPMx > 0, the OA output is connected internally to the corresponding ADC input, and the external ADC input is not connected. The OA output signals can also be routed to ADC12 inputs A1 (OA0), A3 (OA1), or A5 (OA2) when OAFCx = 0 or when OAADC1 = 1. In this case, the OA output is connected to both the ADC12 input internally and the corresponding pin on the device. The OA output is also connected to an internal R-ladder with the OAFCx bits. The R-ladder tap is selected with the OAFBRx bits to provide programmable gain amplifier functionality.
22-4
OA
OA Operation
22.2.4 OA Configurations
The OA can be configured for different amplifier functions with the OAFCx bits. as listed in Table 221.
Comparator Mode
In this mode, the output of the OAx is isolated from the resistor ladder. RTOP is connected to AVSS, and RBOTTOM is connected to AVCC. The OAxTAP signal is connected to the inverting input of the OAx, providing a comparator with a programmable threshold voltage selected by the OAFBRx bits. The non-inverting input is selected by the OAPx bits. Hysteresis can be added by an external positive feedback resistor. The external connection for the inverting input is disabled, and the OANx bits are dont care. The OAx output is connected internally to the ADC12 input channel as selected by the OAxCTL0 bits.
OA
22-5
OA Operation
22-6
OA
OA Operation
Figure 222 shows an example of a two-opamp differential amplifier using OA0 and OA1. The control register settings and are shown in Table 222. The gain for the amplifier is selected by the OAFBRx bits for OA1 and is shown in Table 223. The OAx interconnections are shown in Figure 223.
V2
+ OA1
V1
+ OA0 R1 R2
Vdiff =
(V 2 V 1) xR 2 R1
OA
22-7
OA Operation
0 1
A13 int.
00 01 10 11 0 1
OAADC1 + OA1 0 1 00 01 10 11 OAFBRx 3 000 4R 001 4R 010 2R 011 2R 100 R 101 R 110 + OA0 00 01 10 11 000 001 010 011 100 101 110 111 OA0OUT OA1RBOTTOM R 111 R 000 001 010 011 100 101 110 111 00 01 10 11 OAADC1 1 A3 int./ext., OA1O
OAPx
00 01 10 11 V1 0 1
OAPMx
22-8
OA
OA Operation
Figure 224 shows an example of a three-opamp differential amplifier using OA0, OA1, and OA2. The control register settings are shown in Table 224. The gain for the amplifier is selected by the OAFBRx bits of OA0 and OA2. The OAFBRx settings for both OA0 and OA2 must be equal. The gain settings are shown in Table 225. The OAx interconnections are shown in Figure 225.
V2
+
OA0
R1
R2
+
OA2
V1
+
OA1
Vdiff
(V 2 V1) xR 2 R1
R1
R2
OA
22-9
OA Operation
OAADC0 OAPMx V2 0 1 + OA0 0 OAFBRx 00 01 10 11 OA0TAP 011 2R 100 R 101 R 110 R 111 R OA0RBOTTOM 000 001 010 011 100 000 4R 001 4R 010 2R 00 01 10 11 OAFBRx 3 000 4R 001 4R 010 2R 011 2R 101 OAPMx V1 0 1 + OA1 00 01 10 11 000 001 010 011 100 101 110 111 OA1OUT OA2RBOTTOM 110 111 100 R 101 R 110 R 111 R 000 001 010 011 100 101 110 111 00 01 10 11 OAADC1 3 OA0TAP 1 + OA2 0 1 OA0OUT OAPMx OAADC1 1 A5 int./ext., OA2O
00 01 10 11
A14 ext.
0 1
A14 int.
OAPx
00 01 10 11
22-10
OA
1 OAPx OAPMx OAxI0 OA0I0 Int. DAC12 00 01 10 11 OANx OAxI1 OAxI2 Int. DAC12 00 01 10 11 0 1 OAxP + OAx 0
OAFCx=001 1 SWCTL3 (OA0) OAFCx SWCTL7 (OA1) 3 unused unused OAN0 reserved reserved 0 1 unused 110 111 2 SWCTL2 (OA0) SWCTL6 (OA1) SWxC SWCTL0/1 (OA0) SWCTL6/7 (OA1) 000 001 ... 101 OA0FB/A0(OA0) OA1FB/A1(OA1)
OA
22-11
22.3.1 OA Amplifier
Each OA is a configurable low-current operational amplifier that can be configured as an inverting amplifier or a non-inverting amplifier.
22.3.2 OA Inputs
The OA has configurable input selection. The signals for the + and inputs are individually selected with the OANx and OAPx bits and can be selected as external signals or internal signals from the DAC12 modules or VSS. One of the non-inverting inputs (OA0I0) is tied together internally for all OA modules. The SWCTL0, SWCTL1, SWCTL4, and SWCTL5 bits force settings of the OANx and OAPx bits. See section Switch Control for more details.
22.3.3 OA Outputs
The OA outputs are routed to the respective output pin OAxOUT and the positive SD16_A inputs A0+ (OA0), or A1+ (OA1).
22.3.4 OA Configurations
The OA can be configured for different amplifier functions with the OAFCx bits as listed in Table 226. The SWCTL0, SWCTL1, SWCTL4, and SWCTL5 bits force settings of the OAFCx bits. See section Switch Control for more details.
22-12
OA
Unity-Gain Mode
In this mode, the output of the OAx is connected directly to the inverting input of the OAx providing a unity-gain buffer. The non-inverting input is selected by the OAPx bits. The external connection for the inverting input is disabled, and the OANx bits are dont care.
OAxI1 OAxI2
00 01 10 11
0 1
OA0FB/A0(OA0) OA1FB/A1(OA1)
OA
22-13
00 01 10 11
22-14
OA
1 OAPx 0
A0(OA0) A1(OA1)
00 01 10 11 + OAx
VOffset
to SD16_A
OA
22-15
22-16
OA
Figure 22-- 10. MSP430FG47x Operational Amplifiers 0/1 (OA0/1) Block Diagram
OAPx 2 DAC12OPSx Control logic 1 OA0I0 DAC12_x 1 0
See Note 1
SWCTLx 3 OACALx
OAxI0
to Ax-
Vss
+ -
OAx
OAxO/Ax+
00 01 10 11 0 1
1 OAFCx = 110 00 01 10
1 0 OAFCx = 110 & SWCTL9 (OA0) OAFCx = 110 & SWCTL13 (OA1)
OAxFB
00 01 10
1 0
OAxRFB
OA
22-17
22.4.1 OA Amplifier
Each OA is a configurable low-current operational amplifier that can be configured as an inverting amplifier or a non-inverting amplifier.
22.4.2 OA Inputs
The OA has configurable input selection. The signals for the + and inputs are individually selected with the OANx and OAPx bits and can be selected as external signals or internal signals from the DAC12 module. One of the non-inverting inputs (OA0I0) is tied together internally for both OA modules. The SWCTL0, SWCTL1, SWCTL4, SWCTL5, SWCTL8, and SWCTL12 bits overwrite settings given by the OANx and OAPx bits. See section Switch Control for more details. Also the untiy gain buffer mode sets the input for the input of the OAx module to the OAx output.
22.4.3 OA Outputs
The OA outputs are routed to the respective output pin OAxOUT and the positive SD16_A inputs A0+ (OA0), or A1+ (OA1).
22.4.4 OA Configurations
The OA can be configured for different amplifier functions with the OAFCx bits as listed in Table 228. The SWCTL0, SWCTL1, SWCTL4, SWCTL5, SWCTL8, and SWCTL12 bits force settings of the OAFCx bits. See section Switch Control for more details.
22-18
OA
OA
22-19
OAPMx
OANx 2
SWCTLx
+ -
OAx
OAxO/Ax+
Control logic
00 01 10 11
00 01 10
OAxFB
1 0
OAxRFB
22-20
OA
2
C o n tro l lo g ic
D AC12O PSx
1
D AC 12_x
00 01
OAPMx
S e e N o te 1 V ss
to S D 1 6 _
10 11
OANx
SW C TLx
+ -
OAx
O A x O /A x +
2
C o n tro l lo g ic
O A x I1
00 01 10 11
O A x I2
O A x F B /A x -
O A x I3
N o te 1 : D A C 1 2 _ 0 is ro u te d to O A 1 . D A C 1 2 _ 1 is ro u te d to O A 0 o n ly if D A C 1 2 O P S 1 = 0 .
OA
22-21
22-22
OA
1 OAPx 0
A0(OA0) A1(OA1)
VOffset
to SD16_A
OA
22-23
OA Registers
22.5 OA Registers
The OA registers are listed in Table 2210.
22-24
OA
OA Registers
OANx
Bits 7-6
Inverting input select. These bits select the input signal for the OA inverting input. 00 OAxI0 01 OAxI1 10 DAC0 internal 11 DAC1 internal Non-inverting input select. These bits select the input signal for the OA non-inverting input. 00 OAxI0 01 OA0I1 10 DAC0 internal 11 DAC1 internal Slew rate select These bits select the slew rate vs. current consumption for the OA. 00 Off, output high Z 01 Slow 10 Medium 11 Fast OA output select. This bit connects the OAx output to ADC12 input Ax and output pin OAxO when OAFCx > 0. 0 OAx output not connected to internal/external A1 (OA0), A3 (OA1), or A5 (OA2) signals 1 OAx output connected to internal/external A1 (OA0), A3 (OA1), or A5 (OA2) signals OA output select. This bit connects the OAx output to ADC12 input Ax when OAPMx > 0. 0 OAx output not connected to internal A12 (OA0), A13 (OA1), or A14 (OA2) signals 1 OAx output connected to internal A12 (OA0), A13 (OA1), or A14 (OA2) signals
OAPx
Bits 5-4
OAPMx
Bits 3-2
OAADC1
Bit 1
OAADC0
Bit 0
OA
22-25
OA Registers
OAFBRx
Bits 7-5
feedback resistor select Tap 0 Tap 1 Tap 2 Tap 3 Tap 4 Tap 5 Tap 6 Tap 7
OAFCx
Bits 4-2
OAx function control. This bit selects the function of OAx 000 General purpose 001 Unity gain buffer 010 Reserved 011 Comparing amplifier 100 Non-inverting PGA 101 Reserved 110 Inverting PGA 111 Differential amplifier Reserved OA rail-to-rail input off. 0 OAx input signal range is rail-to-rail 1 OAx input signal range is limited. See the device-specific data sheet for parameters.
Reserved OARRIP
Bit 1 Bit 0
22-26
OA
OA
22-27
OANx
Bits 76
Inverting input select These bits select the input signal for the OAx inverting input. 00 OAxI1 01 OAxI2 10 DAC internal 11 VSS Non-inverting input select These bits select the input signal for the OAx non-inverting input. 00 OAxI0 01 OA0I0 10 DAC internal 11 VSS Slew rate select These bits select the slew rate vs. current consumption of the OAx. 00 Off, output high Z 01 Slow 10 Medium 11 Fast Reserved
OAPx
Bits 54
OAPMx
Bits 32
Reserved
Bits 10
22-28
OA
Reserved OAFCx
Bits 75 Bit 42
Reserved OAx function control These bits select the function of OAx 000 General purpose 001 Unity gain buffer 010 Reserved 011 Reserved 100 Reserved 101 Reserved 110 Inverting amplifier 111 Reserved Offset calibration This bit enables the offset calibration. 0 Offset calibration disabled 1 Offset calibration enabled Reserved
OACAL
Bit 1
Reserved
Bit 0
OA
22-29
SWCTL7
Bit 7
Shunt switch for OA1 0 Switch open 1 OA1OUT and OA1FB shorted together SW1C control 0 Switch open 1 SW1C shorted to VSS OANx and OAFCx forced settings for OA1 00 No forced settings 01 OANx forced to 00; OAFCx forced to 110. 10 OANx forced to 01; OAFCx forced to 110. 11 No forced settings Shunt switch for OA0 0 Switch open 1 OA0OUT and OA0FB shorted together SW0C control 0 Switch open 1 SW0C shorted to VSS OANx and OAFCx forced settings for OA0 00 No forced settings 01 OANx forced to 00; OAFCx forced to 110. 10 OANx forced to 01; OAFCx forced to 110. 11 No forced settings
SWCTL6
Bit 6
SWCTL5, SWCTL4
Bits 54
SWCTL3
Bit 3
SWCTL2
Bit 2
SWCTL1, SWCTL0
Bits 10
22-30
OA
OA
22-31
OANx
Bits 76
Inverting input select These bits select the input signal for the OAx inverting input. 00 OAxI1 01 OAxI2 10 OAxI3 11 DAC12_0 (OA0), DAC12_1 (OA1) if the DAC12OPS bits are cleared. Non-inverting input select These bits select the input signal for the OAx non-inverting input. 00 OAxI0 01 OA0I0 if DAC12OPS is set. If DAC12OPS is 0 then DAC12_0 (OA0)/ DAC12_1 (OA1) is used. 10 DAC12_1 (OA0)/ DAC12_0 (OA1) 11 VSS Slew rate select These bits select the slew rate vs. current consumption of the OAx. 00 Off, output high Z 01 Slow 10 Medium 11 Fast Reserved
OAPx
Bits 54
OAPMx
Bits 32
Reserved
Bits 10
22-32
OA
Reserved OAFCx
Bits 75 Bit 42
Reserved OAx function control These bits select the function of OAx 000 General purpose 001 Unity gain buffer 010 Reserved 011 Reserved 100 Reserved 101 Reserved 110 Inverting amplifier 111 Reserved Offset calibration This bit enables the offset calibration. 0 Offset calibration disabled 1 Offset calibration enabled Reserved
OACAL
Bit 1
Reserved
Bit 0
OA
22-33
7 Reserved r0
6 Reserved r0
5 SWCTL13 rw0
4 SWCTL12 rw0
3 Reserved r0
2 Reserved r0
1 SWCTL9 rw0
0 SWCTL8 rw0
SWCTL7
Bit 15
Shunt switch for OA1 0 Switch open 1 OA1OUT and OA1FB shorted together Reserved OANx and OAFCx forced settings for OA1 0 No forced settings 1 OA1I2 enabled; OAFCx forced to 110. OANx and OAFCx forced settings for OA1 0 No forced settings 1 OA1I1 enabled; OAFCx forced to 110. Shunt switch for OA0 0 Switch open 1 OA0OUT and OA0FB shorted together Reserved OANx and OAFCx forced settings for OA0 0 No forced settings 1 OA0I2 enabled; OAFCx forced to 110. OANx and OAFCx forced settings for OA0 0 No forced settings 1 OA0I1 enabled; OAFCx forced to 110. Reserved Range switch control for OA1 0 Switch open 1 Switch closed. OANx and OAFCx forced settings for OA1 0 No forced settings 1 OA1I3 enabled; OAFCx forced to 110. Reserved
Reserved SWCTL5
Bit 14 Bit 13
SWCTL4
Bit 12
SWCTL3
Bit 11
Reserved SWCTL1
Bit 10 Bit 9
SWCTL0
Bit 8
Reserved SWCTL13
Bits 76 Bit 5
SWCTL12
Bit 4
Reserved
Bits 32
22-34
OA
Bit 1
Range feedback switch control for OA0 0 Switch open 1 Switch closed. OANx and OAFCx forced settings for OA0 0 No forced settings 1 OA0I3 enabled; OAFCx forced to 110.
SWCTL8
Bit 0
OA
22-35
22-36
OA
Chapter 23
Comparator_A
Comparator_A is an analog voltage comparator. This chapter describes Comparator_A. Comparator_A is implemented in all MSP430x4xx devices.
Topic
Page
23.1 Comparator_A Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23-2 23.2 Comparator_A Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23-4 23.3 Comparator_A Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23-9
Comparator_A
23-1
Comparator_A Introduction
23-2
Comparator_A
Comparator_A Introduction
P2CA0 0 CA0
CAON CAF
0 1 0 1 ++ 0 1 P2CA1 1 0 1
CA1
0V
1 CAREFx
0 1
0.25x VCC
Comparator_A
23-3
Comparator_A Operation
23.2.1 Comparator
The comparator compares the analog voltages at the + and input terminals. If the + terminal is more positive than the terminal, the comparator output CAOUT is high. The comparator can be switched on or off using control bit CAON. The comparator should be switched off when not in use to reduce current consumption. When the comparator is switched off, the CAOUT is always low.
Internally, the input switch is constructed as a T-switch to suppress distortion in the signal path. Note: Comparator Input Connection
When the comparator is on, the input terminals should be connected to a signal, power, or ground. Otherwise, floating levels may cause unexpected interrupts and increased current consumption. The CAEX bit controls the input multiplexer, exchanging which input signals are connected to the comparators + and terminals. Additionally, when the comparator terminals are exchanged, the output signal from the comparator is inverted. This allows the user to determine or compensate for the comparator input offset voltage.
23-4
Comparator_A
Comparator_A Operation
Comparator_A
23-5
Comparator_A Operation
VI ICC
VO
ICC
VCC
VI 0 VCC
CAPD.x = 1
VSS
23-6
Comparator_A
Comparator_A Operation
0.25xVCC
The MSP430 resources used to calculate the temperature sensed by Rmeas are:
- Two digital I/O pins to charge and discharge the capacitor. - I/O set to output high (VCC) to charge capacitor, reset to discharge. - I/O switched to high-impedance input with CAPDx set when not in use. - One output charges and discharges the capacitor via Rref. - One output discharges capacitor via Rmeas. - The + terminal is connected to the positive terminal of the capacitor. - The terminal is connected to a reference level, for example 0.25 x VCC. - The output filter should be used to minimize switching noise. - CAOUT used to gate Timer_A CCI1B, capturing capacitor discharge time.
More than one resistive element can be measured. Additional elements are connected to CA0 with available I/O pins and switched to high impedance when not being measured.
Comparator_A
23-7
Comparator_A Operation
The thermistor measurement is based on a ratiometric conversion principle. The ratio of two capacitor discharge times is calculated as shown in Figure 236.
0.25 VCC
Rmeas Rref
Phase I: Charge Phase II: Discharge tref Phase III: Charge Phase IV: Discharge tmeas
The VCC voltage and the capacitor value should remain constant during the conversion, but are not critical since they cancel in the ratio: R meas R ref C C ln ln Vref V CC
N meas + N ref
Vref V CC
23-8
Comparator_A
Comparator_A Registers
Comparator_A
23-9
Comparator_A Registers
CAEX CARSEL
Bit 7 Bit 6
Comparator_A exchange. This bit exchanges the comparator inputs and inverts the comparator output. Comparator_A reference select. This bit selects which terminal the VCAREF is applied to. When CAEX = 0: 0 VCAREF is applied to the + terminal 1 VCAREF is applied to the terminal When CAEX = 1: 0 VCAREF is applied to the terminal 1 VCAREF is applied to the + terminal Comparator_A reference. These bits select the reference voltage VCAREF. 00 Internal reference off. An external reference can be applied. 01 0.25*VCC 10 0.50*VCC 11 Diode reference is selected Comparator_A on. This bit turns on the comparator. When the comparator is off it consumes no current. The reference circuitry is enabled or disabled independently. 0 Off 1 On Comparator_A interrupt edge select 0 Rising edge 1 Falling edge Comparator_A interrupt enable 0 Disabled 1 Enabled The Comparator_A interrupt flag 0 No interrupt pending 1 Interrupt pending
CAREF
Bits 5-4
CAON
Bit 3
CAIES
Bit 2
CAIE
Bit 1
CAIFG
Bit 0
23-10
Comparator_A
Comparator_A Registers
Unused P2CA1
Unused. Pin to CA1. This bit selects the CA1 pin function. 0 The pin is not connected to CA1 1 The pin is connected to CA1 Pin to CA0. This bit selects the CA0 pin function. 0 The pin is not connected to CA0 1 The pin is connected to CA0 Comparator_A output filter 0 Comparator_A output is not filtered 1 Comparator_A output is filtered Comparator_A output. This bit reflects the value of the comparator output. Writing this bit has no effect.
P2CA0
Bit 2
CAF
Bit 1
CAOUT
Bit 0
CAPDx
Bits 7-0
Comparator_A port disable. These bits individually disable the input buffer for the pins of the port associated with Comparator_A. For example, the CAPDx bits can be used to individually enable or disable each P1.x pin buffer. CAPD0 disables P1.0, CAPD1 disables P1.1, etc. 0 The input buffer is enabled. 1 The input buffer is disabled.
Comparator_A
23-11
23-12
Comparator_A
Chapter 24
Comparator_A+
Comparator_A+ is an analog voltage comparator. This chapter describes the operation of the Comparator_A+ of the 4xx family. It is available on the MSP430F41x2 devices.
Topic
Page
24.1 Comparator_A+ Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-2 24.2 Comparator_A+ Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-4 24.3 Comparator_A+ Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-10
Comparator_A+
24-1
Comparator_A+ Introduction
24-2
Comparator_A+
Comparator_A+ Introduction
Comparator_A+
24-3
Comparator_A+ Operation
24.2.1 Comparator
The comparator compares the analog voltages at the + and input terminals. If the + terminal is more positive than the terminal, the comparator output CAOUT is high. The comparator can be switched on or off using control bit CAON. The comparator should be switched off when not in use to reduce current consumption. When the comparator is switched off, the CAOUT is always low.
Internally, the input switch is constructed as a T-switch to suppress distortion in the signal path. Note: Comparator Input Connection
When the comparator is on, the input terminals should be connected to a signal, power, or ground. Otherwise, floating levels may cause unexpected interrupts and increased current consumption. The CAEX bit controls the input multiplexer, exchanging which input signals are connected to the comparators + and terminals. Additionally, when the comparator terminals are exchanged, the output signal from the comparator is inverted. This allows the user to determine or compensate for the comparator input offset voltage.
24-4
Comparator_A+
Comparator_A+ Operation
Sampling Capacitor, C s
CASHORT
Analog Inputs
The required sampling time is proportional to the size of the sampling capacitor (CS), the resistance of the input switches in series with the short switch (Ri), and the resistance of the external source (RS). The total internal resistance (RI) is typically in the range of 2 10 k. The sampling capacitor CS should be greater than 100pF. The time constant, Tau, to charge the sampling capacitor CS can be calculated with the following equation: Tau = (RI + RS) x CS Depending on the required accuracy 3 to 10 Tau should be used as a sampling time. With 3 Tau the sampling capacitor is charged to approximately 95% of the input signals voltage level, with 5 Tau it is charge to more than 99% and with 10 Tau the sampled voltage is sufficient for 12bit accuracy.
Comparator_A+
24-5
Comparator_A+ Operation
24-6
Comparator_A+
Comparator_A+ Operation
VI ICC
VO
ICC
VCC
VI 0 VCC
CAPD.x = 1
VSS
Comparator_A+
24-7
Comparator_A+ Operation
0.25xVCC
The MSP430 resources used to calculate the temperature sensed by Rmeas are:
- Two digital I/O pins to charge and discharge the capacitor. - I/O set to output high (VCC) to charge capacitor, reset to discharge. - I/O switched to high-impedance input with CAPDx set when not in use. - One output charges and discharges the capacitor via Rref. - One output discharges capacitor via Rmeas. - The + terminal is connected to the positive terminal of the capacitor. - The terminal is connected to a reference level, for example 0.25 x VCC. - The output filter should be used to minimize switching noise. - CAOUT used to gate Timer_A CCI1B, capturing capacitor discharge time.
More than one resistive element can be measured. Additional elements are connected to CA0 with available I/O pins and switched to high impedance when not being measured.
24-8
Comparator_A+
Comparator_A+ Operation
The thermistor measurement is based on a ratiometric conversion principle. The ratio of two capacitor discharge times is calculated as shown in Figure 247.
0.25 VCC
Rmeas Rref
Phase I: Charge Phase II: Discharge tref Phase III: Charge Phase IV: Discharge tmeas
The VCC voltage and the capacitor value should remain constant during the conversion, but are not critical since they cancel in the ratio: R meas R ref C C ln ln Vref V CC
N meas + N ref
Vref V CC
Comparator_A+
24-9
Comparator_A+ Registers
24-10
Comparator_A+
Comparator_A+ Registers
CAEX CARSEL
Bit 7 Bit 6
Comparator_A+ exchange. This bit exchanges the comparator inputs and inverts the comparator output. Comparator_A+ reference select. This bit selects which terminal the VCAREF is applied to. When CAEX = 0: 0 VCAREF is applied to the + terminal 1 VCAREF is applied to the terminal When CAEX = 1: 0 VCAREF is applied to the terminal 1 VCAREF is applied to the + terminal Comparator_A+ reference. These bits select the reference voltage VCAREF. 00 Internal reference off. An external reference can be applied. 01 0.25*VCC 10 0.50*VCC 11 Diode reference is selected Comparator_A+ on. This bit turns on the comparator. When the comparator is off it consumes no current. The reference circuitry is enabled or disabled independently. 0 Off 1 On Comparator_A+ interrupt edge select 0 Rising edge 1 Falling edge Comparator_A+ interrupt enable 0 Disabled 1 Enabled The Comparator_A+ interrupt flag 0 No interrupt pending 1 Interrupt pending
CAREF
Bits 5-4
CAON
Bit 3
CAIES
Bit 2
CAIE
Bit 1
CAIFG
Bit 0
Comparator_A+
24-11
Comparator_A+ Registers
CASHORT
Bit 7
Input short. This bit shorts the + and input terminals. 0 Inputs not shorted. 1 Inputs shorted. Input select. This bit together with P2CA0 selects the + terminal input when CAEX = 0 and the terminal input when CAEX = 1. Input select. These bits select the terminal input when CAEX = 0 and the + terminal input when CAEX = 1. 000 No connection 001 CA1 010 CA2 011 CA3 100 CA4 101 CA5 110 CA6 111 CA7 Input select. This bit, together with P2CA4, selects the + terminal input when CAEX = 0 and the terminal input when CAEX = 1. 00 No connection 01 CA0 10 CA1 11 CA2 Comparator_A+ output filter 0 Comparator_A+ output is not filtered 1 Comparator_A+ output is filtered Comparator_A+ output. This bit reflects the value of the comparator output. Writing this bit has no effect.
P2CA0
Bit 2
CAF
Bit 1
CAOUT
Bit 0
24-12
Comparator_A+
Comparator_A+ Registers
CAPDx
Bits 7-0
Comparator_A+ port disable. These bits individually disable the input buffer for the pins of the port associated with Comparator_A+. For example, if CA0 is on pin P2.3, the CAPDx bits can be used to individually enable or disable each port pin buffer. CAPD0 disables the pin associated with CA0, CAPD1 disables the pin connected associated with CA1, etc. 0 The input buffer is enabled. 1 The input buffer is disabled.
Comparator_A+
24-13
24-14
Comparator_A+
Chapter 25
LCD Controller
The LCD controller drives static, 2-mux, 3-mux, or 4-mux LCDs. This chapter describes LCD controller. The LCD controller is implemented on all MSP430x4xx devices, except the MSP430F41x2, MSP430x42x0, MSP430FG461x, MSP430F47x, MSP430FG47x, MSP430F47x3/4, and MSP430F471xx devices.
Topic
Page
25.1 LCD Controller Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-2 25.2 LCD Controller Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-4 25.3 LCD Controller Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-18
LCD Controller
25-1
Static 2-mux, 1/2 bias 3-mux, 1/3 bias 4-mux, 1/3 bias
The LCD controller block diagram is shown in Figure 251. Note: Max LCD Segment Control
The maximum number of segment lines available differs with device. See the device-specific datasheet for details.
25-2
LCD Controller
SEG38 Mux Display Memory 20x 8-bits Mux Segment Output Control SEG1 S1 S38
LCDP2 LCDP1 LCDP0 LCDMX1 LCDMX0 LCDSON LCDON VA VB VC VD V1 R33 Common Output Control
R f LCD (from Basic Timer) OSCOFF (from SR) Timing Generator V2 Analog Voltage V3 Multiplexer V4 V5 R23 R13 R03 Rx Rx Rx R R R R
LCD Controller
25-3
---------------------
---------------------
---------------------
---------------------
--------------------Sn
---------------------
Sn+1
25-4
LCD Controller
The LCDPx bits only affect pins with multiplexed LCD segment functions and digital I/O functions. Dedicated LCD segment pins are not affected by the LCDPx bits.
LCD Controller
25-5
SP6
SP1
a b
25-6
LCD Controller
Figure 254 shows an example static LCD, pinout, LCD-to-MSP430 connections, and the resulting segment mapping. This is only an example. Segment mapping in a users application depends on the LCD pinout and on the MSP430-to-LCD connections.
a b c h e d f g c h b e d f g
a b c h e d f g
a b c h
Display Memory COM MAB 0A0h 09Fh 09Eh 09Dh 09Ch 09Bh 09Ah 099h 098h 097h 096h 095h 094h 093h 092h 091h A 3 ----------------3 2 ----------------2 1 ----------------1 0 h f d b h f d b h f d b h f d b 0 3 ----------------3 2 ----------------2 1 ----------------1 0 g e c a g e c a g e c a g e c a 0 n = 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 0 A 0 G 3 B
Digit 4
Digit 3
Digit 2
Digit 1
G0 B 3
Parallel-Serial Conversion
Sn+1
Sn
LCD Controller
25-7
25-8
LCD Controller
V1 V5 V1 V3 0V V3 V1 V1 V3 0V V3 V5
SP4 SP3
SP2
LCD Controller
25-9
Figure 256 shows an example 2-mux LCD, pinout, LCD-to-MSP430 connections, and the resulting segment mapping. This is only an example. Segment mapping in a users application completely depends on the LCD pinout and on the MSP430-to-LCD connections.
a b c h e d DIGIT1 Display Memory COM MAB 0A0h 09Fh 09Eh 09Dh 09Ch 09Bh 09Ah 099h 098h 097h 096h 095h 094h 093h 092h 091h A 3 ----------------3 2 ----------------2 1 g b g b g b g b g b g b g b g b 1 0 e h e h e h e h e h e h e h e h 0 3 ----------------3 2 ----------------2 1 c a c a c a c a c a c a c a c a 1 0 d f d f d f d f d f d f d f d f 0 n = 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 0 A 0 G 3 B 1/2 Digit 8 f g c h b
0 G B 3
Sn+1
Sn
25-10
LCD Controller
........... ........... MOV.B Table(Rx),Ry ; ; MOV.B Ry,&LCDn ; ; ; ; RRA Ry ; RRA Ry ; MOV.B Ry,&LCDn+1 ; ; ........... ........... ........... Table DB a+b+c+d+e+f ........... DB a+b+c+d+e+f+g+ ........... ........... DB ........... ;
Load segment information into temporary memory. (Ry) = 0000 0000 gebh cdaf Note: All bits of an LCD memory byte are written (Ry) = 0000 0000 0geb hcda (Ry) = 0000 0000 00ge bhcd ; Note: All bits of an LCD memory byte are written
; displays 0 ; displays 8
LCD Controller
25-11
V1 V2 V4 V5 V1 V2 V4 V5 V1 V2 V4 V5 V1 V2 V4 V5 V1
SP = Segment Pin
SP3
V5 V1 V2 V4 V5 V1 0V V1 V1
0V V1
25-12
LCD Controller
Figure 258 shows an example 3-mux LCD, pinout, LCD-to-MSP430 connections, and the resulting segment mapping. This is only an example. Segment mapping in a users application depends on the LCD pinout and on the MSP430-to-LCD connections.
y b c h e d f g
a b c h DIGIT1
Display Memory
1 g c f g c f g c f g c f g c f g 1 0 d h e d h e d h e d h e d h e d 0 3 ----------------3 2 y a b y a b y a b y a b y a b y 2 1 f g c f g c f g c f g c f g c f 1 0 e d h e d h e d h e d h e d h e 0 n = 30 28 Digit 10 26 Digit 9 24 22 Digit 8 20 Digit 7 18 16 Digit 6 14 Digit 5 12 10 Digit 4 8 Digit 3 6 4 Digit 2 2 Digit 1 0 A Parallel0 Serial G 3 B Conversion
MAB 09Fh 09Eh 09Dh 09Ch 09Bh 09Ah 099h 098h 097h 096h 095h 094h 093h 092h 091h
A B G 0 3
Sn+1
Sn
LCD Controller
25-13
25-14
LCD Controller
V1 V2 V4 V5 V1 V2 V4 V5 V1 V2 V4 V5 V1 V2 V4 V5 V1 V2 V4 V5 V1 V2 V4 V5 V1
COM1
COM0 COM2
COM3
c SP1 SP2
SP1
SP = Segment Pin
SP2
0V V1 V1
0V V1
LCD Controller
25-15
Figure 2510 shows an example 4-mux LCD, pinout, LCD-to-MSP430 connections, and the resulting segment mapping. This is only an example. Segment mapping in a users application depends on the LCD pinout and on the MSP430-to-LCD connections.
MAB 09Fh 09Eh 09Dh 09Ch 09Bh 09Ah 099h 098h 097h 096h 095h 094h 093h 092h 091h
A B
Sn+1
Sn
25-16
LCD Controller
; displays 0 ; displays 1
LCD Controller
25-17
25-18
LCD Controller
LCDPx
Bits 7-5
LCD port select. These bits select the pin function to be port I/O or LCD function for groups of segments pins. These bits ONLY affect pins with multiplexed functions. Dedicated LCD pins are always LCD function. 000 No multiplexed pins are LCD function 001 S0-S15 are LCD function 010 S0-S19 are LCD function 011 S0-S23 are LCD function 100 S0-S27 are LCD function 101 S0-S31 are LCD function 110 S0-S35 are LCD function 111 S0-S39 are LCD function LCD mux rate. These bits select the LCD mode. 00 Static 01 2-mux 10 3-mux 11 4-mux LCD segments on. This bit supports flashing LCD applications by turning off all segment lines, while leaving the LCD timing generator and R33 enabled. 0 All LCD segments are off 1 All LCD segments are enabled and on or off according to their corresponding memory location. Unused LCD On. This bit turns on the LCD timing generator and R33. 0 LCD timing generator and Ron are off 1 LCD timing generator and Ron are on
LCDMXx
Bits 4-3
LCDSON
Bit 2
Unused LCDON
Bit 1 Bit 0
LCD Controller
25-19
25-20
LCD Controller
Chapter 26
LCD_A Controller
The LCD_A controller drives static, 2-mux, 3-mux, or 4-mux LCDs. This chapter describes the LCD_A controller. LCD_A controller is implemented on MSP430F41x2, MSP430x42x0, MSP430FG461x, MSP430F47x, MSP430FG47x, MSP430F47x3/4, and MSP430F471xx devices.
Topic
Page
26.1 LCD_A Controller Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-2 26.2 LCD_A Controller Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-4 26.3 LCD_A Controller Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-21
LCD_A Controller
26-1
Static 2-mux, 1/2 bias or 1/3 bias 3-mux, 1/2 bias or 1/3 bias 4-mux, 1/2 bias or 1/3 bias
The LCD controller block diagram is shown in Figure 261. Note: Maximum LCD Segment Control
The maximum number of segment lines available differs with device. See the device-specific data sheet for available segment pins.
26-2
LCD_A Controller
SEG38 Mux Display Memory 20x 8bits Mux Segment Output Control SEG1 S1 S38
LCDFREQx
LCDON
VLCD
ACLK 32768 Hz
fLCD
Timing Generator
LCDMXx REXT VLCDREFx VLCDx 4 Regulated Charge Pump/ Contrast Control VLCD
R03EXT V1 V2
V3 V4 V5
LCDCPEN
LCD2B
LCD_A Controller
26-3
---------------------
---------------------
---------------------
---------------------
--------------------Sn
---------------------
Sn+1
26-4
LCD_A Controller
A 4.7 F or larger capacitor must be connected from pin LCDCAP to ground when the internal charge pump is enabled. Otherwise, damage can occur. The internal charge pump may use an external reference voltage when VLCDREFx = 01. In this case, the charge pump voltage will be 3x the voltage applied externally to the LCDREF pin and the VLCDx bits are ignored. When VLCDEXT = 1, VLCD is sourced externally from the LCDCAP pin and the internal charge pump is disabled. The charge pump and internal bias generation require an input clock source of 32768 Hz +/ 10%. If neither is used, the input clock frequency may be different per the application needs.
LCD_A Controller
26-5
To source the bias voltages V2 V4 externally, REXT is set. This also disables the internal bias generation. Typically an equally weighted resistor divider is used with resistors ranging from 100 kW to 1 MW. When using an external resistor divider, the VLCD voltage may be sourced from the internal charge pump when VLCDEXT = 0. V5 can also be sourced externally when R03EXT is set. When using an external resistor divider R33 may serve as a switched-VLCD output when VLCDEXT = 0. This allows the power to the resistor ladder to be turned off eliminating current consumption when the LCD is not used. When VLCDEXT = 1, R33 serves as a VLCD input.
Charge Pump
VLCD
Internal V LCD
R23 R R
V2 (2/3 VLCD)
0 R03 Rx Rx Rx Optional External Resistors Rx = Optional Contrast Control Static 1/2 Bias 1/3 Bias 1 R03EXT V5
26-6
LCD_A Controller
The internal bias generator supports 1/2 bias LCDs when LCD2B = 1, and 1/3 bias LCDs when LCD2B = 0 in 2-mux, 3-mux, and 4-mux modes. In static mode, the internal divider is disabled. Some devices share the LCDCAP, R33, and R23 functions. In this case, the charge pump cannot be used together with an external resistor divider with 1/3 biasing. When R03 is not available externally, V5 is always AVSS.
00 01 01 10 10 11 11
X 1 0 1 0 1 0
1 2 2 3 3 4 4
V1, V5 V1, V3, V5 V1, V2, V4, V5 V1, V3, V5 V1, V2, V4, V5 V1, V3, V5 V1, V2, V4, V5
A typical approach to determine the required VLCD is by equating VRMS,OFF with a defined LCD threshold voltage, typically when the LCD exhibits approximately 10% contrast (Vth,10%): VRMS,OFF = Vth,10%. Using the values for VRMS,OFF/VLCD provided in the table results in VLCD = Vth,10%/(VRMS,OFF/VLCD). In the static mode, a suitable choice is VLCD greater or equal than 3 times Vth,10%. In 3-mux and 4-mux mode typically a 1/3 biasing is used but a 1/2 biasing scheme is also possible. The 1/2 bias reduces the contrast ratio but the advantage is a reduction of the required full-scale LCD voltage VLCD.
LCD_A Controller
26-7
If pins that share digital I/O and LCD functions are used as digital I/Os they should not be toggled at frequencies >10kHz while the LCD is enabled (LCDON=1); otherwise, increased current consumption could be observed. The LCDSx bits selects the LCD function in groups of four pins. When LCDSx = 0, no multiplexed pin is set to LCD function. When LCDSx = 1, the complete group of four is selected as LCD function. Note: LCDSx Bits Do Not Affect Dedicated LCD Segment Pins
The LCDSx bits only affect pins with multiplexed LCD segment functions and digital I/O functions. Dedicated LCD segment pins are not affected by the LCDSx bits.
26-8
LCD_A Controller
SP6
SP1
a b
LCD_A Controller
26-9
Figure 265 shows an example static LCD, pinout, LCD-to-MSP430 connections, and the resulting segment mapping. This is only an example. Segment mapping in a users application depends on the LCD pinout and on the MSP430-to-LCD connections.
Display Memory COM MAB 0A0h 09Fh 09Eh 09Dh 09Ch 09Bh 09Ah 099h 098h 097h 096h 095h 094h 093h 092h 091h A 3 ----------------3 2 ----------------2 1 ----------------1 0 h f d b h f d b h f d b h f d b 0 3 ----------------3 2 ----------------2 1 ----------------1 0 g e c a g e c a g e c a g e c a 0 n = 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 0 A 0 G 3 B
Digit 4
Digit 3
Digit 2
Digit 1
G0 B 3
Parallel-Serial Conversion
Sn+1
Sn
26-10
LCD_A Controller
LCD_A Controller
26-11
V1 V5 V1 V3 0V V3 V1 V1 V3 0V V3 V5
SP4 SP3
SP2
26-12
LCD_A Controller
Figure 267 shows an example 2-mux LCD, pinout, LCD-to-MSP430 connections, and the resulting segment mapping. This is only an example. Segment mapping in a users application completely depends on the LCD pinout and on the MSP430-to-LCD connections.
a b c h e d DIGIT1 Display Memory COM MAB 0A0h 09Fh 09Eh 09Dh 09Ch 09Bh 09Ah 099h 098h 097h 096h 095h 094h 093h 092h 091h A 3 ----------------3 2 ----------------2 1 g b g b g b g b g b g b g b g b 1 0 e h e h e h e h e h e h e h e h 0 3 ----------------3 2 ----------------2 1 c a c a c a c a c a c a c a c a 1 0 d f d f d f d f d f d f d f d f 0 n = 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 0 A 0 G 3 B 1/2 Digit 8 f g c h b
0 G B 3
Sn+1
Sn
LCD_A Controller
26-13
........... ........... MOV.B Table(Rx),Ry ; ; MOV.B Ry,&LCDn ; ; ; ; RRA Ry ; RRA Ry ; MOV.B Ry,&LCDn+1 ; ; ........... ........... ........... Table DB a+b+c+d+e+f ........... DB a+b+c+d+e+f+g ........... ........... DB ........... ;
Load segment information into temporary memory. (Ry) = 0000 0000 gebh cdaf Note: All bits of an LCD memory byte are written (Ry) = 0000 0000 0geb hcda (Ry) = 0000 0000 00ge bhcd ; Note: All bits of an LCD memory byte are written
; displays 0 ; displays 8
26-14
LCD_A Controller
V1 V2 V4 V5 V1 V2 V4 V5 V1 V2 V4 V5 V1 V2 V4 V5 V1
V5 V1 SP3 V5 V1
SP = Segment Pin
0V V1 V1
0V V1
LCD_A Controller
26-15
Figure 269 shows an example 3-mux LCD, pinout, LCD-to-MSP430 connections, and the resulting segment mapping. This is only an example. Segment mapping in a users application depends on the LCD pinout and on the MSP430-to-LCD connections.
y b c h e d f g
a b c h DIGIT1
Display Memory
1 g c f g c f g c f g c f g c f g 1 0 d h e d h e d h e d h e d h e d 0 3 ----------------3 2 y a b y a b y a b y a b y a b y 2 1 f g c f g c f g c f g c f g c f 1 0 e d h e d h e d h e d h e d h e 0 n = 30 28 Digit 10 26 Digit 9 24 22 Digit 8 20 Digit 7 18 16 Digit 6 14 Digit 5 12 10 Digit 4 8 Digit 3 6 4 Digit 2 2 Digit 1 0 A Parallel0 Serial G 3 B Conversion
MAB 09Fh 09Eh 09Dh 09Ch 09Bh 09Ah 099h 098h 097h 096h 095h 094h 093h 092h 091h
A B G 0 3
Sn+1
Sn
26-16
LCD_A Controller
LCD_A Controller
26-17
V1 V2 V4 V5 V1 V2 V4 V5 V1 V2 V4 V5 V1 V2 V4 V5 V1 V2 V4 V5 V1 V2 V4 V5 V1
COM1
COM0 COM2
COM3
c SP1 SP2
SP1
SP = Segment Pin
SP2
0V V1 V1
0V V1
26-18
LCD_A Controller
Figure 2611 shows an example 4-mux LCD, pinout, LCD-to-MSP430 connections, and the resulting segment mapping. This is only an example. Segment mapping in a users application depends on the LCD pinout and on the MSP430-to-LCD connections.
MAB 09Fh 09Eh 09Dh 09Ch 09Bh 09Ah 099h 098h 097h 096h 095h 094h 093h 092h 091h
A B
Sn+1
Sn
LCD_A Controller
26-19
; displays 0 ; displays 1
26-20
LCD_A Controller
LCD_A Controller
26-21
LCDFREQx
Bits 7-5
LCD frequency select. These bits select the ACLK divider for the LCD frequency. 000 Divide by 32 001 Divide by 64 010 Divide by 96 011 Divide by 128 100 Divide by 192 101 Divide by 256 110 Divide by 384 111 Divide by 512 LCD mux rate. These bits select the LCD mode. 00 Static 01 2-mux 10 3-mux 11 4-mux LCD segments on. This bit supports flashing LCD applications by turning off all segment lines, while leaving the LCD timing generator and R33 enabled. 0 All LCD segments are off 1 All LCD segments are enabled and on or off according to their corresponding memory location. Unused LCD On. This bit turns on the LCD_A module. 0 LCD_A module off. 1 LCD_A module on.
LCDMXx
Bits 4-3
LCDSON
Bit 2
Unused LCDON
Bit 1 Bit 0
26-22
LCD_A Controller
Segments S0S3 on the MSP430FG461x devices are disabled from LCD functionality when charge pump is enabled.
LCDS28
Bit 7
LCD segment 28 to 31 enable This bit only affects pins with multiplexed functions. Dedicated LCD pins are always LCD function. 0 Multiplexed pins are port functions. 1 Pins are LCD functions LCD segment 24 to 27 enable This bit only affects pins with multiplexed functions. Dedicated LCD pins are always LCD function. 0 Multiplexed pins are port functions. 1 Pins are LCD functions LCD segment 20 to 23 enable This bit only affects pins with multiplexed functions. Dedicated LCD pins are always LCD function. 0 Multiplexed pins are port functions. 1 Pins are LCD functions LCD segment 16 to 19 enable This bit only affects pins with multiplexed functions. Dedicated LCD pins are always LCD function. 0 Multiplexed pins are port functions. 1 Pins are LCD functions LCD segment 12 to 15 enable This bit only affects pins with multiplexed functions. Dedicated LCD pins are always LCD function. 0 Multiplexed pins are port functions. 1 Pins are LCD functions LCD segment 8 to 11 enable This bit only affects pins with multiplexed functions. Dedicated LCD pins are always LCD function. 0 Multiplexed pins are port functions. 1 Pins are LCD functions LCD segment 4 to 7 enable This bit only affects pins with multiplexed functions. Dedicated LCD pins are always LCD function. 0 Multiplexed pins are port functions. 1 Pins are LCD functions LCD segment 0 to 3 enable This bit only affects pins with multiplexed functions. Dedicated LCD pins are always LCD function. 0 Multiplexed pins are port functions. 1 Pins are LCD functions
LCDS24
Bit 6
LCDS20
Bit 5
LCDS16
Bit 4
LCDS12
Bit 3
LCDS8
Bit 2
LCDS4
Bit 1
LCDS0
Bit 0
LCD_A Controller
26-23
Unused LCDS36
Bits 72 Bit 1
Unused LCD segment 36 to 39 enable This bit only affects pins with multiplexed functions. Dedicated LCD pins are always LCD function. 0 Multiplexed pins are port functions. 1 Pins are LCD functions LCD segment 32 to 35 enable This bit only affects pins with multiplexed functions. Dedicated LCD pins are always LCD function. 0 Multiplexed pins are port functions. 1 Pins are LCD functions
LCDS32
Bit 0
26-24
LCD_A Controller
Unused R03EXT
Bit 7 Bit 6
Unused V5 voltage select. This bit selects the external connection for the lowest LCD voltage. R03EXT is ignored if there is no R03 pin available. 0 V5 is AVSS 1 V5 is sourced from the R03 pin V2 V4 voltage select. This bit selects the external connections for voltages V2 V4. 0 V2 V4 are generated internally 1 V2 V4 are sourced externally and the internal bias generator is switched off VLCD source select 0 VLCD is generated internally 1 VLCD is sourced externally Charge pump enable. 0 Charge pump disabled. 1 Charge pump enabled when VLCD is generated internally (VLCDEXT = 0) and VLCDx > 0 or VLCDREFx > 0. Charge pump reference select 00 Internal 01 External 10 Reserved 11 Reserved Bias select. LCD2B is ignored when LCDMx = 00. 0 1/3 bias 1 1/2 bias
REXT
Bit 5
VLCDEXT
Bit 4
LCDCPEN
Bit 3
VLCDREFx
Bits 21
LCD2B
Bit 0
LCD_A Controller
26-25
Unused VLCDx
Bits 75 Bits 41
Unused Charge pump voltage select. LCDCPEN must be 1 for the charge pump to be enabled. AVCC is used for VLCD when VLCDx = 0000 and VREFx = 00 and VLCDEXT = 0. 0000 Charge pump disabled 0001 VLCD = 2.60 V 0010 VLCD = 2.66 V 0011 VLCD = 2.72 V 0100 VLCD = 2.78 V 0101 VLCD = 2.84 V 0110 VLCD = 2.90 V 0111 VLCD = 2.96 V 1000 VLCD = 3.02 V 1001 VLCD = 3.08 V 1010 VLCD = 3.14 V 1011 VLCD = 3.20 V 1100 VLCD = 3.26 V 1101 VLCD = 3.32 V 1110 VLCD = 3.38 V 1111 VLCD = 3.44 V Unused
Unused
Bit 0
26-26
LCD_A Controller
Chapter 27
ADC10
The ADC10 module is a high-performance 10-bit analog-to-digital converter. This chapter describes the operation of the ADC10 module of the 4xx family. The ADC10 is implemented on the MSP4340F41x2 devices.
Topic
Page
16.1 ADC10 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-2 16.2 ADC10 Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-4 16.3 ADC10 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-24
ADC10
27-1
ADC10 Introduction
references
- Selectable conversion clock source - Single-channel, repeated single-channel, sequence, and repeated
27-2
ADC10
ADC10 Introduction
REFOUT SREF1 0 1
VREF +
AVCC
A0 A1 A2 A3 A4 A5 A6 A7
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
SREF2
AVCC INCHx=0Bh
ADC10DF
ADC10MEM Ref_x R Data Transfer Controller ADC10SA R AVSS ADC10CT ADC10TB ADC10B1 n RAM, Flash, Peripherials
Not all devices support all channels. See the devices specific datasheet for details.
ADC10
27-3
ADC10 Operation
The ADC10 core is configured by two control registers, ADC10CTL0 and ADC10CTL1. The core is enabled with the ADC10ON bit. With few exceptions the ADC10 control bits can only be modified when ENC = 0. ENC must be set to 1 before any conversion can take place.
27-4
ADC10
ADC10 Operation
Ax
ESD Protection
Analog Port Selection The ADC10 external inputs Ax, VeREF+, and VREF share terminals with general purpose I/O ports, which are digital CMOS gates (see device-specific datasheet). When analog signals are applied to digital CMOS gates, parasitic current can flow from VCC to GND. This parasitic current occurs if the input voltage is near the transition level of the gate. Disabling the port pin buffer eliminates the parasitic current flow and therefore reduces overall current consumption. The ADC10AEx bits provide the ability to disable the port pin input and output buffers.
; P7.5 on MSP430x41x2 device configured for analog input BIS.B #01h,&ADC10AE0 ; P7.5 ADC10 function and enable
ADC10
27-5
ADC10 Operation
27-6
ADC10
ADC10 Operation
The ADC10SC bit The Timer_A0 Output Unit 1 The Timer_A1 Output Unit 0 The Timer_A1 Output Unit 1
The polarity of the SHI signal source can be inverted with the ISSH bit. The SHTx bits select the sample period tsample to be 4, 8, 16, or 64 ADC10CLK cycles. The sampling timer sets SAMPCON high for the selected sample period after synchronization with ADC10CLK. Total sampling time is tsample plus tsync.The high-to-low SAMPCON transition starts the analog-to-digital conversion, which requires 11 ADC10CLK cycles as shown in Figure 273.
SHI
13 x ADC10CLKs tconvert
ADC10
27-7
ADC10 Operation
MSP430 RS VS RI VC CI VI = Input voltage at pin Ax VS = External source voltage RS = External source resistance RI = Internal MUX-on input resistance CI = Input capacitance VC = Capacitance-charging voltage
VI
The resistance of the source RS and RI affect tsample.The following equations can be used to calculate the minimum sampling time for a 10-bit conversion. t sample u (R S ) RI) ln(2 11) CI
Substituting the values for RI and CI given above, the equation becomes: t sample u (R S ) 2k) 7.625 27pF
For example, if RS is 10 k, tsample must be greater than 2.47 s. When the reference buffer is used in burst mode, the sampling time must be greater than the sampling time calculated and the settling time of the buffer, tREFBURST:
sample
(R S ) R I) t REFBURST
ln(2 11)
CI
For example, if VRef is 1.5 V and RS is 10 k, tsample must be greater than 2.47 s when ADC10SR = 0, or 2.5 s when ADC10SR = 1. See the device-specific datasheet for parameters. To calculate the buffer settling time when using an external reference, the formula is: t REFBURST + SR Where: SR: Vref: Buffer slew rate (~1 s/V when ADC10SR = 0 and ~2 s/V when ADC10SR = 1) External reference voltage VRef * 0.5ms
27-8
ADC10
ADC10 Operation
01
10
11
ADC10
27-9
ADC10 Operation
ADC10ON = 1
x = INCHx Wait for Enable ENC = SHS = 0 and ENC = 1 or and ADC10SC = ENC =
ENC = 0
ENC = 0
12 x ADC10CLK Convert ENC = 0 1 x ADC10CLK Conversion Completed, Result to ADC10MEM, ADC10IFG is Set
x = input channel Ax Conversion result is unpredictable
27-10
ADC10
ADC10 Operation
Sequence-of-Channels Mode
A sequence of channels is sampled and converted once. The sequence begins with the channel selected by INCHx and decrements to channel A0. Each ADC result is written to ADC10MEM. The sequence stops after conversion of channel A0. Figure 276 shows the sequence-of-channels mode. When ADC10SC triggers a sequence, successive sequences can be triggered by the ADC10SC bit . When any other trigger source is used, ENC must be toggled between each sequence.
ADC10ON = 1 ENC =
x = INCHx Wait for Enable ENC = SHS = 0 and ENC = 1 or and ADC10SC = ENC =
x=0
If x > 0 then x = x 1
If x > 0 then x = x 1
12 x ADC10CLK MSC = 1 and x0 Convert MSC = 0 and x0 1 x ADC10CLK Conversion Completed, Result to ADC10MEM, ADC10IFG is Set
x = input channel Ax
ADC10
27-11
ADC10 Operation
Repeat-Single-Channel Mode
A single channel selected by INCHx is sampled and converted continuously. Each ADC result is written to ADC10MEM. Figure 277 shows the repeat-single-channel mode.
ADC10ON = 1
x = INCHx Wait for Enable ENC = SHS = 0 and ENC = 1 or and ADC10SC = ENC =
ENC = 0
12 x ADC10CLK MSC = 1 and ENC = 1 Convert MSC = 0 and ENC = 1 1 x ADC10CLK Conversion Completed, Result to ADC10MEM, ADC10IFG is Set
x = input channel Ax
27-12
ADC10
ADC10 Operation
Repeat-Sequence-of-Channels Mode
A sequence of channels is sampled and converted repeatedly. The sequence begins with the channel selected by INCHx and decrements to channel A0. Each ADC result is written to ADC10MEM. The sequence ends after conversion of channel A0, and the next trigger signal re-starts the sequence. Figure 278 shows the repeat-sequence-of-channels mode.
x = INCHx Wait for Enable ENC = SHS = 0 and ENC = 1 or and ADC10SC = ENC =
x = input channel Ax
ADC10
27-13
ADC10 Operation
Stopping Conversions
Stopping ADC10 activity depends on the mode of operation. The recommended ways to stop an active conversion or conversion sequence are:
- Resetting ENC in single-channel single-conversion mode stops a
conversion immediately and the results are unpredictable. For correct results, poll the ADC10BUSY bit until reset before clearing ENC.
- Resetting ENC during repeat-single-channel operation stops the
27-14
ADC10
ADC10 Operation
ADC10
27-15
ADC10 Operation
ADC10SA+2 ADC10SA
The internal address pointer is initially equal to ADC10SA and the internal transfer counter is initially equal to n. The internal pointer and counter are not visible to software. The DTC transfers the word-value of ADC10MEM to the address pointer ADC10SA. After each DTC transfer, the internal address pointer is incremented by two and the internal transfer counter is decremented by one. The DTC transfers continue with each loading of ADC10MEM, until the internal transfer counter becomes equal to zero. No additional DTC transfers will occur until a write to ADC10SA. When using the DTC in the one-block mode, the ADC10IFG flag is set only after a complete block has been transferred. Figure 2710 shows a state diagram of the one-block mode.
27-16
ADC10
ADC10 Operation
Figure 2710. State Diagram for Data Transfer Control in One-Block Transfer Mode
n=0 (ADC10DTC1)
DTC reset
n0 Wait for write to ADC10SA n=0 DTC init Initialize Start Address in ADC10SA Prepare DTC
x=0
ADC10IFG=1
ADC10
27-17
ADC10 Operation
DTC
nth transfer
ADC10SA+2n2 ADC10SA+2n4
ADC10SA+2 ADC10SA
The internal address pointer is initially equal to ADC10SA and the internal transfer counter is initially equal to n. The internal pointer and counter are not visible to software. The DTC transfers the word-value of ADC10MEM to the address pointer ADC10SA. After each DTC transfer the internal address pointer is incremented by two and the internal transfer counter is decremented by one. The DTC transfers continue, with each loading of ADC10MEM, until the internal transfer counter becomes equal to zero. At this point, block one is full and both the ADC10IFG flag the ADC10B1 bit are set. The user can test the ADC10B1 bit to determine that block one is full. The DTC continues with block two. The internal transfer counter is automatically reloaded with n. At the next load of the ADC10MEM, the DTC begins transferring conversion results to block two. After n transfers have completed, block two is full. The ADC10IFG flag is set and the ADC10B1 bit is cleared. User software can test the cleared ADC10B1 bit to determine that block two is full. Figure 2712 shows a state diagram of the two-block mode.
27-18
ADC10
ADC10 Operation
Figure 2712. State Diagram for Data Transfer Control in Two-Block Transfer Mode
n0 n=0 Wait for write to ADC10SA Initialize Start Address in ADC10SA Prepare DTC
DTC init
Write to ADC10SA x=n If ADC10B1 = 0 then AD = SA Write to ADC10SA or n=0 DTC idle n is latched in counter x Wait until ADC10MEM is written
Transfer data to Address AD AD = AD + 2 x=x1 x=0 ADC10B1 = 1 or ADC10CT=1 ADC10CT = 0 and ADC10B1 = 0
ADC10
27-19
ADC10 Operation
Continuous Transfer
A continuous transfer is selected if ADC10CT bit is set. The DTC will not stop after block one in (one-block mode) or block two (two-block mode) has been transferred. The internal address pointer and transfer counter are set equal to ADC10SA and n respectively. Transfers continue starting in block one. If the ADC10CT bit is reset, DTC transfers cease after the current completion of transfers into block one (in the one-block mode) or block two (in the two-block mode) have been transfer.
Low-power mode LPM0/1 MCLK=DCOCLK Low-power mode LPM3/4 MCLK=DCOCLK Low-power mode LPM0/1 MCLK=LFXT1CLK Low-power mode LPM3 Low-power mode LPM4
MCLK=LFXT1CLK MCLK=LFXT1CLK
The additional 2 s are needed to start the DCOCLK. See device-datasheet for parameters.
27-20
ADC10
ADC10 Operation
1.200
1.100
1.000
ADC10
27-21
ADC10 Operation
Figure 27-- 14. ADC10 Grounding and Noise Considerations (internal Vref).
DVCC Digital Power Supply Decoupling DVSS 10uF Analog Power Supply Decoupling (if available) 10uF 100nF 100nF AVCC
AVSS
Figure 27-- 15. ADC10 Grounding and Noise Considerations (external Vref).
DVCC Digital Power Supply Decoupling DVSS 10uF Analog Power Supply Decoupling (if available) 10uF Using an External Positive Reference Using an External Negative Reference 100nF VREF+/VeREF+ VREF-/VeREF100nF AVCC
AVSS
27-22
ADC10
ADC10 Operation
D Reset
ADC10
27-23
ADC10 Registers
27-24
ADC10
ADC10 Registers
7 MSC rw(0)
6 REF2_5V rw(0)
5 REFON rw(0)
4 ADC10ON rw(0)
3 ADC10IE rw(0)
2 ADC10IFG rw(0)
1 ENC rw(0)
0 ADC10SC rw(0)
SREFx
Bits 15-13
Select reference 000 VR+ = VCC and VR = VSS 001 VR+ = VREF+ and VR = VSS 010 VR+ = VeREF+ and VR = VSS 011 VR+ = Buffered VeREF+ and VR = VSS 100 VR+ = VCC and VR = VREF/ VeREF 101 VR+ = VREF+ and VR = VREF/ VeREF 110 VR+ = VeREF+ and VR = VREF/ VeREF 111 VR+ = Buffered VeREF+ and VR = VREF/ VeREF ADC10 sample-and-hold time 00 4 x ADC10CLKs 01 8 x ADC10CLKs 10 16 x ADC10CLKs 11 64 x ADC10CLKs ADC10 sampling rate. This bit selects the reference buffer drive capability for the maximum sampling rate. Setting ADC10SR reduces the current consumption of the reference buffer. 0 Reference buffer supports up to ~200 ksps 1 Reference buffer supports up to ~50 ksps Reference output 0 Reference output off 1 Reference output on Reference burst. 0 Reference buffer on continuously 1 Reference buffer on only during sample-and-conversion
ADC10 SHTx
Bits 12-11
ADC10SR
Bit 10
REFOUT
Bit 9
REFBURST
Bit 8
ADC10
27-25
Bit 7
Multiple sample and conversion. Valid only for sequence or repeated modes. 0 The sampling requires a rising edge of the SHI signal to trigger each sample-and-conversion. 1 The first rising edge of the SHI signal triggers the sampling timer, but further sample-and-conversions are performed automatically as soon as the prior conversion is completed Reference-generator voltage. REFON must also be set. 0 1.5 V 1 2.5 V Reference generator on 0 Reference off 1 Reference on ADC10 on 0 ADC10 off 1 ADC10 on ADC10 interrupt enable 0 Interrupt disabled 1 interrupt enabled ADC10 interrupt flag. This bit is set if ADC10MEM is loaded with a conversion result. It is automatically reset when the interrupt request is accepted, or it may be reset by software. When using the DTC this flag is set when a block of transfers is completed. 0 No interrupt pending 1 Interrupt pending Enable conversion 0 ADC10 disabled 1 ADC10 enabled Start conversion. Software-controlled sample-and-conversion start. ADC10SC and ENC may be set together with one instruction. ADC10SC is reset automatically. 0 No sample-and-conversion start 1 Start sample-and-conversion
REF2_5V
Bit 6
REFON
Bit 5
ADC10ON
Bit 4
ADC10IE
Bit 3
ADC10IFG
Bit 2
ENC
Bit 1
ADC10SC
Bit 0
27-26
ADC10
ADC10 Registers
6 ADC10DIVx
2 CONSEQx rw(0)
0 ADC10 BUSY r0
rw(0)
rw(0)
rw(0)
INCHx
Bits 15-12
Input channel select. These bits select the channel for a single-conversion or the highest channel for a sequence of conversions. 0000 A0 0001 A1 0010 A2 0011 A3 0100 A4 0101 A5 0110 A6 0111 A7 1000 VeREF+ 1001 VREF /VeREF 1010 Temperature sensor 1011 (VCC VSS) / 2 1100 (VCC VSS) / 2, A12 on MSP430x22xx devices 1101 (VCC VSS) / 2, A13 on MSP430x22xx devices 1110 (VCC VSS) / 2, A14 on MSP430x22xx devices 1111 (VCC VSS) / 2, A15 on MSP430x22xx devices Sample-and-hold source select. For The MSP430F41x2 devices: 00 ADC10SC bit 01 Timer_A0.OUT1 10 Timer_A1.OUT0 11 Timer_A1.OUT1 ADC10 data format 0 Straight binary 1 2s complement Invert signal sample-and-hold 0 The sample-input signal is not inverted. 1 The sample-input signal is inverted.
SHSx
Bits 11-10
ADC10DF
Bit 9
ISSH
Bit 8
ADC10
27-27
Bits 7-5
ADC10 clock divider 000 /1 001 /2 010 /3 011 /4 100 /5 101 /6 110 /7 111 /8 ADC10 clock source select 00 ADC10OSC 01 ACLK 10 MCLK 11 SMCLK Conversion sequence mode select 00 Single-channel-single-conversion 01 Sequence-of-channels 10 Repeat-single-channel 11 Repeat-sequence-of-channels ADC10 busy. This bit indicates an active sample or conversion operation 0 No operation is active. 1 A sequence, sample, or conversion is active.
ADC10 SSELx
Bits 4-3
CONSEQx
Bits 2-1
ADC10 BUSY
Bit 0
27-28
ADC10
ADC10 Registers
ADC10AE0x Bits
7-0
ADC10 analog enable. These bits enable the corresponding pin for analog input. BIT0 corresponds to A0, BIT1 corresponds to A1, etc. 0 Analog input disabled 1 Analog input enabled
ADC10AE1x Bits
7-4
ADC10 analog enable. These bits enable the corresponding pin for analog input. BIT4 corresponds to A12, BIT5 corresponds to A13, BIT6 corresponds to A14, and BIT7 corresponds to A15. 0 Analog input disabled 1 Analog input enabled
ADC10
27-29
ADC10 Registers
Conversion Results r r
Conversion Results r r r r r r r r
Conversion Results
Bits 15-0
The 10-bit conversion results are right justified, straight-binary format. Bit 9 is the MSB. Bits 15-10 are always 0.
Conversion Results r r r r r r r r
5 0 r0
4 0 r0
3 0 r0
2 0 r0
1 0 r0
0 0 r0
Conversion Results r r
Conversion Results
Bits 15-0
The 10-bit conversion results are left-justified, 2s complement format. Bit 15 is the MSB. Bits 5-0 are always 0.
27-30
ADC10
ADC10 Registers
Reserved
Reserved. Always read as 0. ADC10 two-block mode. 0 One-block transfer mode 1 Two-block transfer mode ADC10 continuous transfer. 0 Data transfer stops when one block (one-block mode) or two blocks (two-block mode) have completed. 1 Data is transferred continuously. DTC operation is stopped only if ADC10CT cleared, or ADC10SA is written to. ADC10 block one. This bit indicates for two-block mode which block is filled with ADC10 conversion results. ADC10B1 is valid only after ADC10IFG has been set the first time during DTC operation. ADC10TB must also be set. 0 Block 2 is filled 1 Block 1 is filled This bit should normally be reset.
ADC10TB
ADC10CT
Bit 2
ADC10B1
Bit 1
ADC10 FETCH
Bit 0
ADC10
27-31
ADC10 Registers
DTC Transfers rw(0) rw(0) rw(0) rw(0) rw(0) rw(0) rw(0) rw(0)
DTC Transfers
Bits 7-0
DTC transfers. These bits define the number of transfers in each block. 0 DTC is disabled 01h-0FFh Number of transfers per block
4 ADC10SAx
0 0
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
r0
ADC10SAx
ADC10 start address. These bits are the start address for the DTC. A write to register ADC10SA is required to initiate DTC transfers. Unused, Read only. Always read as 0.
Unused
27-32
ADC10
Chapter 28
ADC12
The ADC12 module is a high-performance 12-bit analog-to-digital converter (ADC). This chapter describes the ADC12. The ADC12 is implemented in the MSP430x43x MSP430x44x, and MSP430FG461x devices.
Topic
Page
28.1 ADC12 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-2 28.2 ADC12 Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-4 28.3 ADC12 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-20
ADC12
28-1
ADC12 Introduction
software or timers.
- Conversion initiation by software, Timer_A, or Timer_B - Software selectable on-chip reference voltage generation (1.5 V or 2.5 V) - Software selectable internal or external reference - Eight individually configurable external input channels (twelve on
references
- Independent channel-selectable reference sources for both positive and
negative references
- Selectable conversion clock source - Single-channel, repeat-single-channel, sequence, and repeat-sequence
conversion modes
- ADC core and reference voltage can be powered down separately - Interrupt vector register for fast decoding of 18 ADC interrupts - 16 conversion-result storage registers
28-2
ADC12
ADC12 Introduction
REF2_5V Ve REF+ VREF+ VREF / Ve REF AVCC INCHx 4 A0 A1 A2 A3 A4 A5 A6 A7 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 SREF2 1 AVSS 0 11 10 01 00 SREF1 SREF0 Ref_x on 1.5 V or 2.5 V Reference
REFON INCHx=0Ah
AVCC
ADC12OSC ADC12SSELx
ADC12ON
ADC12DIVx Sample and Hold S/H VR VR+ Divider /1 .. /8 ADC12CLK BUSY SHP SHT0x 4 1 Sample Timer /4 .. /1024 4 SHT1x INCHx=0Bh Ref_x ADC12MEM0 CSTARTADDx 16 x 12 Memory Buffer ADC12MEM15 ADC12MCTL0 16 x 8 Memory Control ADC12MCTL15 MSC SHI 0 1 Sync ISSH ENC 00 01 10 11 ADC12SC TA1 TB0 TB1 00 01 10 11 ACLK MCLK SMCLK
SHSx
AVCC
SAMPCON
R AVSS
CONSEQx
ADC12
28-3
ADC12 Operation
The ADC12 core is configured by two control registers, ADC12CTL0 and ADC12CTL1. The core is enabled with the ADC12ON bit. The ADC12 can be turned off when not in use to save power. With few exceptions the ADC12 control bits can only be modified when ENC = 0. ENC must be set to 1 before any conversion can take place.
28-4
ADC12
ADC12 Operation
Ax
ESD Protection
ADC12
28-5
ADC12 Operation
Approximately 200 A is required from any reference used by the ADC12 while the two LSBs are being resolved during a conversion. A parallel combination of 10-F and 0.1-F capacitors is recommended for any reference used as shown in Figure 2811. External references may be supplied for VR+ and VR through pins VeREF+ and VREF/VeREF respectively.
28-6
ADC12
ADC12 Operation
The ADC12SC bit The Timer_A Output Unit 1 The Timer_B Output Unit 0 The Timer_B Output Unit 1
The polarity of the SHI signal source can be inverted with the ISSH bit. The SAMPCON signal controls the sample period and start of conversion. When SAMPCON is high, sampling is active. The high-to-low SAMPCON transition starts the analog-to-digital conversion, which requires 13 ADC12CLK cycles. Two different sample-timing methods are defined by control bit SHP, extended sample mode and pulse mode.
SHI
13 x ADC12CLK tconvert
ADC12
28-7
ADC12 Operation
SHI
13 x ADC12CLK tconvert
28-8
ADC12
ADC12 Operation
MSP430 RS VS RI VC CI VI = Input voltage at pin Ax VS = External source voltage RS = External source resistance RI = Internal MUX-on input resistance CI = Input capacitance VC = Capacitance-charging voltage
VI
The resistance of the source RS and RI affect tsample. The following equation can be used to calculate the minimum sampling time tsample for a 12-bit conversion: t sample u (R S ) RI) ln(2 13) C I ) 800ns
Substituting the values for RI and CI given above, the equation becomes: t sample u (R S ) 2kW) 9.011 40pF ) 800ns
ADC12
28-9
ADC12 Operation
01
10
11
28-10
ADC12
ADC12 Operation
CONSEQx = 00
ADC12 off
ADC12ON = 1 ENC =
x = CSTARTADDx Wait for Enable ENC = SHSx = 0 and ENC = 1 or and ADC12SC = ENC = 0 ENC =
Wait for Trigger SAMPCON = SAMPCON = 1 Sample, Input Channel Defined in ADC12MCTLx
ENC = 0
SAMPCON = 12 x ADC12CLK Convert ENC = 0 1 x ADC12CLK Conversion Completed, Result Stored Into ADC12MEMx, ADC12IFG.x is Set
ADC12
28-11
ADC12 Operation
Sequence-of-Channels Mode
A sequence of channels is sampled and converted once. The ADC results are written to the conversion memories starting with the ADCMEMx defined by the CSTARTADDx bits. The sequence stops after the measurement of the channel with a set EOS bit. Figure 287 shows the sequence-of-channels mode. When ADC12SC triggers a sequence, successive sequences can be triggered by the ADC12SC bit. When any other trigger source is used, ENC must be toggled between each sequence.
CONSEQx = 01
x = CSTARTADDx Wait for Enable ENC = SHSx = 0 and ENC = 1 or and ADC12SC = ENC =
Wait for Trigger SAMPCON = SAMPCON = 1 Sample, Input Channel Defined in ADC12MCTLx EOS.x = 1
SAMPCON = MSC = 1 and SHP = 1 and EOS.x = 0 (MSC = 0 or SHP = 0) and EOS.x = 0
Convert
x = pointer to ADC12MCTLx
28-12
ADC12
ADC12 Operation
Repeat-Single-Channel Mode
A single channel is sampled and converted continuously. The ADC results are written to the ADC12MEMx defined by the CSTARTADDx bits. It is necessary to read the result after the completed conversion because only one ADC12MEMx memory is used and is overwritten by the next conversion. Figure 288 shows repeat-single-channel mode
CONSEQx = 10
x = CSTARTADDx Wait for Enable ENC = SHSx = 0 and ENC = 1 or and ADC12SC = ENC =
Sample, Input Channel Defined in ADC12MCTLx SAMPCON = 12 x ADC12CLK MSC = 1 and SHP = 1 and ENC = 1 Convert (MSC = 0 or SHP = 0) and ENC = 1
x = pointer to ADC12MCTLx
ADC12
28-13
ADC12 Operation
Repeat-Sequence-of-Channels Mode
A sequence of channels is sampled and converted repeatedly. The ADC results are written to the conversion memories starting with the ADC12MEMx defined by the CSTARTADDx bits. The sequence ends after the measurement of the channel with a set EOS bit and the next trigger signal re-starts the sequence. Figure 289 shows the repeat-sequence-of-channels mode.
CONSEQx = 11
x = CSTARTADDx Wait for Enable ENC = SHSx = 0 and ENC = 1 or and ADC12SC = ENC =
Sample, Input Channel Defined in ADC12MCTLx SAMPCON = If EOS.x = 1 then x = CSTARTADDx else {if x < 15 then x = x + 1 else x = 0} MSC = 1 and SHP = 1 and (ENC = 1 or EOS.x = 0)
Convert
x = pointer to ADC12MCTLx
28-14
ADC12
ADC12 Operation
Stopping Conversions
Stopping ADC12 activity depends on the mode of operation. The recommended ways to stop an active conversion or conversion sequence are:
- Resetting ENC in single-channel single-conversion mode stops a
conversion immediately and the results are unpredictable. For correct results, poll the busy bit until reset before clearing ENC.
- Resetting ENC during repeat-single-channel operation stops the
CONSEQx = 0 and resetting ENC bit. Conversion data are unreliable. Note: No EOS Bit Set For Sequence
If no EOS bit is set and a sequence mode is selected, resetting the ENC bit does not stop the sequence. To stop the sequence, first select a single-channel mode and then reset ENC.
ADC12
28-15
ADC12 Operation
1.200
1.100
1.000
28-16
ADC12
ADC12 Operation
100 nF
Using an External + Positive Reference 10 uF Using the Internal + Reference Generator 10 uF Using an External + Negative Reference 10 uF
100 nF VREF+
100 nF
ADC12
28-17
ADC12 Operation
The ADC12IFGx bits are set when their corresponding ADC12MEMx memory register is loaded with a conversion result. An interrupt request is generated if the corresponding ADC12IEx bit and the GIE bit are set. The ADC12OV condition occurs when a conversion result is written to any ADC12MEMx before its previous conversion result was read. The ADC12TOV condition is generated when another sample-and-conversion is requested before the current conversion is completed. The DMA is triggered after the conversion in single channel modes or after the completion of a sequenceofchannel modes.
28-18
ADC12
ADC12 Operation
16 cycles 14 cycles
The interrupt handler for ADC12IFG15 shows a way to check immediately if a higher prioritized interrupt occurred during the processing of ADC12IFG15. This saves nine cycles if another ADC12 interrupt is pending.
; Interrupt handler for ADC12. INT_ADC12 ; Enter Interrupt Service Routine 6 ADD &ADC12IV,PC; Add offset to PC 3 RETI ; Vector 0: No interrupt 5 JMP ADOV ; Vector 2: ADC overflow 2 JMP ADTOV ; Vector 4: ADC timing overflow 2 JMP ADM0 ; Vector 6: ADC12IFG0 2 ... ; Vectors 8-32 2 JMP ADM14 ; Vector 34: ADC12IFG14 2 ; ; Handler for ADC12IFG15 starts here. No JMP required. ; ADM15 MOV &ADC12MEM15,xxx ; Move result, flag is reset ... ; Other instruction needed? JMP INT_ADC12 ; Check other int pending
;
;
;
ADC12IFG14-ADC12IFG1 handlers go here MOV &ADC12MEM0,xxx ; Move result, flag is reset ... ; Other instruction needed? RETI ; Return 5
... RETI ... RETI ; Handle Conv. time overflow ; Return ; Handle ADCMEMx overflow ; Return
ADM0
; ADTOV ; ADOV
ADC12
28-19
ADC12 Registers
28-20
ADC12
ADC12 Registers
7 MSC rw(0)
6 REF2_5V rw(0)
5 REFON rw(0)
4 ADC12ON rw(0)
3 ADC12OVIE rw(0)
1 ENC rw(0)
0 ADC12SC rw(0)
SHT1x
Sample-and-hold time. These bits define the number of ADC12CLK cycles in the sampling period for registers ADC12MEM8 to ADC12MEM15. Sample-and-hold time. These bits define the number of ADC12CLK cycles in the sampling period for registers ADC12MEM0 to ADC12MEM7.
SHTx Bits 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 ADC12CLK cycles 4 8 16 32 64 96 128 192 256 384 512 768 1024 1024 1024 1024
SHT0x
ADC12
28-21
Bit 7
Multiple sample and conversion. Valid only for sequence or repeated modes. 0 The sampling timer requires a rising edge of the SHI signal to trigger each sample-and-conversion. 1 The first rising edge of the SHI signal triggers the sampling timer, but further sample-and-conversions are performed automatically as soon as the prior conversion is completed. Reference generator voltage. REFON must also be set. 0 1.5 V 1 2.5 V Reference generator on 0 Reference off 1 Reference on ADC12 on 0 ADC12 off 1 ADC12 on ADC12MEMx overflow-interrupt enable. The GIE bit must also be set to enable the interrupt. 0 Overflow interrupt disabled 1 Overflow interrupt enabled ADC12 conversion-time-overflow interrupt enable. The GIE bit must also be set to enable the interrupt. 0 Conversion time overflow interrupt disabled 1 Conversion time overflow interrupt enabled Enable conversion 0 ADC12 disabled 1 ADC12 enabled Start conversion. Software-controlled sample-and-conversion start. ADC12SC and ENC may be set together with one instruction. ADC12SC is reset automatically. 0 No sample-and-conversion-start 1 Start sample-and-conversion
REF2_5V
Bit 6
REFON
Bit 5
ADC12ON
Bit 4
ADC12OVIE Bit 3
ADC12 TOVIE
Bit 2
ENC
Bit 1
ADC12SC
Bit 0
28-22
ADC12
ADC12 Registers
6 ADC12DIVx
2 CONSEQx rw(0)
rw(0)
rw(0)
rw(0)
CSTART ADDx
Bits 15-12
Conversion start address. These bits select which ADC12 conversion-memory register is used for a single conversion or for the first conversion in a sequence. The value of CSTARTADDx is 0 to 0Fh, corresponding to ADC12MEM0 to ADC12MEM15. Sample-and-hold source select 00 ADC12SC bit 01 Timer_A.OUT1 10 Timer_B.OUT0 11 Timer_B.OUT1 Sample-and-hold pulse-mode select. This bit selects the source of the sampling signal (SAMPCON) to be either the output of the sampling timer or the sample-input signal directly. 0 SAMPCON signal is sourced from the sample-input signal. 1 SAMPCON signal is sourced from the sampling timer. Invert signal sample-and-hold 0 The sample-input signal is not inverted. 1 The sample-input signal is inverted. ADC12 clock divider 000 /1 001 /2 010 /3 011 /4 100 /5 101 /6 110 /7 111 /8
SHSx
Bits 11-10
SHP
Bit 9
ISSH
Bit 8
ADC12DIVx
Bits 7-5
ADC12
28-23
Bits 4-3
ADC12 clock source select 00 ADC12OSC 01 ACLK 10 MCLK 11 SMCLK Conversion sequence mode select 00 Single-channel, single-conversion 01 Sequence-of-channels 10 Repeat-single-channel 11 Repeat-sequence-of-channels ADC12 busy. This bit indicates an active sample or conversion operation. 0 No operation is active. 1 A sequence, sample, or conversion is active.
CONSEQx
Bits 2-1
ADC12 BUSY
Bit 0
Conversion Results rw rw rw
Conversion Results rw rw rw rw rw rw rw rw
Conversion Results
Bits 15-0
The 12-bit conversion results are right-justified. Bit 11 is the MSB. Bits 15-12 are always 0. Writing to the conversion memory registers will corrupt the results.
28-24
ADC12
ADC12 Registers
EOS
Bit 7
End of sequence. Indicates the last conversion in a sequence. 0 Not end of sequence 1 End of sequence Select reference 000 VR+ = AVCC and VR = AVSS 001 VR+ = VREF+ and VR = AVSS 010 VR+ = VeREF+ and VR = AVSS 011 VR+ = VeREF+ and VR = AVSS 100 VR+ = AVCC and VR = VREF/ VeREF 101 VR+ = VREF+ and VR = VREF/ VeREF 110 VR+ = VeREF+ and VR = VREF/ VeREF 111 VR+ = VeREF+ and VR = VREF/ VeREF Input channel select 0000 A0 0001 A1 0010 A2 0011 A3 0100 A4 0101 A5 0110 A6 0111 A7 1000 VeREF+ 1001 VREF /VeREF 1010 Temperature sensor 1011 (AVCC AVSS) / 2 1100 (AVCC AVSS) / 2, A12 on FG43x and FG461x devices 1101 (AVCC AVSS) / 2, A13 on FG43x and FG461x devices 1110 (AVCC AVSS) / 2, A14 on FG43x and FG461x devices 1111 (AVCC AVSS) / 2, A15 on FG43x and FG461x devices
SREFx
Bits 6-4
INCHx
Bits 3-0
ADC12
28-25
ADC12 Registers
7 ADC12IE7 rw(0)
6 ADC12IE6 rw(0)
5 ADC12IE5 rw(0)
4 ADC12IE4 rw(0)
3 ADC12IE3 rw(0)
2 ADC12IE2 rw(0)
1 ADC12IE1 rw(0)
0 ADC12IE0 rw(0)
ADC12IEx
Bits 15-0
Interrupt enable. These bits enable or disable the interrupt request for the ADC12IFGx bits. 0 Interrupt disabled 1 Interrupt enabled
ADC12IFGx
Bits 15-0
ADC12MEMx Interrupt flag. These bits are set when corresponding ADC12MEMx is loaded with a conversion result. The ADC12IFGx bits are reset if the corresponding ADC12MEMx is accessed, or may be reset with software. 0 No interrupt pending 1 Interrupt pending
28-26
ADC12
ADC12 Registers
7 0 r0
6 0 r0
3 ADC12IVx
0 0
r(0)
r(0)
r(0)
r(0)
r(0)
r0
ADC12IVx
Bits 15-0
ADC12IV Contents 000h 002h 004h 006h 008h 00Ah 00Ch 00Eh 010h 012h 014h 016h 018h 01Ah 01Ch 01Eh 020h 022h 024h
Interrupt Source No interrupt pending ADC12MEMx overflow Conversion time overflow ADC12MEM0 interrupt flag ADC12MEM1 interrupt flag ADC12MEM2 interrupt flag ADC12MEM3 interrupt flag ADC12MEM4 interrupt flag ADC12MEM5 interrupt flag ADC12MEM6 interrupt flag ADC12MEM7 interrupt flag ADC12MEM8 interrupt flag ADC12MEM9 interrupt flag ADC12MEM10 interrupt flag ADC12MEM11 interrupt flag ADC12MEM12 interrupt flag ADC12MEM13 interrupt flag ADC12MEM14 interrupt flag ADC12MEM15 interrupt flag
Interrupt Flag ADC12IFG0 ADC12IFG1 ADC12IFG2 ADC12IFG3 ADC12IFG4 ADC12IFG5 ADC12IFG6 ADC12IFG7 ADC12IFG8 ADC12IFG9 ADC12IFG10 ADC12IFG11 ADC12IFG12 ADC12IFG13 ADC12IFG14 ADC12IFG15
Interrupt Priority
Highest
Lowest
ADC12
28-27
28-28
ADC12
Chapter 29
SD16
The SD16 module is a multichannel 16-bit sigma-delta analog-to-digital converter. This chapter describes the SD16 of the MSP430x4xx family. The SD16 module is implemented in the MSP430F42x, MSP430F42xA, MSP430FE42x, MSP430FE42xA, and MSP430FE42x2 devices.
Topic
Page
29.1 SD16 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-2 29.2 SD16 Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-4 29.3 SD16 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-19
SD16
29-1
SD16 Introduction
(The number of channels is device dependent, see the device-specific data sheet.)
- Up to eight multiplexed differential analog inputs per channel
(The number of inputs is device dependent, see the device-specific data sheet.)
- Software selectable on-chip reference voltage generation (1.2 V) - Software selectable internal or external reference - Built-in temperature sensor accessible by all channels - Up to 1.048576-MHz modulator input frequency - Selectable low-power conversion mode
29-2
SD16
SD16 Introduction
SD16VMIDON Temperature sensor Reference fM Channel 0 Conversion Control (to prior channel) SD16GRP SD16SC SD16SNGL Channel 1
Temperature sensor
Reference
fM
SD16INCHx
+ + + + + + + +
000 001 010 011 100 101 110 111 SD16LP 7 PGA 1..32 2nd Order Modulator SD16GAINx
SD16DF
SD16PRE1
Channel 2
SD16
29-3
SD16 Operation
For a 1.2V reference, the maximum full-scale input range for a gain of 1 is: 1.2V2 +" 0.6 V 1 Refer to the device-specific data sheet for full-scale input specifications. " V FSR +
29-4
SD16
SD16 Operation
SD16
29-5
SD16 Operation
MSP430 RS VS+ CS AVCC / 2 CS RS VS 1 kW 1 kW VS+ VS RS CS = Positive external source voltage = Negative external source voltage = External source resistance = Sampling capacitance
The maximum modulator frequency fM may be calculated from the minimum settling time tSettling of the sampling circuit given by: t Settling w (RS ) 1kW) where fM + AVCC AV CC 1 and V Ax + max * V S) , * VS* , 2 2 t Settling CS ln
GAIN
2 17 VREF
VAx
with VS+ and VS referenced to AVSS. CS varies with the gain setting as shown in Table 291.
29-6
SD16
SD16 Operation
p
f fM
f fM
where the oversampling rate, OSR, is the ratio of the modulator frequency fM to the sample frequency fS. Figure 293 shows the filters frequency response for an OSR of 32. The first filter notch is at fS = fM/OSR. The notch frequency can be adjusted by changing the modulator frequency, fM, using SD16SSELx and SD16DIVx and the oversampling rate using SD16OSRx. The digital filter for each enabled ADC channel completes the decimation of the digital bit-stream and outputs new conversion results to the corresponding SD16MEMx register at the sample frequency fS.
SD16
29-7
SD16 Operation
Figure 294 shows the digital filter step response and conversion points. For step changes at the input after start of conversion a settling time must be allowed before a valid conversion result is available. The SD16INTDLYx bits can provide sufficient filter settling time for a full-scale change at the ADC input. If the step occurs synchronously to the decimation of the digital filter the valid data will be available on the third conversion. An asynchronous step will require one additional conversion before valid data is available.
0.6
0.4
0.2 1 0
Conversion
0.2
0
Conversion
29-8
SD16
SD16 Operation
OSR=128, LSBACC=1 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OSR=64, LSBACC=0 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OSR=64, LSBACC=1 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OSR=32, LSBACC=x 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SD16
29-9
SD16 Operation
Digital Filter Output (OSR = 256) FFFFFF 800000 000000 7FFFFF 000000 800000
Twos complement
ZERO FSR
Figure 296 shows the relationship between the full-scale input voltage range from VFSR to +VFSR and the conversion result. The digital values for both data formats are illustrated.
29-10
SD16
SD16 Operation
A channel is grouped and is the master channel of the group when SD16GRP = 0 if SD16GRP for the prior channel(s) is set.
SD16
29-11
SD16 Operation
Cleared by SW Time
29-12
SD16
SD16 Operation
Cleared by SW Conversion
Conversion
Cleared by SW Time
SD16
29-13
SD16 Operation
The SD16PREx delay is applied to the beginning of the next conversion cycle after being written. The delay is used on the first conversion after SD16SC is set and on the conversion cycle following each write to SD16PREx. Following conversions are not delayed. After modifying SD16PREx, the next write to SD16PREx should not occur until the next conversion cycle is completed, otherwise the conversion results may be incorrect. The accuracy of the result for the delayed conversion cycle using SD16PREx is dependent on the length of the delay and the frequency of the analog signal being sampled. For example, when measuring a DC signal, SD16PREx delay has no effect on the conversion result regardless of the duration. The user must determine when the delayed conversion result is useful in their application. Figure 2910 shows the operation of grouped channels 0 and 1. The preload register of channel 1 is loaded with zero resulting in immediate conversion whereas the conversion cycle of channel 0 is delayed by setting SD16PRE0 = 8. The first channel 0 conversion uses SD16PREx = 8, shifting all subsequent conversions by 8 fM clock cycles.
29-14
SD16
SD16 Operation
Start of Conversion
Time
When channels are grouped, care must be taken when a channel or channels operate in single conversion mode or are disabled in software while the master channel remains active. Each time channels in the group are re-enabled and resynchronized with the master channel, the preload delay for that channel will be reintroduced. Figure 2911 shows the re-synchronization and preload delays for channels in a group. It is recommended that SD16PREx = 0 for the master channel to maintain a consistent delay between the master and remaining channels in the group when they are re-enabled.
Cleared by SW Set by SW (syncronized to master) PRE1 Set by SW Conversion Conversion Autoclear Conv Conversion
SD16
29-15
SD16 Operation
0.450
0.400
0.350
0.300
0.250
29-16
SD16
SD16 Operation
The SD16IFG bits are set when their corresponding SD16MEMx memory register is written with a conversion result. An interrupt request is generated if the corresponding SD16IE bit and the GIE bit are set. The SD16 overflow condition occurs when a conversion result is written to any SD16MEMx location before the previous conversion result was read.
SD16
29-17
SD16 Operation
16 cycles 14 cycles
The interrupt handler for channel 2 SD16IFG shows a way to check immediately if a higher prioritized interrupt occurred during the processing of the ISR. This saves nine cycles if another SD16 interrupt is pending.
; Interrupt handler for SD16. INT_SD16 ; Enter Interrupt Service Routine 6 ADD &SD16IV,PC; Add offset to PC 3 RETI ; Vector 0: No interrupt 5 JMP ADOV ; Vector 2: ADC overflow 2 JMP ADM0 ; Vector 4: CH_0 SD16IFG 2 JMP ADM1 ; Vector 6: CH_1 SD16IFG 2 ; ; Handler for CH_2 SD16IFG starts here. No JMP required. ; ADM2 MOV &SD16MEM2,xxx ; Move result, flag is reset ... ; Other instruction needed? JMP INT_SD16 ; Check other int pending 2
;
; Move result, flag is reset ; Other instruction needed? ; Return 5 ; Move result, flag is reset
; Return ; Handle SD16MEMx overflow ; Return 5
ADM0
; ADOV
MOV &SD16MEM0,xxx
RETI ... RETI
29-18
SD16
SD16 Registers
SD16
29-19
SD16 Registers
7 SD16DIVx rw0
5 SD16SSELx rw0
1 SD16OVIE rw0
0 Reserved r0
rw0
rw0
Reserved
Reserved Low-power mode. This bit selects a reduced-speed reduced-power mode for the SD16. 0 Low-power mode is disabled 1 Low-power mode is enabled. The maximum clock frequency for the SD16 is reduced. SD16 clock divider 00 /1 01 /2 10 /4 11 /8 SD16 clock source select 00 MCLK 01 SMCLK 10 ACLK 11 External TACLK VMID buffer on 0 Off 1 On Reference generator on 0 Reference off 1 Reference on SD16 overflow interrupt enable. The GIE bit must also be set to enable the interrupt. 0 Overflow interrupt disabled 1 Overflow interrupt enabled Reserved
SD16LP
SD16DIVx
Bits 7-6
SD16SSELx Bits
5-4
SD16 VMIDON
Bit 3
SD16 REFON
Bit 2
SD16OVIE
Bit 1
Reserved
Bit 0
29-20
SD16
SD16 Registers
4 SD16DF rw0
3 SD16IE rw0
2 SD16IFG rw0
1 SD16SC rw0
0 SD16GRP r(w)0
Reserved
Reserved Single conversion mode select 0 Continuous conversion mode 1 Single conversion mode Oversampling ratio 00 256 01 128 10 64 11 32 LSB toggle. This bit, when set, causes SD16LSBACC to toggle each time the SD16MEMx register is read. 0 SD16LSBACC does not toggle with each SD16MEMx read 1 SD16LSBACC toggles with each SD16MEMx read LSB access. This bit allows access to the upper or lower 16-bits of the SD16 conversion result. 0 SD16MEMx contains the most significant 16-bits of the conversion. 1 SD16MEMx contains the least significant 16-bits of the conversion. SD16 overflow interrupt flag 0 No overflow interrupt pending 1 Overflow interrupt pending SD16 data format 0 Offset binary 1 2s complement SD16 interrupt enable 0 Disabled 1 Enabled
SD16SNGL
SD16OSRx
Bits 9-8
SD16 LSBTOG
Bit 7
SD16 LSBACC
Bit 6
SD16OVIFG
Bit 5
SD16DF
Bit 4
SD16IE
Bit 3
SD16
29-21
Bit 2
SD16 interrupt flag. SD16IFG is set when new conversion results are available. SD16IFG is automatically reset when the corresponding SD16MEMx register is read, or may be cleared with software. 0 No interrupt pending 1 Interrupt pending SD16 start conversion 0 No conversion start 1 Start conversion SD16 group. Groups SD16 channel with next higher channel. Not used for the last channel. 0 Not grouped 1 Grouped
SD16SC
Bit 1
SD16GRP
Bit 0
SD16 INTDLYx
Bits 7-6
Interrupt delay generation after conversion start. These bits select the delay for the first interrupt after conversion start. 00 Fourth sample causes interrupt 01 Third sample causes interrupt 10 Second sample causes interrupt 11 First sample causes interrupt SD16 preamplifier gain 000 x1 001 x2 010 x4 011 x8 100 x16 101 x32 110 Reserved 111 Reserved SD16 channel differential pair input 000 Ax.0 001 Ax.1 010 Ax.2 011 Ax.3 100 Ax.4 101 Ax.5 110 Ax.6- Temperature Sensor 111 Ax.7- Short for PGA offset measurement
SD16GAINx
Bits 5-3
SD16INCHx
Bits 2-0
29-22
SD16
SD16 Registers
Conversion Results r r r r r r r r
Conversion Results r r r r r r r r
Conversion Result
Bits 15-0
Conversion Results. The SD16MEMx register holds the upper or lower 16-bits of the digital filter output, depending on the SD16LSBACC bit.
Preload Value rw0 rw0 rw0 rw0 rw0 rw0 rw0 rw0
Bits 7-0
SD16
29-23
SD16 Registers
7 0 r0
6 0 r0
5 0 r0
3 SD16IVx
0 0
r0
r0
r0
r0
r0
SD16IVx
Bits 15-0
SD16IV Contents 000h 002h 004h 006h 008h 00Ah 00Ch 00Eh 010h
Interrupt Source No interrupt pending SD16MEMx overflow SD16_0 Interrupt SD16_1 Interrupt SD16_2 Interrupt Reserved Reserved Reserved Reserved
Interrupt Flag SD16CCTLx SD16OVIFG SD16CCTL0 SD16IFG SD16CCTL1 SD16IFG SD16CCTL1 SD16IFG
Interrupt Priority
Highest
Lowest
When an SD16 overflow occurs, the user must check all SD16CCTLx SD16OVIFG flags to determine which channel overflowed.
29-24
SD16
Chapter 30
SD16_A
The SD16_A module is a multichannel 16-bit sigma-delta analog-to-digital converter (ADC). This chapter describes the SD16_A of the MSP430x4xx family. The SD16_A module is implemented in the MSP430F42x0, MSP430FG42x0, MSP430F47x , MSP430FG47x, MSP430F47x3/4, and MSP430F471xx devices.
Topic
Page
30.1 SD16_A Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-2 30.2 SD16_A Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-5 30.3 SD16_A Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-22
SD16_A
30-1
SD16_A Introduction
(The number of channels is device dependent, see the device-specific data sheet.)
- Up to eight multiplexed differential analog inputs per channel
(The number of inputs is device dependent, see the device-specific data sheet.)
- Software selectable on-chip reference voltage generation (1.2 V) - Software selectable internal or external reference - Built-in temperature sensor accessible by all channels - Up to 1.1-MHz modulator input frequency - High impedance input buffer
The block diagram of the SD16_A module is shown in Figure 301 for the MSP430F47x3/4 and MSP430F471xx. The block diagram of the SD16_A module is shown in Figure 302 for the MSP430F42x0, MSP430F47x, MSP430FG47x, and MSP430FG42x0.
30-2
SD16_A
SD16_A Introduction
AVCC
Channel 0 Channel 1 Conversion Control (to prior channel) SD16INCHx Group/Start Conversion Logic SD16GRP SD16SC SD16SGNL Conversion Control (from next channel) SD16GAINx PGA 1..32 2ndOrder Modulator SD16OSRx 15 SD16MEM1 0
+ + + + + + + +
SD16XOSR SD16PRE1
SD16UNI SD16DF
Channel 2 Channel 3 ( up to Channel 6) Reference Temperature. and Vcc Sense AVCC Temp. sensor 1 SD16INCHx=101 5R R 5R
Note:
Ax.1 to Ax.4 not available on all devices. See device-specific data sheet.
SD16_A
30-3
SD16_A Introduction
Figure 302. Block Diagram of the MSP430F42x0, MSP430FG42x0, MSP430FG47x, and MSP430F47x SD16_A
SD16REFON VREF 0 Reference 1.2V SD16SSELx SD16XDIVx SD16DIVx 00 AV SS Reference fM Divider 1/3/16/48 Divider 1/2/4/8 01 10 11 SD16VMIDON Start Conversion Logic SD16SC SD16SNGL MCLK SMCLK ACLK TACLK
AV CC
SD16INCHx
A0 A1 A2 A3 A4 A5 A6 A7
+ + + + + + + +
000 001 010 011 100 101 110 111 Reference AVCC Temp. sensor 1 SD16INCHx=101 5R R 5R SD16LP SD16UNI SD16DF SD16XOSR BUF PGA 1..32 2ndOrder Modulator SD16BUFx SD16GAINx SD16OSRx 15 SD16MEM0 0
30-4
SD16_A
SD16_A Operation
For a 1.2V reference, the maximum full-scale input range for a gain of 1 is: 1.2V2 +" 0.6V 1 See the device-specific data sheet for full-scale input specifications. " V FSR +
SD16_A
30-5
SD16_A Operation
An external RC anti-aliasing filter is recommended for the SD16_A to prevent aliasing of the input signal. The cutoff frequency should be < 10 kHz for a 1-Mhz modulator clock and OSR = 256. The cutoff frequency may set to a lower frequency for applications that have lower bandwidth requirements.
30-6
SD16_A
SD16_A Operation
MSP430 RS VS+
1 kW
VS+ VS RS CS CS AVCC / 2 CS
= Positive external source voltage = Negative external source voltage = External source resistance = Sampling capacitance
RS VS
1 kW
When the buffers are used, RS does not affect the sampling frequency fS. However, when the buffers are not used or are not present on the device, the maximum modulator frequency fM may be calculated from the minimum settling time tSettling of the sampling circuit given by: t Settling w (RS ) 1kW) where fM + AVCC AV CC 1 and V Ax + max * V S) , * VS* , 2 2 t Settling CS ln
GAIN
2 17 VREF
VAx
with VS+ and VS referenced to AVSS. CS varies with the gain setting as shown in Table 302.
SD16_A
30-7
SD16_A Operation
p
f fM
f fM
where the oversampling rate, OSR, is the ratio of the modulator frequency fM to the sample frequency fS. Figure 304 shows the filters frequency response for an OSR of 32. The first filter notch is at fS = fM/OSR. The notchs frequency can be adjusted by changing the modulators frequency, fM, using SD16SSELx and SD16DIVx and the oversampling rate using the SD16OSRx and SD16XOSR bits. The digital filter for each enabled ADC channel completes the decimation of the digital bit-stream and outputs new conversion results to the corresponding SD16MEMx register at the sample frequency fS.
30-8
SD16_A
SD16_A Operation
Figure 305 shows the digital filter step response and conversion points. For step changes at the input after start of conversion a settling time must be allowed before a valid conversion result is available. The SD16INTDLYx bits can provide sufficient filter settling time for a full-scale change at the ADC input. If the step occurs synchronously to the decimation of the digital filter the valid data will be available on the third conversion. An asynchronous step will require one additional conversion before valid data is available.
0.6
0.4
0.2 1 0
Conversion
0.2
0
Conversion
SD16_A
30-9
SD16_A Operation
30-10
SD16_A
SD16_A Operation
OSR=256, LSBACC=0, SD16UNI=1 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SD16_A
30-11
SD16_A Operation
SD16MEMx FFFF 8000 0000 7FFF 0000 8000 FFFF 0000 0000
Digital Filter Output (OSR = 256) FFFFFF 800000 000000 7FFFFF 000000 800000 FFFFFF 800000 000000
Unipolar
ZERO FSR
Note:
Any offset measurement done either externally or using the internal differential pair A7 would be appropriate only when the channel is operating under bipolar mode with SD16UNI = 0. If the measured value is to be used in the unipolar mode for offset correction it needs to be multiplied by two.
30-12
SD16_A
SD16_A Operation
Figure 307 shows the relationship between the full-scale input voltage range from VFSR to +VFSR and the conversion result. The data formats are illustrated.
8000h
VFSR 0000h
SD16_A
30-13
SD16_A Operation
A channel is grouped and is the master channel of the group when SD16GRP = 0 if SD16GRP for the prior channel(s) is set. The grouping feature is not present on MSP430F42x0 and MSP430FG42x0 devices.
30-14
SD16_A
SD16_A Operation
Cleared by SW Time
SD16_A
30-15
SD16_A Operation
Cleared by SW Conversion
Conversion
Cleared by SW Time
30-16
SD16_A
SD16_A Operation
The SD16PREx delay is applied to the beginning of the next conversion cycle after being written. The delay is used on the first conversion after SD16SC is set and on the conversion cycle following each write to SD16PREx. Following conversions are not delayed. After modifying SD16PREx, the next write to SD16PREx should not occur until the next conversion cycle is completed, otherwise the conversion results may be incorrect. The accuracy of the result for the delayed conversion cycle using SD16PREx is dependent on the length of the delay and the frequency of the analog signal being sampled. For example, when measuring a DC signal, SD16PREx delay has no effect on the conversion result regardless of the duration. The user must determine when the delayed conversion result is useful in their application. Figure 3011 shows the operation of grouped channels 0 and 1. The preload register of channel 1 is loaded with zero resulting in immediate conversion whereas the conversion cycle of channel 0 is delayed by setting SD16PRE0 = 8. The first channel 0 conversion uses SD16PREx = 8, shifting all subsequent conversions by 8 fM clock cycles.
SD16_A
30-17
SD16_A Operation
Start of Conversion
Time
When channels are grouped, care must be taken when a channel or channels operate in single conversion mode or are disabled in software while the master channel remains active. Each time channels in the group are re-enabled and re-synchronize with the master channel, the preload delay for that channel will be reintroduced. Figure 3012 shows the re-synchronization and preload delays for channels in a group. It is recommended that SD16PREx = 0 for the master channel to maintain a consistent delay between the master and remaining channels in the group when they are re-enabled.
Cleared by SW Set by SW (syncronized to master) PRE1 Set by SW Conversion Conversion Autoclear Conv Conversion
30-18
SD16_A
SD16_A Operation
0.450
0.400
0.350
0.300
0.250
SD16_A
30-19
SD16_A Operation
The SD16IFG bits are set when their corresponding SD16MEMx memory register is written with a conversion result. An interrupt request is generated if the corresponding SD16IE bit and the GIE bit are set. The SD16_A overflow condition occurs when a conversion result is written to any SD16MEMx location before the previous conversion result was read.
30-20
SD16_A
SD16_A Operation
16 cycles 14 cycles
The interrupt handler for channel 2 SD16IFG shows a way to check immediately if a higher prioritized interrupt occurred during the processing of the ISR. This saves nine cycles if another SD16_A interrupt is pending.
; Interrupt handler for SD16_A. INT_SD16 ; Enter Interrupt Service Routine 6 ADD &SD16IV,PC; Add offset to PC 3 RETI ; Vector 0: No interrupt 5 JMP ADOV ; Vector 2: ADC overflow 2 JMP ADM0 ; Vector 4: CH_0 SD16IFG 2 JMP ADM1 ; Vector 6: CH_1 SD16IFG 2 ; ; Handler for CH_2 SD16IFG starts here. No JMP required. ; ADM2 MOV &SD16MEM2,xxx ; Move result, flag is reset ... ; Other instruction needed? JMP INT_SD16 ; Check other int pending 2
;
; Move result, flag is reset ; Other instruction needed? ; Return 5 ; Move result, flag is reset
; Return ; Handle SD16MEMx overflow ; Return 5
ADM0
; ADOV
MOV &SD16MEM0,xxx
RETI ... RETI
SD16_A
30-21
SD16_A Registers
Short Form SD16CTL SD16IV SD16AE SD16CCTL0 SD16MEM0 SD16INCTL0 SD16PRE0 SD16CCTL1 SD16MEM1 SD16INCTL1 SD16PRE1 SD16CCTL2 SD16MEM2 SD16INCTL2 SD16PRE2 SD16CCTL3 SD16MEM3 SD16INCTL3 SD16PRE3 SD16CCTL4 SD16MEM4 SD16INCTL4 SD16PRE4 SD16CCTL5 SD16MEM5 SD16INCTL5 SD16PRE5 SD16CCTL6 SD16MEM6 SD16INCTL6 SD16PRE6
Register Type Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write Read/write
Address 0100h 0110h 0B7h 0102h 0112h 0B0h 0B8h 0104h 0114h 0B1h 0B9h 0106h 0116h 0B2h 0BAh 0108h 0118h 0B3h 0BBh 010Ah 011Ah 0B4h 0BCh 010Ch 011Ch 0B5h 0BDh 010Eh 011Eh 0B6h 0BEh
Initial State Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC Reset with PUC
30-22
SD16_A
SD16_A Registers
7 SD16DIVx rw0
5 SD16SSELx rw0
1 SD16OVIE rw0
0 Reserved r0
REFON
rw0
SD16
rw0
rw0
Reserved SD16XDIVx
Reserved SD16_A clock divider 000 /1 001 /3 010 /16 011 /48 1xx Reserved Low-power mode. This bit selects a reduced-speed reduced-power mode 0 Low-power mode is disabled 1 Low-power mode is enabled. The maximum clock frequency for the SD16_A is reduced. SD16_A clock divider 00 /1 01 /2 10 /4 11 /8 SD16_A clock source select 00 MCLK 01 SMCLK 10 ACLK 11 External TACLK VMID buffer on 0 Off 1 On Reference generator on 0 Reference off 1 Reference on SD16_A overflow interrupt enable. The GIE bit must also be set to enable the interrupt. 0 Overflow interrupt disabled 1 Overflow interrupt enabled Reserved
SD16LP
Bit 8
SD16DIVx
Bits 7-6
SD16SSELx Bits
5-4
SD16 VMIDON
Bit 3
SD16 REFON
Bit 2
SD16OVIE
Bit 1
Reserved
Bit 0
SD16_A
30-23
SD16_A Registers
4 SD16DF rw0
3 SD16IE rw0
2 SD16IFG rw0
1 SD16SC rw0
0 SD16GRP r(w)0
Not implemented on all devices see the device-specific data sheet. Reserved with r0 access if high impedance buffer not implemented. Reserved in MSP430F42x0, MSP430FG42x0, MSP430F47x, and MSP430FG47x devices.
Reserved SD16BUFx
Reserved High impedance input buffer mode 00 Buffer disabled 01 Slow speed/current 10 Medium speed/current 11 High speed/current Unipolar mode select 0 Bipolar mode 1 Unipolar mode Extended oversampling ratio. This bit, along with the SD16OSRx bits, select the oversampling ratio. See SD16OSRx bit description for settings. Single conversion mode select 0 Continuous conversion mode 1 Single conversion mode Oversampling ratio When SD16XOSR = 0 00 256 01 128 10 64 11 32 When SD16XOSR = 1 00 512 01 1024 10 Reserved 11 Reserved LSB toggle. This bit, when set, causes SD16LSBACC to toggle each time the SD16MEMx register is read. 0 SD16LSBACC does not toggle with each SD16MEMx read 1 SD16LSBACC toggles with each SD16MEMx read
SD16UNI
Bit 12
SD16XOSR
Bit 11 Bit 10
SD16SNGL
SD16OSRx
Bits 9-8
SD16 LSBTOG
Bit 7
30-24
SD16_A
Bit 6
LSB access. This bit allows access to the upper or lower 16-bits of the SD16_A conversion result. 0 SD16MEMx contains the most significant 16-bits of the conversion. 1 SD16MEMx contains the least significant 16-bits of the conversion. SD16_A overflow interrupt flag 0 No overflow interrupt pending 1 Overflow interrupt pending SD16_A data format 0 Offset binary 1 2s complement SD16_A interrupt enable 0 Disabled 1 Enabled SD16_A interrupt flag. SD16IFG is set when new conversion results are available. SD16IFG is automatically reset when the corresponding SD16MEMx register is read, or may be cleared with software. 0 No interrupt pending 1 Interrupt pending SD16_A start conversion 0 No conversion start 1 Start conversion SD16_A group. Groups SD16_A channel with next higher channel. Not used for the last channel. Reserved in MSP430F42x0, MSP430FG42x0, MSP430F47x, and MSP430FG47x devices. 0 Not grouped 1 Grouped
SD16OVIFG
Bit 5
SD16DF
Bit 4
SD16IE
Bit 3
SD16IFG
Bit 2
SD16SC
Bit 1
SD16GRP
Bit 0
SD16_A
30-25
SD16_A Registers
SD16 INTDLYx
Bits 7-6
Interrupt delay generation after conversion start. These bits select the delay for the first interrupt after conversion start. 00 Fourth sample causes interrupt 01 Third sample causes interrupt 10 Second sample causes interrupt 11 First sample causes interrupt SD16_A preamplifier gain 000 x1 001 x2 010 x4 011 x8 100 x16 101 x32 110 Reserved 111 Reserved SD16_A channel differential pair input. The available selections are device dependent. See the device-specific data sheet. 000 Ax.0 or A0 001 Ax.1 or A1 010 Ax.2 or A2 011 Ax.3 or A3 100 Ax.4 or A4 101 (AVCC AVSS) / 11 110 Temperature sensor 111 Short for PGA offset measurement
SD16GAINx
Bits 5-3
SD16INCHx
Bits 2-0
Ax.1
to Ax.4 not available on all devices. See device-specific data sheet. Applies to MSP430F42x0, MSP430FG42x0, MSP430FG47x, and MSP430F47x devices
30-26
SD16_A
SD16_A Registers
Conversion Results r r r r r r r r
Conversion Results r r r r r r r r
Conversion Result
Bits 15-0
Conversion results. The SD16MEMx register holds the upper or lower 16-bits of the digital filter output, depending on the SD16LSBACC bit.
SD16PREx, SD16_A Channel x Preload Register (Not present on MSP430F42x0, MSP430FG42x0, MSP430FG47x and MSP430F47x)
7 6 5 4 3 2 1 0
Preload Value rw0 rw0 rw0 rw0 rw0 rw0 rw0 rw0
Bits 7-0
SD16_A
30-27
SD16_A Registers
SD16AE, SD16_A Analog Input Enable Register (Present on MSP430F42x0, MSP430FG42x0, MSP430FG47x, and MSP430F47x)
7 SD16AE7 rw0 6 SD16AE6 rw0 5 SD16AE5 rw0 4 SD16AE4 rw0 3 SD16AE3 rw0 2 SD16AE2 rw0 1 SD16AE1 rw0 0 SD16AE0 rw0
SD16AEx
Bits 7-0
SD16_A analog enable 0 External input disabled. Negative inputs are internally connected to VSS. 1 External input enabled.
30-28
SD16_A
SD16_A Registers
7 0 r0
6 0 r0
5 0 r0
3 SD16IVx
0 0
r0
r0
r0
r0
r0
SD16IVx
Bits 15-0
SD16IV Contents 000h 002h 004h 006h 008h 00Ah 00Ch 00Eh 010h
Interrupt Source No interrupt pending SD16MEMx overflow SD16_A Channel 0 Interrupt SD16_A Channel 1 Interrupt SD16_A Channel 2 Interrupt SD16_A Channel 3 Interrupt SD16_A Channel 4 Interrupt SD16_A Channel 5 Interrupt SD16_A Channel 6 Interrupt
Interrupt Flag SD16CCTLx SD16OVIFG SD16CCTL0 SD16IFG SD16CCTL1 SD16IFG SD16CCTL2 SD16IFG SD16CCTL3 SD16IFG SD16CCTL4 SD16IFG SD16CCTL5 SD16IFG SD16CCTL6 SD16IFG
Interrupt Priority
Highest
Lowest
When an SD16_A overflow occurs, the user must check all SD16CCTLx SD16OVIFG flags to determine which channel overflowed.
SD16_A
30-29
30-30
SD16_A
Chapter 31
DAC12
The DAC12 module is a 12-bit voltage-output digital-to-analog converter (DAC). This chapter describes the DAC12. Two DAC12 modules are implemented in the MSP430FG43x, MSP430FG461x, and MSP430FG47x devices. One DAC12 module is implemented in the MSP430x42x0 and MSP430F47x devices.
Topic
Page
31.1 DAC12 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31-2 31.2 DAC12 Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31-6 31.3 DAC12 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31-13
DAC12
31-1
DAC12 Introduction
Note: Multiple DAC12 Modules Some devices may integrate more than one DAC12 module. When more than one DAC12 is present on a device, the multiple DAC12 modules operate identically. Throughout this chapter, nomenclature appears such as DAC12_xDAT or DAC12_xCTL to describe register names. When this occurs, the x is used to indicate which DAC12 module is being discussed. In cases where operation is identical, the register is simply referred to as DAC12_xCTL. The block diagram of the two DAC12 modules in the MSP430FG43x, MSP430FG47x, and MSP430FG461x devices is shown in Figure 311. The block diagram for the DAC12 module in the MSP430x42x0 and MSP430F47x devices is shown in Figure 312.
31-2
DAC12
DAC12 Introduction
To ADC12 module
VR
VR+ DAC12_0OUT x3
1 0 DAC12ENC
DAC12_0Latch
DAC12RES DAC12DF
DAC12GRP
DAC12_0DAT
VR
VR+ DAC12_1OUT x3
1 0
DAC12_1Latch
DAC12RES DAC12DF
DAC12GRP
DAC12ENC
DAC12_1DAT
DAC12_1DAT Updated
DAC12
31-3
DAC12 Introduction
Figure 312. DAC12 Block Diagram For MSP430Fx42x0 and MSP430F47x Devices
V REF
V R
V R+ DAC12_0OUT x3
1 0 ENC
DAC12_0Latch
DAC12RES DAC12DF
DAC12GRP
DAC12_0DAT
DAC12_0DAT Updated
31-4
DAC12
DAC12 Introduction
VR-
VR+ DAC12_0OUT x3
DAC12_0
00 01 TA1 TB2 10 11
DAC12ENC DAC12_0DAT
DAC12SREFx DAC12IR 00 01 10 11 /3
DAC12AMPx
AVSS
VR-
VR+ DAC12_1OUT x3
DAC12_1
00 01 TA1 TB2 10 11
DAC12ENC DAC12_1DAT
DAC12_1DAT Updated
DAC12
31-5
DAC12 Operation
DAC12_xDAT 256
In 8-bit mode the maximum useable value for DAC12_xDAT is 0FFh, and in 12-bit mode the maximum useable value for DAC12_xDAT is 0FFFh. Values greater than these may be written to the register, but all leading bits are ignored. Note: Using the DAC12IR = 0 The maximum DAC12 output voltage (full scale) is limited to AVcc. Using the equation of Table 311 (DAC12IR = 0), this leads to Vref v AVcc/3.
31-6
DAC12
DAC12 Operation
DAC12
31-7
DAC12 Operation
31-8
DAC12
DAC12 Operation
Figure 314. Output Voltage vs DAC12 Data, 12-Bit, Straight Binary Mode
Output Voltage Full-Scale Output
0 0 0FFFh
DAC Data
When using 2s compliment data format, the range is shifted such that a DAC12_xDAT value of 0800h (0080h in 8-bit mode) results in a zero output voltage, 0000h is the mid-scale output voltage, and 07FFh (007Fh for 8-bit mode) is the full-scale voltage output (see Figure 315).
Mid-Scale Output
0 0800h (2048) 0
DAC12
31-9
DAC12 Operation
Output Voltage
When the output amplifier has a positive offset, a digital input of zero does not result in a zero output voltage. The DAC12 output voltage reaches the maximum output level before the DAC12 data reaches the maximum code (see Figure 317).
Vcc
Output Voltage
The DAC12 has the capability to calibrate the offset voltage of the output amplifier. Setting the DAC12CALON bit initiates the offset calibration. The calibration should complete before using the DAC12. When the calibration is complete, the DAC12CALON bit is automatically reset. The DAC12AMPx bits should be configured before calibration. For best calibration results, port and CPU activity should be minimized during calibration.
31-10
DAC12
DAC12 Operation
When DAC12_0 and DAC12_1 are grouped, both DAC12_xDAT registers must be written to before the outputs update even if data for one or both of the DACs is not changed. Figure 318 shows a latch-update timing example for grouped DAC12_0 and DAC12_1. When DAC12_0 DAC12GRP = 1 and both DAC12_x DAC12LSELx > 0 and either DAC12ENC = 0, neither DAC12 will update.
DAC12_0 DAC12GRP DAC12_0 DAC12ENC TimerA_OUT1 DAC12_0DAT New Data DAC12_1DAT New Data DAC12_0 Latch Trigger DAC12_0 DAC12LSELx = 2 DAC12_0 Updated
Note:
The DMA controller is capable of transferring data to the DAC12 faster than the DAC12 output can settle. The user must assure the DAC12 settling time is not violated when using the DMA controller. See the device-specific data sheet for parameters.
DAC12
31-11
DAC12 Operation
31-12
DAC12
DAC12 Registers
DAC12
31-13
DAC12 Registers
6 DAC12AMPx
4 DAC12DF
3 DAC12IE rw(0)
2 DAC12IFG rw(0)
1 DAC12ENC rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
DAC12OPS
Bit 15
DAC12 output select MSP430FG43x and MSP430FG461x Devices: 0 DAC12_0 output on P6.6, DAC12_1 output on P6.7 1 DAC12_0 output on VeREF+, DAC12_1 output on P5.1 MSP430Fx42x0 Devices: 0 DAC12_0 output not available external to the device 1 DAC12_0 output available internally and externally. MSP430FG47x Devices: 0 DAC12_x output not available external to the device 1 DAC12_x output available internally and externally. DAC12 select reference voltage MSP430FG43x and MSP430FG461x Devices: 00 VREF+ 01 VREF+ 10 VeREF+ 11 VeREF+ MSP430Fx42x0 and MSP430FG47x Devices: 00 AVCC 01 AVCC 10 VREF (internal from SD16_A or external) 11 VREF (internal from SD16_A or external) DAC12 resolution select 0 12-bit resolution 1 8-bit resolution
DAC12 SREFx
Bits 14-13
DAC12RES
Bit 12
31-14
DAC12
Bits 11-10
DAC12 load select. Selects the load trigger for the DAC12 latch. DAC12ENC must be set for the DAC to update, except when DAC12LSELx = 0. 00 DAC12 latch loads when DAC12_xDAT written (DAC12ENC is ignored) 01 DAC12 latch loads when DAC12_xDAT written, or, when grouped, when all DAC12_xDAT registers in the group have been written. 10 Rising edge of Timer_A.OUT1 (TA1) 11 Rising edge of Timer_B.OUT2 (TB2) DAC12 calibration on. This bit initiates the DAC12 offset calibration sequence and is automatically reset when the calibration completes. 0 Calibration is not active 1 Initiate calibration/calibration in progress DAC12 input range. This bit sets the reference input and voltage output range. 0 DAC12 full-scale output = 3x reference voltage 1 DAC12 full-scale output = 1x reference voltage DAC12 amplifier setting. These bits select settling time vs. current consumption for the DAC12 input and output amplifiers. DAC12AMPx 000 001 010 011 100 101 110 111 Off Off Low speed/current Low speed/current Low speed/current Medium speed/current Medium speed/current High speed/current Input Buffer Output Buffer DAC12 off, output high Z DAC12 off, output 0 V Low speed/current Medium speed/current High speed/current Medium speed/current High speed/current High speed/current
DAC12 CALON
Bit 9
DAC12IR
Bit 8
DAC12 AMPx
Bits 7-5
DAC12DF
Bit 4
DAC12 data format 0 Straight binary 1 2s complement DAC12 interrupt enable 0 Disabled 1 Enabled DAC12 Interrupt flag 0 No interrupt pending 1 Interrupt pending
DAC12IE
Bit 3
DAC12IFG
Bit 2
DAC12
31-15
Bit 1
DAC12 enable conversion. This bit enables the DAC12 module when DAC12LSELx > 0. When DAC12LSELx = 0, DAC12ENC is ignored. 0 DAC12 disabled 1 DAC12 enabled DAC12 group. Groups DAC12_x with the next higher DAC12_x. Not used for DAC12_1 on MSP430FG43x, MSP430FG47x, MSP430x42x0, or MSP430FG461x devices. 0 Not grouped 1 Grouped
DAC12GRP
Bit 0
31-16
DAC12
DAC12 Registers
4 DAC12 Data
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
Unused
Unused. These bits are always 0 and do not affect the DAC12 core. DAC12 data
DAC12 Data The DAC12 data are right-justified. Bit 11 is the MSB. The DAC12 data are right-justified. Bit 11 is the MSB (sign). The DAC12 data are right-justified. Bit 7 is the MSB. Bits 11 to 8 are dont care and do not affect the DAC12 core. The DAC12 data are right-justified. Bit 7 is the MSB (sign). Bits 11 to 8 are dont care and do not affect the DAC12 core.
8-bit 2s complement
DAC12
31-17
31-18
DAC12
Chapter 32
Scan IF
The Scan IF peripheral automatically scans sensors and measures linear or rotational motion. This chapter describes the Scan interface. The Scan IF is implemented in the MSP430FW42x devices.
Topic
Page
32.1 Scan IF Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32-2 32.2 Scan IF Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32-4 32.3 Scan IF Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32-35
Scan IF
32-1
Scan IF Introduction
such
as
Hall-effect
or
giant
- Direct analog input for A/D conversion - Direct digital input for digital sensors such as optical decoders - Support for quadrature decoding
32-2
Scan IF
Scan IF Introduction
Scan I/F Analog FrontEnd (AFE) SIFCI SIFCI3 SIFCI2 SIFCI1 SIFCI0 SIFCH3 SIFCH2 SIFCH1 SIFCH0 SIFCOM SIFVSS DAC 10 Bit w/ RAM Timing State Machine (TSM) w/ oscillator AVCC ACLK SMCLK Excit S/H Analog Input Multiplexer Interrupt Request Processing State Machine (PSM) + Rotation Data
To Timer_A
1/2
Scan IF
32-3
Scan IF Operation
Throughout this chapter, signals from the TSM are noted in the signal name with (tsm). For example, The signal SIFEX(tsm) comes from the TSM.
32-4
Scan IF
Scan IF Operation
SIFCI
11 10 01 00 SIFCAINV Output Stage SIFRSON(tsm) SIFCA(tsm) SIFCAON SIFCAX SIFSH S/H S/H S/H S/H 11 10 01 00 1 1 0 SIFDAC(tsm) SIFDACON SIFTCH0OUT SIFTCH1OUT 11 10 01 00 SIFTEN Excitation Excit Excit Excit Excit SIFLCEN(tsm) SIFEX(tsm) SIFVCC2 2 11 10 01 2 2 2 DAC 10 Bit SIFDACR0 SIFDACR1 SIFDACR2 SIFDACR3 SIFDACR4 SIFDACR5 SIFDACR6 SIFDACR7 TESTDX Sync. SIFTESTD SIFTESTS1(tsm) SIFTCH1x SIFTCH0x SIFCHx(tsm) 0 + SIF0OUT SIF1OUT SIF2OUT SIF3OUT
SIFCI3 SIFCI2 SIFCI1 SIFCI0 SIFVSS Sample/Hold SIFCH3 SIFCH2 SIFCH1 SIFCH0
11 10 01 00
SIFCOM
VMID
00
Scan IF
32-5
Scan IF Operation
Excitation
The excitation circuitry is used to excite the LC sensors or to power the resistor dividers. The excitation circuitry is shown in Figure 323 for one LC sensor connected. When the SIFTEN bit is set and the SIFSH bit is cleared the excitation circuitry is enabled and the sample-and-hold circuitry is disabled. When the SIFEX(tsm) signal from the timing state machine is high the SIFCHx input of the selected channel is connected to SIFVSS and the SIFCOM input is connected to the mid-voltage generator to excite the sensor. The SIFLCEN(tsm) signal must be high for excitation. While one channel is excited and measured all other channels are automatically disabled. Only the selected channel is excited and measured. The excitation period should be long enough to overload the LC sensor slightly. After excitation the SIFCHx input is released from ground when SIFEX(tsm) = 0 and the LC sensor can oscillate freely. The oscillations will swing above the positive supply but will be clipped by the protection diode to the positive supply voltage plus one diode drop. This gives consistent maximum oscillation amplitude. At the end of the measurement the sensor should be damped by setting SIFLCEN(tsm) = 0 to remove any residual energy before the next measurement.
Mid-Voltage Generator
The mid-voltage generator is on when SIFVCC2 = 1 and allows the LC sensors to oscillate freely. The mid-voltage generator requires a maximum of 6 ms to settle and requires ACLK to be active and operating at 32768 Hz.
32-6
Scan IF
Scan IF Operation
Damping 0
11 1 10 01 00 From
SIFVCC2
Scan IF
32-7
Scan IF Operation
Sample-And-Hold
The sample-and-hold is used to sample the sensor voltage to be measured. The sample-and-hold circuitry is shown in Figure 323. When SIFSH = 1 and SIFTEN = 0 the sample-and-hold circuitry is enabled and the excitation circuitry and mid-voltage generator are disabled. The sample-and-hold is used for resistive dividers or for other analog signals that should be sampled. Up to four resistor dividers can be connected to SIFCHx and SIFCOM. AVCC and SIFCOM are the common positive and negative potentials for all connected resistor dividers. When SIFEX(tsm) = 1, SIFCOM is connected to SIFV SS allowing current to flow through the dividers. This charges the capacitors of each sample-and-hold circuit to the divider voltages. All resistor divider channels are sampled simultaneously. When SIFEX(tsm) = 0 the sample-and-hold capacitor is disconnected from the resistor divider and SIFCOM is disconnected from SIFVSS. After sampling, each channel can be measured sequentially using the channel select logic, the comparator, and the DAC. The selected SIFCHx input can be modeled as an RC low-pass filter during the sampling time tsample, as shown below in Figure 324. An internal MUX-on input resistance Ri(SIFCHx) (max. 3 k) in series with capacitor CSCH(SIFCHx) (max. 7 pF) is seen by the resistor-divider. The capacitor voltage VC must be charged to within LSB of the resistor divider voltage for an accurate 10-bit conversion. See the device-specific data sheet for parameters.
MSP430 RS VS Ri(SIFCHx) VC CSHC(SIFCHx) VI VS RS Ri(SIFCHx) CISHC(SIFCHx) VC = Input voltage at pin SIFCHx = External source voltage = External source resistance = Internal MUX-on input resistance = Input capacitance = Capacitance-charging voltage
VI
The resistance of the source RS and Ri(SIFCHx) affect tsample.The following equation can be used to calculate the minimum sampling time tsample for a 10-bit conversion: t sample u (R S ) RiSIFCHx) ln(2 11) C SHC(SIFCHx) (1)
Substituting the values for RI and CI given above, the equation becomes: t sample u (R S ) 3k) 7.625 7pF (2)
32-8
Scan IF
Scan IF Operation
The TESTDX signal and SIFTESTS1(tsm) signal select between the SIFxOUT output bits and the SIFTCHxOUT output bits for the comparator output as described in Table 322. TESTDX is controlled by the SIFTESTD bit.
When TESTDX = 0, the SIFCHx(tsm) signals select which SIFCIx or SIFCHx channel is excited and connected to the comparator. The SIFCHx(tsm) signals also select the corresponding output bit for the comparator result. When TESTDX = 1, channel selection depends on the SIFTESTS1(tsm) signal. When TESTDX = 1 and SIFTESTS1(tsm) = 0, input channel selection is controlled with the SIFTCH0x bits and the output bit is SIFTCH0OUT. When TESTDX = 1 and SIFTESTS1(tsm) = 1, input channel selection is controlled with the SIFTCH1x bits and the output bit is SIFTCH1OUT.
Scan IF
32-9
Scan IF Operation
When SIFCAX = 1, the SIFCSEL and SIFCI3 bits select between the SIFCIx channels and the SIFCI input allowing storage of the comparator output for one input signal into the four output bits SIF0OUT - SIF3OUT. This can be used to observe the envelope function of sensors. The output logic is enabled by the SIFRSON(tsm) signal. When the comparator output is high while SIFRSON = 1, an internal latch is set. Otherwise the latch is reset. The latch output is written into the selected output bit with the rising edge of the SIFSTOP(tsm) signal as shown in Figure 325.
Comparator Output
SIFRSON(tsm)
Internal Latch
SIFSTOP(tsm)
SIFxOUT/ SIFTCHxOUT
Time
32-10
Scan IF
Scan IF Operation
Scan IF
32-11
Scan IF Operation
For each input there are two DAC registers to set the reference level as listed in Table 323. Together with the last stored output of the comparator, SIFxOUT, the two levels can be used as an analog hysteresis as shown in Figure 326. The individual settings for the four inputs can be used to compensate for mismatches between the sensors.
SIF1OUT
Time
When TESTDX = 1, the SIFDACR6 and SIFDACR7 registers are used as the comparator reference as described in Table 324.
32-12
Scan IF
Scan IF Operation
SIFCS
1 0
SIFO0
00 01 10 11 SIFS2x 1 0
SIFO1
00 01 10 11 1 0 SIFO2
When SIFCS = 1, the SIFEX(tsm) signal and the comparator output can be selected as inputs to different Timer1_A5 capture/compare registers. This can be used to measure the time between excitation of a sensor and the last oscillation that passes through the comparator or to perform a slope A/D conversion. When SIFCS =0, the output bits SIFxOUT can be selected as inputs to Timer1_A5 with the SIFS1x and SIFS2x bits. This can be used to measure the duty cycle of SIFxOUT.
Scan IF
32-13
Scan IF Operation
32-14
Scan IF
Scan IF Operation
Start
SMCLK
0 1
Divider /1/2/4/8
SIFFNOM
SIFCLKFQx 4
Scan IF
32-15
Scan IF Operation
TSM Operation
The TSM automatically starts and re-starts periodically based on a divided ACLK start signal selected with the SIFDIV2x bits, the SIFDIV3Ax and SIFDIV3Bx bits when SIFTSMRP = 0. For example, if SIFDIV3A and SIFDIV3B are configured to 270 ACLK cycles, then the TSM automatically starts every 270 ACLK cycles. When SIFTSMRP = 1 the TSM restarts immediately with the SIFTSM0 state at the end of the previous sequence i.e. with the next ACLK cycle after encountering a state with SIFSTOP = 1. The SIFIFG2 interrupt flag is set when the TSM starts. The SIFDIV3Ax and SIFDIV3Bx bits may be updated anytime during operation. When updated, the current TSM sequence will continue with the old settings until the last state of the sequence completes. The new settings will take affect at the start of the next sequence.
32-16
Scan IF
Scan IF Operation
Scan IF
32-17
Scan IF Operation
TSM Active
TSM Start Signal (Divided ACLK) Normal Cycle Normal Cycle Test Cycle Normal Cycle Normal Cycle Test Cycle
TESTDX
SIFTESTD
32-18
Scan IF
Scan IF Operation
TSM Example
Figure 3210 shows an example for a TSM sequence. The TSMx register values for the example are shown in Table 326. ACLK and SIFCLK are not drawn to scale. The TSM sequence starts with SIFTSM0 and ends with a set SIFSTOP bit in SIFTSM9. Only the SIFTSM5 to SIFTSM9 states are shown.
The example also shows the affects of the clock synchronization when switching between SIFCLK and ACLK. In state SIFTSM6, SIFACLK is set, whereas in the previous state and the successive state, SIFACLK is cleared. The waveform shows the duration of SIFTSM6 is less than one ACLK cycle and the duration of state SIFTSM7 is up to one SIFCLK period longer than configured by the SIFREPEATx bits.
SIFTSM5
SIFTSM6
SIFTSM7
SIFTSM8
SIF TSM9
10
10
10
00
Scan IF
32-19
Scan IF Operation
32-20
Scan IF
Scan IF Operation
00 01 10 11
+1 SIFCNT1 1
1 4 64 256
00 01 10 11 Set_SIFIFG3
SIFCNT1ENM
SIFCNTRST SIFIS2x
00 01 10 11 Set_SIFIFG4
Set_SIFIFG5 Set_SIFIFG7
PSM Operation
At the falling edge of the SIFSTOP(tsm) signal the PSM moves the current-state byte from the PSM state table to the PSM output latch. The PSM has one dedicated channel of direct memory access (DMA), so all accesses to the PSM state table(s) are done automatically with no CPU intervention. The current-state and next-state logic are reset while the Scan IF is disabled. One of the bytes stored at addresses SIFPSMV to SIFPSMV + 3 will be loaded first depending on the S1 and S2 signals when the Scan IF is enabled.
Scan IF
32-21
Scan IF Operation
Signals S1 and S2 form a 2-bit offset added to the SIFPSMV contents to determine the first byte loaded to the PSM output latch. For example, when S2 = 1, and S1 = 0, the first byte loaded by the PSM will be at the address SIFPSMV + 2. The next byte and further subsequent bytes are determined by the next state calculations and are calculated by the PSM based on the state table contents and the values of signals S1 and S2. Note: SIFSTOP(tsm) Signal Frequency
The SIFSTOP(tsm) signal frequency must be at least a factor of 32 lower than the MCLK. Otherwise, unpredictable operation could occur.
When Q7 = 0, the PSM state is updated by the falling edge of the SIFSTOP(tsm) at the end of a TSM sequence. After updating the current state the PSM moves the corresponding state table entry to the output latch. When Q7 = 1, the next state is calculated immediately without waiting for the next falling edge of SIFSTOP(tsm), regardless of the state of SIFQ6EN or SIFQ7EN. The state is then updated with the next instruction fetch. The worst-case time between state transitions in this case is 6 MCLK cycles.
32-22
Scan IF
Scan IF Operation
PSM Counters
The PSM has two 8-bit counters SIFCNT1 and SIFCNT2. SIFCNT1 is updated with Q1 and Q2 and SIFCNT2 is updated with Q2. The counters can be read via the SIFCNT register. If the SIFCNTRST bit is set, each read access will reset the counters, otherwise the counters remain unchanged when read. If a count event occurs during a read access the count is postponed until the end of the read access but multiple count events during a read access will increment the counters only once. When SIFEN = 0, both counters are held in reset. SIFCNT1 can increment or decrement based on Q1 and Q2. When SIFCNT1ENM = 1, SIFCNT1 decrements on a transition to a state where bit Q2 is set. When SIFCNT1ENP = 1, SIFCNT1 increments on a transition to a state where bit Q1 is set. When both bits SIFCNT1ENM and SIFCNT1ENM are set, and both bits Q1 and Q2 are set on a state transition, SIFCNT1 does not increment or decrement. SIFCNT2 decrements based on Q2. When SIFCNT2EN = 1, SIFCNT2 decrements on a transition to a state where bit Q2 is set. On the first count after a reset SIFCNT2 will roll over from zero to 255 (0FFh). When the next state is calculated to be the same state as the current state, the counters SIFCNT1 and SIFCNT2 are incremented or decremented according to Q1 and Q2 at the state transition. For example, if the current state is 05h and Q2 is set, and if the next state is calculated to be 05h, the transition from state 05h to 05h will decrement SIFCNT2 if SIFCNT2EN = 1.
Scan IF
32-23
Scan IF Operation
S1=1 & S2=0 S1=0 & S2=0 S1=0 & S2=0 State 01 00000000 S1=1 & S2=0 S1=1 & S2=0 S1=1 & S2=1
S1=0 & S2=1 S1=0 & S2=0 S1=0 & S2=1 S1=1 & S2=0 State 10 00000000
S1=0 & S2=1 S1=1 & S2=1 S1=0 & S2=1 S1=1 & S2=1
State 11 00000010
00 01 10 11
0) 1) 2) 3)
PSM_INIT MOV #SIMPLEST_PSM,&SIFPSMV ; Init PSM vector MOV #SIFS20,&SIFCTL3 ; S1/S2 source MOV #SIFCNT1ENP+SIFCNT1ENM,&SIFCTL4 ; Q7 and Q6 disabled for next state calc. ; Increment and decrement of SIFCNT1 enabled
32-24
Scan IF
Scan IF Operation
If the PSM is in state 01 of the simplest state machine and the PSM has loaded the corresponding byte at index 01h of the state table:
Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0
For this example, S1 and S2 are set at the end of the next TSM sequence. To calculate the next state the bits Q5 - Q3 and Q0 of the state 01 table entry, together with the S1 and S2 signals are combined to form the next state:
Q7 Q6 Q5 Q4 Q3 Q0 S2 S1
The state table entry for state 11 is loaded at the next state transition:
Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0
Q1 is set in state 11, so SIFCNT1 will be incremented. More complex state machines can be built by combining simple state machines to meet the requirements of specific applications.
Scan IF
32-25
Scan IF Operation
32-26
Scan IF
Scan IF Operation
Interrupt flags SIFIFG3 and SIFIFG4 have hysteresis so that the interrupt flag is set only once if the counter oscillates around the interrupt level as shown in Figure 3213.
Scan IF
32-27
Scan IF Operation
AVCC/2
Time
Damped
32-28
Scan IF
Scan IF Operation
32.2.6.1 LC-Sensor Oscillation Test The oscillation test tests if the amplitude of the oscillation after sensor excitation is above a reference level. The DAC is used to set the reference level for the comparator, and the comparator detects if the LC sensor oscillations are above or below the reference level. If the oscillations are above the reference level, the comparator will output a pulse train corresponding to the oscillations and the selected AFE output bit will 1. The measurement timing and reference level depend on the sensors and the system and should be chosen such that the difference between the damped and the undamped amplitude is maximized. Figure 3215 shows the connections for the oscillation test.
SIFCOM 470 nF SIFVSS DVSS Power Supply Terminals 470nF AVSS DVCC AVCC
Scan IF
32-29
Scan IF Operation
32.2.6.2 LC-Sensor Envelope Test The envelop test measures the decay time of the oscillations after sensor excitation. The oscillation envelope is created by the diodes and RC filters. The DAC is used to set the reference level for the comparator, and the comparator detects if the oscillation envelop is above or below the reference level. The comparator and AFE outputs are connected to Timer1_A5 and the capture/compare registers for Timer1_A5 are used to time the decay of the oscillation envelope. The PSM is not used for the envelope test. When the sensors are connected to the individual SIFCIx inputs as shown in Figure 3216, the comparator reference level can be adjusted for each sensor individually. When all sensors are connected to the SIFCI input as shown in Figure 3217, only one comparator reference level is set for all sensors.
SIFCOM 470 nF SIFVSS DVSS Power Supply Terminals 470 nF AVSS DVCC AVCC
32-30
Scan IF
Scan IF Operation
SIFCOM 470 nF SIFVSS DVSS Power Supply Terminals 470 nF AVSS DVCC AVCC
Scan IF
32-31
Scan IF Operation
SIFCOM SIFVSS DVSS Power Supply Terminals 470 nF AVSS DVCC AVCC
32-32
Scan IF
Scan IF Operation
45
11
10
00
01
11
10
Quadrature decoding requires knowing the previous quadrature pair S1 and S2, as well as the current pair. Comparing these two pairs will tell the direction of the rotation. For example, if the current pair is 00 it can change to 01 or 10, depending on direction. Any other change in the signal pair would represent an error as shown in Figure 3220.
Scan IF
32-33
Scan IF Operation
00 1 10 01 +1 10
00
01
11
11
To transfer the state encoding into counts it is necessary to decide what fraction of the rotation should be counted and on what state transitions. In this example only full rotations will be counted on the transition from state 00 to 01 or 10 using a 180 disk with the sensors 90 apart. All the possible state transitions can be put into a table and this table can be translated into the corresponding state table entries for the processing state machine as shown in Table 328.
00 00 00 00 01 01 01 01 10 10 10 10 11 11 11 11
00 01 10 11 00 01 10 11 00 01 10 11 00 01 10 11
No Rotation Turns right, +1 Turns left, 1 Error Turns left No rotation Error Turns right Turns right Error No rotation Turns left Error Turns left Turns right No rotation
0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0
0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
32-34
Scan IF
Scan IF Registers
Scan IF
32-35
Scan IF Registers
5 Reserved
1 SIFDEBUGx
Reserved
Reserved. Must be written as zero. SIFDEBUG register mode. Writing these bits selects the read-mode of the SIFDEBUG register. SIFDEBUG must be written with MOV instructions only. 00 When read, SIFDEBUG shows the last address read by the PSM 01 When read, SIFDEBUG shows the value of the TSM state pointer and the PSM bits Q7 - Q0 10 When read, SIFDEBUG shows the contents of the current SIFTSMx register. 11 When read, SIFDEBUG shows the currently selected DAC register and its contents.
SIFDEBUGx Bits
Last PSM
Bits 15-0
When SIFDEBUG is read, after 00h has been written to it, SIFDEBUG shows the last address read by the PSM.
32-36
Scan IF
Scan IF Registers
PSM Bits Q7 Q0 r r r r r r r r
Unused
Unused. After 01h is written to SIFDEBUG, these bits are always read as zero. When SIFDEBUG is read, after 01h is written to it, these bits show the TSM register pointer index. When SIFDEBUG is read, after 01h is written to it, these bits show the PSM bits Q7 to Q0.
TSM Index
PSM Bits
Bits 15-0
When SIFDEBUG is read, after 02h is written to it, these bits show the TSM output.
Scan IF
32-37
Scan IF Registers
4 DAC Data
Unused. After 03h is written to SIFDEBUG, this bit is always read as zero. When SIFDEBUG is read, after 03h is written to it, these bits show which DAC register is currently selected to control the DAC. Unused. After 03h is written to SIFDEBUG, these bits are always read as zero. When SIFDEBUG is read, after 03h is written to it, these bits show value of the currently-selected DAC register.
DAC Data
32-38
Scan IF
Scan IF Registers
4 SIFCNT1x
r(0)
r(0)
r(0)
r(0)
r(0)
r(0)
r(0)
r(0)
SIFCNT2x
SIFCNT2. These bits are the SIFCNT2 counter. SIFCNT2 is reset when SIFEN = 0 or if read when SIFCNTRST = 1. SIFCNT1. These bits are the SIFCNT1 counter. SIFCNT1 is reset when SIFEN = 0 or if read when SIFCNTRST = 1.
SIFCNT1x
4 SIFPSMVx
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
SIFPSMVx
Bits 15-0
SIF PSM vector. These bits are the address for the first state in the PSM state table.
Scan IF
32-39
Scan IF Registers
7 SIFIFG5 rw(0)
6 SIFIFG4 rw(0)
5 SIFIFG3 rw(0)
4 SIFIFG2 rw(0)
3 SIFIFG1 rw(0)
2 SIFIFG0 rw(0)
1 SIFTESTD rw(0)
0 SIFEN rw(0)
SIFIEx
Bits 15-9
Interrupt enable. These bits enable or disable the interrupt request for the SIFIFGx bits. 0 Interrupt disabled 1 Interrupt enabled SIF interrupt flag 6. This bit is set when the PSM transitions to a state with a set Q7 bit. SIFIFG6 must be reset with software. 0 No interrupt pending 1 Interrupt pending SIF interrupt flag 5. This bit is set when the PSM transitions to a state with a set Q6 bit. SIFIFG5 must be reset with software. 0 No interrupt pending 1 Interrupt pending SIF interrupt flag 4. This bit is set by the SIFCNT2 counter conditions selected with the SIFIS2x bits. SIFIFG4 must be reset with software. 0 No interrupt pending 1 Interrupt pending SIF interrupt flag 3. This bit is set by the SIFCNT1 counter conditions selected with the SIFIS1x bits SIFIFG3 must be reset with software. 0 No interrupt pending 1 Interrupt pending SIF interrupt flag 2. This bit is set at the start of a TSM sequence. SIFIFG2 must be reset with software. 0 No interrupt pending 1 Interrupt pending SIF interrupt flag 1. This bit is set by the rising edge of the SIFSTOP(tsm) signal. SIFIFG1 must be reset with software. 0 No interrupt pending 1 Interrupt pending
SIFIFG6
Bit 8
SIFIFG5
Bit 7
SIFIFG4
Bit 6
SIFIFG3
Bit 5
SIFIFG2
Bit 4
SIFIFG1
Bit 3
32-40
Scan IF
Bit 2
SIF interrupt flag 0. This bit is set by the SIFxOUT conditions selected by the SIFIFGSETx bits. SIFIFG0 must be reset with software. 0 No interrupt pending 1 Interrupt pending Test cycle insertion. Setting this bit inserts a test cycle between TSM cycles. SIFTESTD is automatically reset at the end of the test cycle. 0 No test cycle inserted 1 Test cycle inserted between TSM cycles. Scan interface enable. Setting this bit enables the Scan IF. 0 Scan IF disabled 1 Scan IF enabled
SIFTESTD
Bit 1
SIFEN
Bit 0
Scan IF
32-41
Scan IF Registers
7 SIFSH rw(0)
6 SIFTEN rw(0)
5 SIFTCH1x rw(0)
3 SIFTCH0x rw(0)
rw(0)
rw(0)
SIFDACON
Bit 15
DAC on. Setting this bit turns the DAC on regardless of the TSM control. 0 The DAC is controlled by the TSM. 1 The DAC is on. Comparator on. Setting this bit turns the comparator on regardless of the TSM control. 0 The comparator is controlled by the TSM. 1 The comparator is on. Invert comparator output 0 Comparator output is not inverted 1 Comparator output is inverted Comparator input select. This bit selects groups of signals for the comparator input. 0 Comparator input is one of the SIFCHx channels, selected with the channel select logic. 1 Comparator input is one of the SIFCIx channels, selected with the channel select logic and the SIFCISEL and SIFCACI3 bits. Comparator input select. This bit is used with the SIFCACI3 bit to select the comparator input when SIFCAX = 1. 0 Comparator input is one of the SIFCIx channels, selected with the channel select logic and SIFCACI3 bit. 1 Comparator input is the SIFCI channel Comparator input select. This bit is selects the comparator input when SIFCISEL = 0 and SIFCAX = 1. 0 Comparator input is selected with the channel select logic. 1 Comparator input is SIFCI3. Sample-and-hold SIFVSS select. 0 The ground connection of the sample capacitor is connected to SIFVSS, regardless of the TSM control. 1 The ground connection of the sample capacitor is controlled by the TSM
SIFCAON
Bit 14
SIFCAINV
Bit 13
SIFCAX
Bit 12
SIFCISEL
Bit 11
SIFCACI3
Bit 10
SIFVSS
Bit 9
32-42
Scan IF
Bit 8
Mid-voltage generator 0 AVCC/2 generator is off 1 AVCC/2 generator is on if SIFSH = 0 Sample-and-hold enable 0 Sample-and-hold is disabled 1 Sample-and-hold is enabled Excitation enable 0 Excitation circuitry is disabled 1 Excitation circuitry is enabled These bits select the comparator input for test channel 1. 00 Comparator input is SIFCH0 when SIFCAX = 0 Comparator input is SIFCI0 when SIFCAX = 1 01 Comparator input is SIFCH1 when SIFCAX = 0 Comparator input is SIFCI1 when SIFCAX = 1 10 Comparator input is SIFCH2 when SIFCAX = 0 Comparator input is SIFCI2 when SIFCAX = 1 11 Comparator input is SIFCH3 when SIFCAX = 0 Comparator input is SIFCI3 when SIFCAX = 1 These bits select the comparator input for test channel 0. 00 Comparator input is SIFCH0 when SIFCAX = 0 Comparator input is SIFCI0 when SIFCAX = 1 01 Comparator input is SIFCH1 when SIFCAX = 0 Comparator input is SIFCI1 when SIFCAX = 1 10 Comparator input is SIFCH2 when SIFCAX = 0 Comparator input is SIFCI2 when SIFCAX = 1 11 Comparator input is SIFCH3 when SIFCAX = 0 Comparator input is SIFCI3 when SIFCAX = 1 AFE output for test channel 1 AFE output for test channel 0
SIFSH
Bit 7
SIFTEN
Bit 6
SIFTCH1x
Bits 5-4
SIFTCH0x
Bits 3-2
Bit 1 Bit 0
Scan IF
32-43
Scan IF Registers
7 SIFCS rw(0)
5 SIFIFGSETx
3 SIF3OUT
2 SIF2OUT r(0)
1 SIF1OUT r(0)
0 SIF0OUT r(0)
rw(0)
rw(0)
rw(0)
r(0)
SIFS2x
Bits 15-14
S2 source select. These bits select the S2 source for the PSM when SIFCS = 1. 00 SIF0OUT is the S2 source. 01 SIF1OUT is the S2 source. 10 SIF2OUT is the S2 source. 11 SIF3OUT is the S2 source. S1 source select. These bits select the S1 source fro the PSM when SIFCS = 1. 00 SIF0OUT is the S1 source. 01 SIF1OUT is the S1 source. 10 SIF2OUT is the S1 source. 11 SIF3OUT is the S1 source. SIFIFG4 interrupt flag source 00 SIFIFG4 is set with each count of SIFCNT2. 01 SIFIFG4 is set if (SIFCNT2 modulo 4) = 0. 10 SIFIFG4 is set if (SIFCNT2 modulo 64) = 0. 11 SIFIFG4 is set when SIFCNT2 decrements from 01h to 00h. SIFIFG3 interrupt flag source 00 SIFIFG3 is set with each count, up or down, of SIFCNT1. 01 SIFIFG3 is set if (SIFCNT1 modulo 4) = 0. 10 SIFIFG3 is set if (SIFCNT1 modulo 64) = 0. 11 SIFIFG3 is set when SIFCNT1 rolls over from 0FFh to 00h. Comparator output/Timer_A input selection 0 The SIFEX(tsm) signal and the comparator output are connected to the TACCRx inputs. 1 The SIFxOUT outputs are connected to the TACCRx inputs selected with the SIFS1x and SIFS2x bits.
SIFS1x
Bits 13-12
SIFIS2x
Bits 11-10
SIFIS1x
Bits 9-8
SIFCS
Bit 7
32-44
Scan IF
6-4
SIFIFG0 interrupt flag source. These bits select when the SIFIFG0 flag is set. 000 SIFIFG0 is set when SIF0OUT is set. 001 SIFIFG0 is set when SIF0OUT is reset. 010 SIFIFG0 is set when SIF1OUT is set. 011 SIFIFG0 is set when SIF1OUT is reset. 100 SIFIFG0 is set when SIF2OUT is set. 101 SIFIFG0 is set when SIF2OUT is reset. 110 SIFIFG0 is set when SIF3OUT is set. 111 SIFIFG0 is set when SIF3OUT is reset. AFE output bit 3 AFE output bit 2 AFE output bit 1 AFE output bit 0
Scan IF
32-45
Scan IF Registers
7 SIFDIV3Bx rw(0)
5 SIFDIV3Ax
3 SIFDIV2x
1 SIFDIV1x rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
rw(0)
SIFCNTRST
Bit 15
Counter reset. Setting this bit enables the SIFCNT register to be reset when it is read. 0 SIFCNT register is not reset when read 1 SIFCNT register is reset when it is read SIFCNT2 enable 0 SIFCNT2 is disabled 1 SIFCNT2 is enabled SIFCNT1 decrement enable 0 SIFCNT1 decrement is disabled 1 SIFCNT1 decrement is enabled SIFCNT1 increment enable 0 SIFCNT1 increment is disabled 1 SIFCNT1 increment is enabled Q7 enable. This bit enables bit Q7 for the next PSM state calculation when SIFQ6EN = 1. 0 Q7 is not used to determine the next PSM state 1 Q7 is used to determine the next PSM state Q6 enable. This bit enables Q6 for the next PSM state calculation. 0 Q6 is not used to determine the next PSM state 1 Q6 is used to determine the next PSM state
SIFCNT2EN
Bit 14
SIFCNT1 ENM
Bit 13
SIFCNT1 ENP
Bit 12
SIFQ7EN
Bit 11
SIFQ6EN
Bit 10
32-46
Scan IF
TSM start trigger ACLK divider. These bits together with the SIFDIV3Ax bits select the division rate for the TSM start trigger. TSM start trigger ACLK divider. These bits together with the SIFDIV3Bx bits select the division rate for the TSM start trigger. The division rate is:
SIFDIV3Ax SIFDIV3Bx 000 001 010 011 100 101 110 111 000 2 6 10 14 18 22 26 30 001 6 18 30 42 54 66 78 90 010 10 30 50 70 90 110 130 150 011 14 42 70 98 126 154 182 210 100 18 54 90 126 162 198 234 270 101 22 66 110 154 198 242 286 330 110 26 78 130 182 234 286 338 390 111 30 90 150 210 270 330 390 450
SIFDIV3Ax
SIFDIV2x
Bits 3-2
ACLK divider. These bits select the ACLK division. 00 /1 01 /2 10 /4 11 /8 TSM SMCLK divider. These bits select the SMCLK division for the TSM. 00 /1 01 /2 10 /4 11 /8
SIFDIV1x
Bits 1-0
Scan IF
32-47
Scan IF Registers
7 SIFTSMRP rw(0)
5 SIFCLKFQx
2 SIFFNOM
1 SIFCLKG ON rw(0)
0 SIFCLKEN rw(0)
rw(1)
rw(0)
rw(0)
rw(0)
rw(0)
SIFCNT3x
Internal oscillator counter. SIFCNT3 counts internal oscillator clock cycles during one ACLK period when SIFFNOM = 0 or during four ACLK periods when SIFFNOM = 1 after SIFCLKGON and SIFCLKEN are both set TSM repeat mode 0 Each TSM sequence is triggered by the ACLK divider controlled with the SIFDIV3Ax and SIFDIV3Bx bits. 1 Each TSM sequence is immediately started at the end of the previous sequence. Internal oscillator frequency adjust. These bits are used to adjust the internal oscillator frequency. Each increase or decrease of the SIFCLKFQx bits increases or decreases the internal oscillator frequency by approximately 5%. 0000 Minimum frequency : 1000 Nominal frequency : 1111 Maximum frequency Internal oscillator nominal frequency 0 4 MHz 1 1 MHz Internal oscillator control. When SIFCLKGON = 1 and SIFCLKEN = 1, the internal oscillator calibration is started. SIFCLKGON is not used when SIFCLKEN = 0. 0 No internal oscillator calibration is started. 1 The internal oscillator calibration is started when SIFCLKEN = 1. Internal oscillator enable. This bit selects the high frequency clock source for the TSM. 0 TSM high frequency clock source is SMCLK. 1 TSM high frequency clock source is the Scan IF internal oscillator.
SIFTSMRP
SIFCLKFQx
Bits 6-3
SIFFNOM
Bit 2
SIFCLKG ON
Bit 1
SIFCLKEN
Bit 0
32-48
Scan IF
Scan IF Registers
4 DAC Data
rw
rw
rw
rw
rw
rw
rw
rw
Unused
Unused. These bits are always read as zero, and when written, do not affect the DAC output. 10-bit DAC data
DAC Data
Scan IF
32-49
Scan IF Registers
7 SIFTESTS1 rw(0)
6 SIFRSON rw(0)
5 SIFCLKON rw(0)
4 SIFCA rw(0)
3 SIFEX rw(0)
2 SIFLCEN rw(0)
1 SIFCHx rw(0)
rw(0)
SIF REPEATx
These bits together with the SIFACLK bit configure the duration of this state. SIFREPEATx selects the number of clock cycles for this state. The number of clock cycles = SIFREPEATx + 1. This bit selects the clock source for the TSM. 0 The TSM clock source is the high frequency source selected by the SIFCLKEN bit. 1 The TSM clock source is ACLK This bit indicates the end of the TSM sequence. The duration of this state is always one high-frequency clock period, regardless of the SIFACLK and SIFREPEATx settings. 0 TSM sequence continues with next state 1 End of TSM sequence TSM DAC on. This bit turns the DAC on during this state when SIFDACON = 0. 0 DAC off during this state. 1 DAC on during this state. TSM test cycle control. This bit selects for this state which channel-control bits and which DAC registers are used for a test cycle. 0 The SIFTCH0x bits select the channel and SIFDACR6 is used for the DAC 1 The SIFTCH1x bits select the channel and SIFDACR7 is used for the DAC Internal output latches enabled. This bit enables the internal latches of the AFE output stage. 0 Output latches disabled 1 Output latches enabled
SIFACLK
SIFSTOP
Bit 9
SIFDAC
Bit 8
SIFTESTS1
Bit 7
SIFRSON
Bit 6
32-50
Scan IF
Bit 5
High-frequency clock on. Setting this bit turns the high-frequency clock source on for this state when SIFACLK = 1, even though the high frequency clock is not used for the TSM. When the high-frequency clock is sourced from the DCO, the DCO is forced on for this state, regardless of the MSP430 low-power mode. 0 High-frequency clock is off for this state when SIFACLK = 1 1 High-frequency clock is on for this state when SIFACLK = 1 TSM comparator on. Setting this bit turns the comparator on for this state when SIFCAON = 0. 0 Comparator off during this state 1 Comparator on during this state Excitation and sample-and-hold. This bit, together with the SIFSH and SIFTEN bits, enables the excitation transistor or samples the input voltage during this state. SIFLCEN must be set to 1 when SIFEX = 1. 0 Excitation transistor disabled when SIFSH = 0 and SIFTEN = 1. Sampling disabled when SIFSH = 1 and SIFTEN = 0. 1 Excitation transistor enabled when SIFSH = 0 and SIFTEN = 1. Sampling enabled when SIFSH = 1 and SIFTEN = 0. LC enable. Setting this bit turns the damping transistor off, enabling the LC oscillations during this state when SIFTEN = 1. 0 All SIFCHx channels are internally damped. No LC oscillations. 1 The selected SIFCHx channel is not internally damped. The LC oscillates. Input channel select. These bits select the input channel to be measured or excited during this state. 00 SIFCH0 01 SIFCH1 10 SIFCH2 11 SIFCH3
SIFCA
Bit 4
SIFEX
Bit 3
SIFLCEN
Bit 2
SIFCHx
Bits 1-0
Scan IF
32-51
Scan IF Registers
Q7
Bit 7
When Q7 = 1, SIFIFG6 will be set. When SIFQ6EN = 1 and SIFQ7EN = 1 and Q7 = 1, the PSM proceeds to the next state immediately, regardless of the SIFSTOP(tsm) signal and Q7 is used in the next-state calculation. When Q6 = 1, SIFIFG5 will be set. When SIFQ6EN = 1, Q6 will be used in the next-state calculation. Bit 5 of the next state Bit 4 of the next state Bit 3 of the next state When Q2 = 1, SIFCNT1 decrements if SIFCNT1ENM = 1 and SIFCNT2 decrements if SIFCNT2EN = 1. When Q1 = 1, SIFCNT1 increments if SIFCNT1ENP = 1. Bit 2 of the next state
Q6 Q5 Q4 Q3 Q2 Q1 Q0
32-52
Scan IF
Chapter 33
Embedded
This chapter describes the Embedded Emulation Module (EEM) that is implemented in all MSP430 flash devices.
Topic
Page
33.1 EEM Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33-2 33.2 EEM Building Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33-4 33.3 EEM Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33-6
33-1
EEM Introduction
(device dependent)
- Clock control for timers, communication peripherals, and other modules
on a global device level or on a per-module basis during an emulation stop Figure 331 shows a simplified block diagram of the largest currently available 4xx EEM implementation. For more details on how the features of the EEM can be used together with the IAR Embedded Workbencht debugger see the application report Advanced Debugging Using the Enhanced Emulation Module (SLAA263) at www.msp430.com. Code Composer Essentials (CCE) and most other debuggers supporting MSP430 have the same or a similar feature set. For details, see the users guide of the applicable debugger.
33-2
EEM Introduction
Trigger Sequencer
OR OR
33-3
EEM Introduction
There are two different types of triggers, the memory trigger and the CPU register write trigger. Each memory trigger block can be independently selected to compare either the MAB or the MDB with a given value. Depending on the implemented EEM the comparison can be =, , , or . The comparison can also be limited to certain bits with the use of a mask. The mask is either bit-wise or byte-wise, depending upon the device. In addition to selecting the bus and the comparison, the condition under which the trigger is active can be selected. The conditions include read access, write access, DMA access, and instruction fetch. Each CPU register write trigger block can be independently selected to compare what is written into a selected register with a given value. The observed register can be selected for each trigger independently. The comparison can be =, , , or . The comparison can also be limited to certain bits with the use of a bit mask. Both types of triggers can be combined to form more complex triggers. For example, a complex trigger can signal when a particular value is written into a user-specified address.
33-4
EEM Introduction
The Trigger sequencer always starts at State 0 and must execute to State 3 to generate an action. If State 1 or State 2 are not required, they can be bypassed.
33-5
EEM Configurations
XS
S
3 1) Low byte 2) High byte 1 4 No No
M
5 1) Low byte 2) High byte 1 6 Yes No
L
8 All 16 or 20 bits 2 8 Yes Yes
only)
Distinction between CPU, DMA, read, and write accesses =, , , or comparison (in XS only =, )
- At least two trigger combination registers - Hardware breakpoints using the CPU Stop reaction - Clock control with individual control of module clocks
33-6
IMPORTANT NOTICE
Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications, enhancements, improvements, and other changes to its products and services at any time and to discontinue any product or service without notice. Customers should obtain the latest relevant information before placing orders and should verify that such information is current and complete. All products are sold subject to TIs terms and conditions of sale supplied at the time of order acknowledgment. TI warrants performance of its hardware products to the specifications applicable at the time of sale in accordance with TIs standard warranty. Testing and other quality control techniques are used to the extent TI deems necessary to support this warranty. Except where mandated by government requirements, testing of all parameters of each product is not necessarily performed. TI assumes no liability for applications assistance or customer product design. Customers are responsible for their products and applications using TI components. To minimize the risks associated with customer products and applications, customers should provide adequate design and operating safeguards. TI does not warrant or represent that any license, either express or implied, is granted under any TI patent right, copyright, mask work right, or other TI intellectual property right relating to any combination, machine, or process in which TI products or services are used. Information published by TI regarding third-party products or services does not constitute a license from TI to use such products or services or a warranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual property of the third party, or a license from TI under the patents or other intellectual property of TI. Reproduction of TI information in TI data books or data sheets is permissible only if reproduction is without alteration and is accompanied by all associated warranties, conditions, limitations, and notices. Reproduction of this information with alteration is an unfair and deceptive business practice. TI is not responsible or liable for such altered documentation. Information of third parties may be subject to additional restrictions. Resale of TI products or services with statements different from or beyond the parameters stated by TI for that product or service voids all express and any implied warranties for the associated TI product or service and is an unfair and deceptive business practice. TI is not responsible or liable for any such statements. TI products are not authorized for use in safety-critical applications (such as life support) where a failure of the TI product would reasonably be expected to cause severe personal injury or death, unless officers of the parties have executed an agreement specifically governing such use. Buyers represent that they have all necessary expertise in the safety and regulatory ramifications of their applications, and acknowledge and agree that they are solely responsible for all legal, regulatory and safety-related requirements concerning their products and any use of TI products in such safety-critical applications, notwithstanding any applications-related information or support that may be provided by TI. Further, Buyers must fully indemnify TI and its representatives against any damages arising out of the use of TI products in such safety-critical applications. TI products are neither designed nor intended for use in military/aerospace applications or environments unless the TI products are specifically designated by TI as military-grade or "enhanced plastic." Only products designated by TI as military-grade meet military specifications. Buyers acknowledge and agree that any such use of TI products which TI has not designated as military-grade is solely at the Buyer's risk, and that they are solely responsible for compliance with all legal and regulatory requirements in connection with such use. TI products are neither designed nor intended for use in automotive applications or environments unless the specific TI products are designated by TI as compliant with ISO/TS 16949 requirements. Buyers acknowledge and agree that, if they use any non-designated products in automotive applications, TI will not be responsible for any failure to meet such requirements. Following are URLs where you can obtain information on other Texas Instruments products and application solutions: Products Audio Amplifiers Data Converters DLP Products DSP Clocks and Timers Interface Logic Power Mgmt Microcontrollers RFID OMAP Mobile Processors Wireless Connectivity www.ti.com/audio amplifier.ti.com dataconverter.ti.com www.dlp.com dsp.ti.com www.ti.com/clocks interface.ti.com logic.ti.com power.ti.com microcontroller.ti.com www.ti-rfid.com www.ti.com/omap www.ti.com/wirelessconnectivity TI E2E Community Home Page e2e.ti.com Applications Automotive and Transportation www.ti.com/automotive Communications and Telecom www.ti.com/communications Computers and Peripherals Consumer Electronics Energy and Lighting Industrial Medical Security Space, Avionics and Defense Video and Imaging www.ti.com/computers www.ti.com/consumer-apps www.ti.com/energy www.ti.com/industrial www.ti.com/medical www.ti.com/security www.ti.com/space-avionics-defense www.ti.com/video
Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265 Copyright 2012, Texas Instruments Incorporated