Slau 056
Slau 056
User’s Guide
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 TI’s 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 TI’s 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 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.
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.
Mailing Address:
Texas Instruments
Post Office Box 655303
Dallas, Texas 75265
Preface
- Chapter 1—Introduction
- Chapter 4—Memory
iii
Related Documentation From Texas Instruments
- Chapter 11—Timer_A
- Chapter 12—Timer_B
- Chapter 15—Comparator_A
- Chapter 17—ADC12
Notational Conventions
FCC Warning
This equipment is intended for use in a laboratory test environment only. It gen-
erates, 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 en-
vironments 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.
iv
Contents
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1
1.1 Features and Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
1.2 41x Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
1.3 43x Devices† . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
1.4 44x Devices† . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
4 Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
4.2 Data in the Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
4.3 Internal ROM Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4
4.3.1 Processing of Memory Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4
4.3.2 Computed Branches and Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5
4.4 RAM and Peripheral Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5
v
Contents
vi
Contents
11 Timer_A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-1
11.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2
11.2 Timer_A Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-3
11.2.1 Timer Mode Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-3
11.2.2 Clock Source Select and Divider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-4
11.2.3 Starting the Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-5
11.3 Timer Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-5
11.3.1 Timer – Stop Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-5
11.3.2 Timer – Up Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-5
11.3.3 Timer – Continuous Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-8
11.3.4 Timer – Up/Down Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-9
11.4 Capture/Compare Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-12
11.4.1 Capture/Compare Block – Capture Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-13
11.4.2 Capture/Compare Block – Compare Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-17
11.4.3 Output Unit – Output Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-18
11.4.4 Output Control Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-19
11.4.5 Output Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-20
11.5 Timer_A Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-22
11.5.1 Timer_A Control Register TACTL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-23
11.5.2 Timer_A Register TAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-25
vii
Contents
12 Timer_B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-1
12.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-2
12.1.1 Similarities and Differences From Timer_A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-2
12.2 Timer_B Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-5
12.2.1 Timer Length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-5
12.2.2 Timer Mode Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-5
12.2.3 Clock Source Select and Divider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-6
12.2.4 Starting the Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-7
12.3 Timer Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-8
12.3.1 Timer—Stop Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-8
12.3.2 Timer—Up Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-8
12.3.3 Timer—Continuous Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-10
12.3.4 Timer—Up/Down Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-12
12.4 Capture/Compare Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-15
12.4.1 Capture/Compare Block—Capture Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-16
12.4.2 Capture/Compare Block—Compare Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-19
12.5 The Output Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-23
12.5.2 Output Control Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-25
12.5.3 Output Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-26
12.6 Timer_B Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-29
12.6.1 Timer_B Control Register TBCTL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-29
12.6.2 Timer_B Register TBR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-32
12.6.3 Capture/Compare Control Register TBCCTLx . . . . . . . . . . . . . . . . . . . . . . . . . 12-32
12.6.4 Timer_B Interrupt Vector Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-35
viii
Contents
15 Comparator_A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-1
15.1 Comparator_A Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-2
15.2 Comparator_A Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-3
15.2.1 Input Analog Switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-3
15.2.2 Input Multiplexer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-3
15.2.3 The Comparator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-3
15.2.4 The Output Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-3
15.2.5 The Voltage Reference Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-4
15.2.6 Comparator_A Interrupt Circuitry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-5
15.3 Comparator_A Control Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-5
15.3.1 Comparator_A, Control Register CACTL1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-6
15.3.2 Comparator_A, Control Register CACTL2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-7
15.3.3 Comparator_A, Port Disable Register CAPD . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-8
15.4 Comparator_A in Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-9
15.4.1 Analog Signals at Digital Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-9
15.4.2 Comparator_A Used to Measure Resistive Elements . . . . . . . . . . . . . . . . . . . 15-11
15.4.3 Measuring Two Independent Resistive Element Systems . . . . . . . . . . . . . . . 15-13
15.4.4 Comparator_A Used to Detect a Current or Voltage Level . . . . . . . . . . . . . . . 15-16
15.4.5 Comparator_A Used to Measure a Current or Voltage Level . . . . . . . . . . . . . 15-17
15.4.6 Measuring the Offset Voltage of Comparator_A . . . . . . . . . . . . . . . . . . . . . . . . 15-20
15.4.7 Compensating for the Offset Voltage of Comparator_A . . . . . . . . . . . . . . . . . 15-22
ix
Contents
17 ADC12 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-1
17.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-2
17.2 ADC12 Description and Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-4
17.2.1 ADC Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-4
17.2.2 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-5
17.3 Analog Inputs and Multiplexer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-6
17.3.1 Analog Multiplexer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-6
17.3.2 Input Signal Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-7
17.3.3 Using the Temperature Diode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-7
17.4 Conversion Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-8
17.5 Conversion Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-9
17.5.1 Single-Channel, Single-Conversion Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-9
17.5.2 Sequence-of-Channels Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-12
17.5.3 Repeat-Single-Channel Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-16
17.5.4 Repeat-Sequence-of-Channels Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-17
17.5.5 Switching Between Conversion Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-19
17.5.6 Power Down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-20
17.6 Conversion Clock and Conversion Speed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-21
17.7 Sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-22
17.7.1 Sampling Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-22
17.7.2 Sample Signal Input Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-23
17.7.3 Sampling Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-24
17.7.4 Using the MSC Bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-27
17.7.5 Sample Timing Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-29
17.8 ADC12 Control Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-30
17.8.1 Control Registers ADC12CTL0 and ADC12CTL1 . . . . . . . . . . . . . . . . . . . . . . 17-31
17.8.2 Conversion-Memory Registers ADC12MEMx . . . . . . . . . . . . . . . . . . . . . . . . . 17-35
17.8.3 Control Registers ADC12MCTLx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-35
17.8.4 ADC12 Interrupt Flags ADC12IFG.x and Interrupt-Enable Registers
ADC12IEN.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-37
17.8.5 ADC12 Interrupt Vector Register ADC12IV . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-37
17.9 A/D Grounding and Noise Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-41
x
Contents
xi
Contents
Figures
2–1 MSP430 System Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
2–2 Bus Connection of Modules/Peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
3–1 Brownout/Reset, SVS, Reset, and Power-Up Clear Schematic . . . . . . . . . . . . . . . . . . . . . . 3-2
3–2 Block Diagram of Brownout and SVS Circuits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3
3–3 Brownout Circuit Operating Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4
3–4 Operating Levels for SVS and Brownout/Reset Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5
3–5 Interrupt Priority Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8
3–6 Block Diagram of NMI Interrupt Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9
3–7 RST/NMI Mode Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9
3–8 Interrupt Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12
3–9 Return From Interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12
3–10 Status Register (SR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12
3–11 MSP430x3xx Family Operating Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23
3–12 Typical Current Consumption vs Operating Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24
4–1 Memory Map of Basic Address Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
4–2 Memory Data Bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
4–3 Bits, Bytes, and Words in a Byte-Organized Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
4–4 ROM Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4
4–5 Byte and Word Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6
4–6 Register-Byte/Byte-Register Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6
4–7 Example of RAM/Peripheral Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8
5–1 Program Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
5–2 System Stack Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
5–3 Stack Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
5–4 PUSH SP and POP SP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
5–5 Status Register Bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
5–6 Operand Fetch Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-12
5–7 Double Operand Instruction Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17
5–8 Single Operand Instruction Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-18
5–9 Conditional-Jump Instruction Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-19
5–10 Core Instruction Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-22
6–1 Connection of the Hardware Multiplier Module to the Bus System . . . . . . . . . . . . . . . . . . . 6-2
6–2 Block Diagram of the MSP430 16y16-Bit Hardware Multiplier . . . . . . . . . . . . . . . . . . . . . . . 6-3
6–3 Registers of the Hardware Multiplier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6
7–1 Frequency-Locked Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3
7–2 Principle of LFXT1 Oscillator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4
7–3 Digitally-Controlled Oscillator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-6
7–4 Fractional Tap Frequency Required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7
7–5 Modulator Hop Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8
xii
Contents
xiii
Contents
xiv
Contents
xv
Contents
xvi
Contents
xvii
Contents
Tables
3–1 Interrupt Control Bits in SFRs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13
3–2 MSP340x41x Interrupt Enable Registers 1 and 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14
3–3 MSP430x43x Interrupt Enable Registers 1 and 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14
3–4 MSP430x44x Interrupt Enable Registers 1 and 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15
3–5 MSP430x41x Interupt Flag Registers 1 and 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15
3–6 MSP430x43x Interrupt Flag Registers 1 and 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16
3–7 MSP430x44x Interrupt Flag Registers 1 and 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16
3–8 MSP430x41x Module Enable Registers 1 and 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17
3–9 MSP430x43x Module Enable Registers 1 and 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17
3–10 MSP430x44x Module Enable Registers 1 and 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18
3–11 Interrupt Sources, Flags, and Vectors of 41x Configurations . . . . . . . . . . . . . . . . . . . . . . . 3-19
3–12 Interrupt Sources, Flags, and Vectors of 43x/44x Configurations . . . . . . . . . . . . . . . . . . . 3-20
3–13 Low-Power Mode Logic Chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23
4–1 Peripheral File Address Map—Word Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8
4–2 Peripheral File Address Map—Byte Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9
4–3 Special Function Register Address Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10
5–1 Register by Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
5–2 Description of Status Register Bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
5–3 Values of Constant Generators CG1, CG2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5
5–4 Source/Destination Operand Addressing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6
5–5 Register Mode Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-7
5–6 Indexed Mode Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8
5–7 Symbolic Mode Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9
5–8 Absolute Mode Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-10
5–9 Indirect Mode Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11
5–10 Indirect Autoincrement Mode Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-12
5–11 Immediate Mode Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-13
5–12 Instruction Format I and Addressing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14
5–13 Execution Cycles for Double Operand Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14
5–14 Instruction Format-II and Addressing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15
5–15 Execution Cycles for Single Operand Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15
5–16 Miscellaneous Instructions or Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-16
5–17 Double Operand Instruction Format Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17
5–18 Single Operand Instruction Format Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-18
5–19 Conditional-Jump Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-19
5–20 Emulated Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-20
6–1 Sum Extension Register Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4
6–2 Hardware Multiplier Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6
7–1 The DCO Range Control Bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9
xviii
Contents
xix
Contents
Examples
13–1 4800 Baud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-6
13–2 19,200 Baud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-6
13–3 Error Example for 2400 Baud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-28
13–4 Synchronization Error—2400 Baud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-31
xx
Contents
xxi
Contents
xxii
Chapter 1
Introduction
This chapter outlines the features and capabilities of the Texas Instruments
(TI) MSP430x4xx family of microcontrollers.
See http://www.ti.com for the latest device information and literature for the
MSP430 family.
Topic Page
1-1
Features and Capabilities
- Ultralow-power architecture:
0.1– 300-µA nominal operating current at 1 MHz
1.8–3.6-V operation
6-µs wake-up from standby mode
Extensive interrupt capability relieves need for polling
1-2
41x Devices
Introduction 1-3
44x Devices
1-4
Chapter 2
Architectural Overview
Topic Page
2.1 Introduction
The architecture of the MSP430 family is based on a memory-to-memory
architecture, a common address space for all functional blocks, and a reduced
instruction set applicable to all functional blocks as illustrated in Figure 2–1.
See specific device data sheets for complete block diagrams of individual
devices.
Oscillator ACLK
System PROGRAM DATA I/O Port USART I/O Port
Clock SMCLK
MCLK
MAB, 16 Bit
MAB, 4 Bit
CPU R/W
Incl.
16 Reg. MDB, 16 Bit MDB, 8 Bit
Bus
Conv.
LCD
ADC WDT Basic Timer Comparator
A Driver
Logic
Module Select
The CPU control over the program counter, the status register, and the stack
pointer (with the reduced instruction set) allows the development of
applications with sophisticated addressing modes and software algorithms.
2-2
Program Memory
In addition to program code, data may also be placed in the code memory
section of the memory map and may be accessed using word or byte
instructions; this is useful for data tables, for example. This unique feature
gives the MSP430 an advantage over other microcontrollers because the data
tables do not have to be copied to RAM for usage.
Sixteen words of memory are reserved for reset and interrupt vectors at the
top of the 64-kilobytes address space from 0FFFFh down to 0FFE0h.
Additionally, because the RAM and flash are connected to the CPU via the
same busses, program code can be loaded into and executed from RAM. This
is another unique feature of the MSP430 devices, and provides valuable,
easy-to-use debugging capability.
2.6 Peripherals
Peripheral modules are connected to the CPU through the MAB, the MDB, and
the interrupt service and request lines. The MAB is usually a 5-bit bus for most
of the peripherals. The MDB is an 8-bit or 16-bit bus. Most of the peripherals
operate in byte format. Modules with an 8-bit data bus are connected by
bus-conversion circuitry to the 16-bit CPU. The data exchange with these
modules must be handled with byte instructions. The SFRs are also handled
with byte instructions. The operation for 8-bit peripherals follows the order
described in Figure 2–2.
MAB
MDB
PUC
Clock source selection for peripherals and CPU is very flexible. Most
peripherals are capable of using the 32,768-Hz crystal oscillator clock, the
high-speed crystal oscillator clock (where applicable), or the DCO clock. The
CPU uses the DCO clock for execution. Additionally, the LFXT1 and XT2 clock
signals may be used for CPU execution on ’43x and ’44x devices. See
Chapter 7 for details on the clock system.
2-4
Chapter 3
Topic Page
3.1.1 Introduction
The MSP430 system reset circuitry (shown in Figure 3–1) sources two internal
reset signals: power-on reset (POR) and power-up clear (PUC). Different
events trigger these reset signals and different initial conditions exist
depending on which signal was generated.
Brownout/ SVS–
Reset Supply
Voltage S POR
Supervisor S Latch POR
0V R
RST/MNI 0V
Delay
NMI(WDTCTL.5)†
S PUC_FLL+
S
TMSEL†
WDTQn† Resetwd1
S POR
WDTIFG† S Latch
PUC
S
EQU† Resetwd2 R
KEYV
(From Flash Module)
MCLK
† From watchdog timer peripheral module
- A low signal on the RST/NMI pin when configured in the reset mode
- A brownout
- A low signal on the RST/NMI pin when configured in the reset mode
Note:
If desired, software can cause a PUC by simply writing to the watchdog timer
control register with an incorrect password.
3-2
System Reset and Initialization
Note:
Generation of the POR/PUC signals does not necessarily generate a system
reset interrupt. Anytime a POR is activated, a system reset interrupt is
generated. However, when a PUC is activated, a system reset interrupt may
or may not be generated. Instead, a lower priority interrupt vector may be
generated, depending on what action caused the PUC. Each device data
sheet gives a detailed table of what action generates each interrupt. This
table should be consulted for the proper handling of all interrupts.
Two circuits monitor the supply voltage as shown in Figure 3–2. The brownout/
reset circuit detects low supply voltages such as when a supply voltage is ap-
plied to or removed from the VCC terminal, whereas the supply voltage supervi-
sor circuit (SVS) detects if the supply voltage connected to the Vcc terminal
drops below the minimum supply voltage that is recommended for operation.
The SVS function is off at reset and power-up to conserve power. The SVS
function may be activated by software using control bits in the SVS control reg-
ister (SVSCTL).
VCC
Brownout
VCC VCC
G D
S
Set POR
+
t Reset ~ 50uS
Voltage P1.3/SVSOut (’41x devices)
Reference
of 1.2 V P1.3/TBOutH/SVSOut
G D
S (’43x and ’44x devices)
Set SVSFG
SVSCTL Reset
056h VLD PORON SVSon SVSOP SVSFG
SVSCTL Bits
rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) r r rw–(0)
3.1.1.1 Brownout/Reset
The brownout/reset circuit resets the device by triggering a POR signal when
power is applied or removed. The operating levels are shown in Figure 3–3.
When ramping up, the POR signal becomes active once VCC crosses the
VCC(start) level. It remains active until VCC crosses the V(B, IT+) threshold and
the delay t(BOR) elapses. The hysteresis VHys(B, IT–) ensures that the supply
voltage has to drop below V(B, IT–) to generate another POR signal from the
brownout/reset circuitry.
VCC V(B,IT–)
Bhys(B, IT–)
V(B,IT+)
V(B,IT–)
VCC(start)
1
Set Signal for
POR circuitry
0
t (BOR)
The minimum supply voltage to generate a reliable POR when VCC glitches
or dips depends on the pulse width of the voltage drop. Generally, if the width
of the voltage drop is small, a deeper voltage drop is required to trigger a POR
signal. See the device data sheet for electrical parameters.
The supply voltage supervisor circuit resets the device by triggering a POR
signal when VCC drops below the appropriate level. The operating levels for
the SVS and the brownout/reset circuit are shown in Figure 3–4. The SVS is
initially disabled by the brownout function and is enabled by software by bits
in the SVSCTL register. Any brownout situation deactivates the SVS function.
When the supply voltage is below V(SVS_Start) the SVS may or may not trigger
a POR. Proper SVS operation is ensured when the supply voltage is above the
V(SVS,start) level. When the supply voltage is between V(SVS,start) and
V(SVS,IT+) the POR signal is reliably triggered. When the supply voltage is
above V(SVS,IT+) the trigger for the POR signal becomes inactive after time
t(SVSR) elapses. When the supply voltage drops below V(SVS,IT–), another
POR is triggered.
The MSP430x41x devices have one V(SYS,IT–) level. The MSP430x43x and
MSP430x44x devices have 14 selectable V(SYS,IT–) levels. In addition, the
MSP430x43x and MSP430x44x devices can compare any external voltage
(not necessarily VCC) that is applied to pin P6.7/A7/SVSin to the internal 1.2
V reference. See the specific device data sheet for specifications of the
V(SYS,IT–) levels.
3-4
System Reset and Initialization
The SVS can be configured to generate a POR signal when a fault is detected
or to only set a bit in the control register. The PORON bit on the SVSCTL regis-
ter determines this function.
The minimum supply voltage required to generate a reliable POR when VCC
glitches or dips depends on the pulse width of the voltage drop. Generally, if
the width of the voltage drop is small, a deeper voltage drop is required to
trigger a POR signal. See the device data sheet for electrical parameters.
The VLD bits control the on/off state of the supply voltage supervisor (SVS)
circuitry. The SVS function is off if VLD=0, and on if VLD=1. Bit PORON
enables or disables the automatic reset of MSP430 upon a low-voltage
situation. If PORON=1, a low-voltage situation generates a POR signal and
resets the MSP430. Bit SVSOP is used to watch the actual SVS comparator
output. Bit SVSFG is set if a low-voltage situation is detected, remains set until
the low-voltage situation is removed, and then it is reset by software; SVSFG
latches such events whereas SVSOP represents the actual output of the
comparator.
Note:
Whenever the supply voltage conditions trigger a POR from the brownout,
the SVS is disabled and must be reenabled by software.
VCC(start)
Brownout Brownout
Brownout Region Region
1
0
t (BOR) t
SVS Circuit is active from VLD > to VCC < V(B,IT–) (BOR)
SVSOut
1
0
t (SVSon)
Set POR t (SVSR)
1
Undefined
SVS
Operating
SVS Operating Voltage Voltage
SVS Operating Range
Voltage Range
Brownout
Brownout Operating Voltage Range
Operating Voltage
Range
- I/O flags are cleared as described in the Digital I/O Configuration chapter.
- FLL+ begins regulation of the DCO. The FLL+ starts with the same default
frequency target as the FLL in ’3XX devices.
After a system reset, the user program can evaluate the various flags to
determine the source of the reset and take appropriate action.
Type Description
rw–(0) Read/write, reset with POR
rw–0 Read/write, reset with POR or PUC
r–1 Read only, set with POR or PUC
r Read only, no initial state
w Write only, no initial state
3-6
Global Interrupt Structure
(Non)maskable interrupts are not masked by the general interrupt enable bit
(GIE) but are individually enabled or disabled by an individual interrupt enable
bit. When a (non)maskable interrupt is accepted, the corresponding interrupt
enable bit is automatically reset, therefore disabling the interrupt for execution
of the interrupt service routine (ISR). The RETI (return from interrupt)
instruction has no effect on the individual enable bits of the (non)maskable
interrupts. So the software must set the corresponding interrupt enable bit in
the ISR before execution of the RETI instruction for the interrupt to be
reenabled after the ISR.
GMIRS
PUC Bus
Grant
PUC
OSCfault
Circuit
Flash ACCV
Reset/NMI
Reset and NMI, as shown in Figure 3–6, can only be used as alternative
interrupts because they use the same input pin. The associated control bits are
located in the watchdog timer control register shown in Figure 3–7, and are
password protected.
3-8
MSP430 Interrupt-Priority Scheme
ACCV
ACCVIFG
S
FCTL1.1
ACCVIE
Flash Module
PUC
RST/NMI
POR PUC
KEYV VCC
PUC
System Reset
Generator
POR
NMIFG
S
NMIRS
IFG1.4
Clear
NMIES TMSEL NMI WDTQn EQU PUC POR
PUC
NMIIE
WDTIFG
S
IE1.4 IRQ
Clear IFG1.0
Clear
PUC WDT
Counter
OSCFault POR
OFIFG
S
IFG1.1
IRQA
TMSEL
OFIE
WDTIE
IE1.1
Clear
IE1.0
NMI_IRQA Clear
PUC
PUC
Watchdog Timer Module
IRQA: Interrupt Request Accepted
If the RST/NMI pin is set to the NMI function, a signal edge (selected by the
NMIES bit) will generate an unconditional interrupt. When accepted, program
execution begins at the address stored in location 0FFFCh. The RST/NMI flag
in the SFR IFG1.4 is also set.
Note:
When configured in the NMI mode, a signal generating an NMI event should
not hold the RST/NMI pin low. When a PUC is generated (see Section 3.1.1),
the PUC resets the bits in the WDTCTL register. This results in the RST/NMI
pin being configured in the reset mode. If the signal on the RST/NMI pin that
generated the NMI event holds the pin low, the processor will be held in the
reset state.
When NMI mode is selected and the NMI edge select bit is changed, an NMI
can be generated, depending on the actual level at RST/NMI pin. When the
NMI edge select bit is changed before selecting the NMI mode, no NMI is
generated.
The NMI interrupt is maskable by the NMIIE bit.
The oscillator fault signal is triggered if the 5 MSB (29–25) DCO control taps
in the SCFI1 register are equal to 0, or greater than or equal to 28h. The
oscillator-fault signal is also triggered if the LFXT1 (LF or HF mode) or the XT2
oscillator is not running, stops running after being operational, or restarts
3-10
Interrupt Processing
running (also from off mode). Note that a PUC signal triggers an oscillator fault
because the PUC switches the 5 MSB(29–25) DCO control taps to 0. The
oscillator fault signal can be enabled to generate an NMI by bit IE1.1 in the
SFRs. The interrupt flag IFG1.1 in the SFRs can then be tested by the interrupt
service routine to determine if the NMI was caused by an oscillator fault. See
Chapter 7 for more details on the operation of the DCO oscillator, the FLL+,
and the crystal oscillators.
3) The program counter pointing to the next instruction is pushed onto the
stack.
7) The GIE bit is reset; the CPUOff bit, the OscOff bit, and the SCG1 bit are
cleared; the status bits V, N, Z, and C are reset. SCG0 is left unchanged,
and loop control remains in the previous operating condition.
8) The content of the appropriate interrupt vector is loaded into the program
counter: the program continues with the interrupt handling routine at that
address.
The interrupt latency is six cycles, starting with the acceptance of an interrupt
request, and lasting until the start of execution of the appropriate
interrupt-service routine first instruction, as shown in Figure 3–8.
Item1 Item1
SP Item2 TOS Item2
PC
SP SR TOS
1) The status register with all previous settings pops from the stack. All pre-
vious settings of GIE, CPUOFF, etc. are now in effect, regardless of the
settings utilized during the interrupt service routine.
2) The program counter pops from the stack and begins execution at the
point where it was interrupted.
Item1 Item1
Item2 SP Item2 TOS
PC PC
SP SR TOS SR
A RETI instruction takes five cycles. Interrupt nesting is activated if the GIE bit
is set inside the interrupt handling routine. The GIE bit is located in status
register SR/R2, which is included in the CPU as shown in Figure 3–10.
rw-0
Apart from the GIE bit, other sources of interrupt requests can be enabled/
disabled individually or in groups. The interrupt enable flags are located
3-12
Interrupt Processing
The Module Enable bits, Interrupt Enable bits, and Interrupt flags contained
in the SFRs are shown in the following tables.
3-14
Interrupt Processing
3-16
Interrupt Processing
3-18
Interrupt Processing
All eight bits of ports P1 and P2 are designed for interrupt processing of
external events. All individual I/O bits are independently programmable. Any
combinations of inputs, outputs, and interrupt conditions are possible. This
allows easy adaptation to different I/O configurations. See Chapter 8 for more
details on I/O ports.
3-20
Operating Modes
There are four bits that control the CPU and the system clock generator:
CPUOff, OscOff, SCG0, and SCG1. These four bits support discontinuous
active mode (AM) requests, to limit the time period of the full operating mode,
and are located in the status register. The major advantage of including the
operating mode bits in the status register is that the present state of the
operating condition is saved onto the stack during an interrupt service request.
As long as the stored status register information is not altered, the processor
continues (after RETI) with the same operating mode as before the interrupt
event. Another program flow may be selected by manipulating the data stored
on the stack or the stack pointer. Being able to access the stack and stack
pointer with the instruction set allows the program structures to be individually
optimized, as illustrated in the following program flow:
Two different modes are available to return from the interrupt service routine
and continue the flow of operation:
J Return with low-power mode bits set. When returning from the
interrupt, the program counter points to the next instruction. The
instruction pointed to is not executed, since the restored low-power
mode stops CPU activity.
J Return with low-power mode bits reset. When returning from the
interrupt, the program continues at the address following the
instruction that set the OscOff or CPUOff-bit in the status register. To
use this mode, the interrupt service routine must reset the OscOff,
CPUOff, SCGO, and SCG1 bits on the stack. Then, when the SR
contents are popped from the stack upon RETI, the operating mode
will be active mode (AM).
Note:
Peripheral operation is not halted by CPUOff. Peripherals are controlled by
their individual control registers.
3-22
Operating Modes
RST/NMI VCC On
Reset Active
POR
WDT Active,
Time Expired, Overflow WDTIFG = 0
Active Mode
CPU Is Active
Various Modules Are Active CPUOff = 1
CPUOff = 1
OscOff = 1
SCG0,1 = 0
SG0,1 = X
LP Mode LPM0
LP-Mode LPM4
CPU Off, FLL+ On
CPU Off, FLL+ Off
MCLK on, ACLK On
MCLK Off, ACLK Off
CPUOff = 1
SCG0 = 1 DC Generator Off
SCG1 = 0 CPUOff = 1 CPUOff = 1
SCG0 = 0 SCG0,1 = 1
LP Mode LPM1 LP Mode LPM3
SCG1 = 1
CPU Off, FLL+ Off CPU Off, FLL+ Off
MCLK On, ACLK On MCLK Off, ACLK On
LP Mode LPM2
CPU Off, FLL+ Off
MCLK Off, ACLK On DC Generator Off
360
315
280
270
ICC/µ A
225 VCC = 3 V
180 VCC = 2.2 V
135
90 55
45 32
17 11 2 1 0.1 0.1
0
AM LPM0 LPM2 LPM3 LPM4
Operating Modes
The low-power modes 1–4 enable or disable the CPU and the clocks. In
addition to the CPU and clocks, enabling or disabling specific peripherals may
further reduce total current consumption of the individual modes. The activity
state of each peripheral is controlled by the control registers for the individual
peripherals. An example is the enable/disable function of the segment lines of
the LCD peripheral: they can be turned on or off using a single register bit in
the LCD control and mode register. In addition, the SFRs include module
enable bits that may be used to enable or disable the operation of specific
peripheral modules (see Table 3–4).
The peripherals are enabled or disabled according with their individual control
register settings, and with the module enable registers in the SFRs. All I/O port
pins and RAM/registers are unchanged. Wake-up is possible through all
enabled interrupts.
The following are examples of entering and exiting LPM0. The method shown
is applicable to all low-power modes.
3-24
Operating Modes
Peripherals that operate with the MCLK signal are inactive because the clock
signal is inactive. Peripherals that operate with the ACLK signal are active or
inactive according with the individual control registers and the module enable
bits in the SFRs. All I/O port pins and the RAM/registers are unchanged.
Wake-up is possible by enabled interrupts coming from active peripherals or
RST/NMI.
Before activating LPM4, the software should consider the system conditions
during the low-power mode period. The two most important conditions are
environmental (that is, temperature effect on the DCO), and the clocked
operation conditions.
The environment defines whether the value of the frequency integrator should
be held or corrected. A correction should be made when ambient conditions
are anticipated to change drastically enough to increase or decrease the
system frequency while the device is in LPM4.
There are some basic practices to follow when current consumption is a critical
part of a system application:
- Switch off the MCLK source for the CPU when not required. Use interrupts
to activate the CPU. Program execution starts in less than 6 µs.
- Select the weakest drive capability if an LCD is used or switch the drive
off.
- Tie all unused inputs to an applicable voltage level. The list below defines
the correct termination for all unused pins.
3-26
Chapter 4
Memory
Topic Page
Memory 4-1
Introduction
4.1 Introduction
All of the physically separated memory areas (ROM, RAM, SFRs, and
peripheral modules) are mapped into the common address space, as shown
in Figure 4–1 for the MSP430 family. The addressable memory space is 64KB.
Future expansion is possible.
The memory data bus (MDB) is 16- or 8-bits wide. For those modules that can
be accessed with word data the width is always 16 bits. For the other modules,
the width is 8 bits, and they must be accessed using byte instructions only. The
program memory (ROM) and the data memory (RAM) can be accessed with
byte or word instructions.
High Byte
Data Bus
Low Byte
4-2
Data in the Memory
xxxAh
15 14 . . Bits . . 9 8 xxx9h
7 6 . . Bits . . 1 0 xxx8h
Byte xxx7h
Byte xxx6h
xxx3h
Memory 4-3
Internal ROM Organization
32 k
0D000h
0CFFFh
xx k
08000h
4-4
RAM and Peripheral Organization
The computed branch and subroutine calls are valid throughout the entire
memory space.
- The SFRs are byte-oriented and mapped into the address space from 0h
up to 0Fh.
- Peripheral modules that are byte-oriented are mapped into the address
space from 010h up to 0FFh.
- Peripheral modules that are word-oriented are mapped into the address
space from 100h up to 01FFh.
The instruction mnemonic suffix defines the data as being word or byte data.
Example:
ADD.B &TCDATA,TCSUM_L ;Byte access
ADDC.B TCSUM_H ;Byte access
ADD R5,SUM_A ; = ADD.W R5,SUM_A ;Word access
ADDC SUM_B ;= ADDC.W SUM_A ;Word access
A word consists of two bytes: a high byte (bit 15 to bit 8), and a low byte
(bit 7 to bit 0) as shown in Figure 4–5. It must always align to an even address.
Memory 4-5
RAM and Peripheral Organization
xxxAh
ADD.B Byte1, Byte2:
Byte1: 012h xxx9h Byte2 = 012h + 034h = 046h
xxx3h
All operations on the stack and PC are word operations and use even-aligned
memory addresses.
4-6
RAM and Peripheral Organization
08Fh 05Fh
+ 012h + 002h ;Low byte of R5
0A1h 00061h ;–>Store into R5 -
;High byte is 0
Mem (0203h) = 0A1h R5 = 00061h
C = 0, Z = 0, N = 1 C = 0, Z = 0, N = 0
Peripheral modules that are mapped into the word address space must be
accessed using word instructions (for example, MOV R5,&WDTCTL).
Peripheral modules that are mapped into the byte address space must be
accessed with byte instructions (MOV.B #1,&TCCTL).
The addressing of both is through the absolute addressing mode or the 16-bit
working registers using the indexed, indirect, or indirect autoincrement
addressing mode. See Figure 4–7 for the RAM/peripheral organization.
Memory 4-7
RAM and Peripheral Organization
Word modules are peripherals that are connected to the 16-bit MDB.
The peripheral file address space is organized into sixteen frames with each
frame representing eight words as described in Table 4–1.
Byte modules are peripherals that are connected to the reduced (eight LSB)
MDB. Access to byte modules is always by byte instructions. The hardware
in the peripheral byte modules takes the low byte (the LSBs) during a write
operation.
4-8
RAM and Peripheral Organization
Memory 4-9
RAM and Peripheral Organization
4-10
Chapter 5
16-Bit CPU
Topic Page
5-2
CPU Registers
0xxxh I1 I1 I1
0xxxh – 2 I2 I2 I2
0xxxh – 4 I3 SP I3 I3 SP
0xxxh – 6 #1 SP
0xxxh – 8
The special cases of using the SP as an argument to the PUSH and POP
instructions are described below.
SPold
SP1 SP1 SP2 SP1
The stack pointer is changed after The stack pointer is not changed after a
a PUSH SP instruction. PUSH SP, POP SP instruction sequence.
The POP SP instruction places SP1 into
the stack pointer SP (SP2=SP1).
The stack pointer is two bytes lower than before this sequence.
rw-0
5-4
CPU Registers
The assembler uses the constant generator automatically if one of the six
constants is used as a source operand in the immediate addressing mode.
The status register SR/R2, used as a source or destination register, can be
used in the register mode only. The remaining combinations of
addressing-mode bits are used to support absolute-address modes and bit
processing without any additional code. Registers R2 and R3, used in the
constant mode, cannot be addressed explicitly; they act like source-only
registers.
The RISC instruction set of the MSP430 has only 27 instructions. However, the
constant generator allows the MSP430 assembler to support 24 additional,
emulated instructions. For example, the single-operand instruction:
CLR dst
MOV R3,dst
or the equivalent
MOV #0,dst
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.
5-6
Addressing Modes
PC PCold PC PCold + 2
0108Ch
01094h 0xxxxh +0006h 01094h 0xxxxh
01092h
01092h 05555h 01092h 01234h
01090h 0xxxxh 01090h 0xxxxh
01080h
01084h 0xxxxh +0002h 01084h 0xxxxh
01082h
01082h 01234h 01082h 01234h
01080h 0xxxxh 01080h 0xxxxh
5-8
Addressing Modes
0FF14h
0F018h 0xxxxh +0F102h 0F018h 0xxxxh
0F016h
0F016h 0A123h 0F016h 0A123h
0F014h 0xxxxh 0F014h 0xxxxh
0FF16h
01116h 0xxxxh +011FEh 01116h 0xxxxh
01114h
01114h 01234h 01114h 0A123h
01112h 0xxxxh 01112h 0xxxxh
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).
5-10
Addressing Modes
Comment: Valid only for source operand. The substitute for destination
operand is 0(Rd).
Comment: Valid only for source operand. The substitute for destination
operand is 0(Rd) plus second instruction INCD Rd.
+1/ +2
5-12
Addressing Modes
0FF16h
010AAh 0xxxxh +01192h 010AAh 0xxxxh
010A8h
010A8h 01234h 010A8h 00045h
010A6h 0xxxxh 010A6h 0xxxxh
Table 5–13 shows a simple way to determine CPU instruction cycles for
Format–I (double operand) instructions.
5-14
Addressing Modes
Table 5–13 describes the CPU format II instructions and addressing modes.
Table 5–15 shows a simple way to determine CPU instruction cycles for
Format–II (single operand) instructions.
Instruction
SWPB
SXT
RRA
Addressing Mode RRC PUSH CALL
Rn 1 3 4
@Rn 3 4 4
@Rn+, #N 3 4 5
x(Rn), Symbolic, Absolute (&) 4 5 5
Example: the instruction PUSH #500h needs 4 cycles for the execution.
The source and destination parts of an instruction are defined by the following
fields:
5-16
Instruction Set Overview
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.
5-18
Instruction Set Overview
The instruction code fetch and the program counter increment technique end
with the formula:
The basic instruction set, together with the register implementations of the
program counter, stack pointer, status register, and constant generator, form
the emulated instruction set; these make up the popular instruction set. The
status bits are set according to the result of the execution of the basic
instruction that replaces the emulated instruction.
5-20
Instruction Set Overview
5.3.5 Miscellaneous
Instructions without operands, such as CPUOff, are not provided. Their
functions are switched on or off by setting or clearing the function bits in the
status register or the appropriate I/O register. Other functions are emulated
using dual operand instructions.
Format II
0Cx
10x RRC RRC.B SWPB RRA RRA.B SXT PUSH PUSH.B CALL RETI
14x
18x
1Cx
20x JNE/JNZ
24x JEQ/JZ
28x JNC
Format III
2Cx JC
30x JN
34x JGE
38x JL
3Cx JMP
4xxx MOV, MOV.B
5xxx ADD, ADD.B
6xxx ADDC, ADDC.B
7xxx SUBC, SUBC.B
8xxx SUB, SUB.B
Format I
9xxx CMP, CMP.B
Axxx DADD, DADD.B
Bxxx BIT, BIT.B
Cxxx BIC, BIC.B
Dxxx BIS, BIS.B
Exxx XOR, XOR.B
Fxxx AND, AND.B
5-22
Chapter 6
Hardware Multiplier
Topic Page
Figure 6–1. Connection of the Hardware Multiplier Module to the Bus System
ROM RAM
TDI
TDO
MAB, 16 Bit
CPU Test
Incl. 16 Reg. JTAG
MDB, 16 Bit
TMS
TCK
MPY
MPYS Other
Modules
MAC
MACS
6-2
Hardware Multiplier Operation
31 0
Product Register
Accessible Register
0000
32-Bit Adder
MACS
MPY MPYS MAC MPY, MPYS MAC, MACS
15 r 0 15 rw 0 15 rw 0
The sum extension register contents differ, depending on the operation and
on the results of the operation.
6.2.2 Multiply Signed, 16×16 bit, 16×8 bit, 8×16 bit, 8×8 bit
6-4
Hardware Multiplier Operation
6.2.3 Multiply Unsigned and Accumulate, 16×16 bit, 16×8 bit, 8×16 bit, 8×8 bit
The following is an example of unsigned multiply and accumulate:
Two registers are implemented for both operands, OP1 and OP2, as shown
in Figure 6–3. Operand 1 uses four different addresses to address the same
register. The different address information is decoded and defines the type of
multiplication operation used.
The multiplication result is located in two word registers: result high (RESHI)
and result low (RESLO). The sum extend register (SumExt) holds the result
sign of a signed operation or the overflow of the multiply and accumulate
(MAC) operation. See Section 6.5.3 for a description of overflow and
underflow when using the MACS operations.
All registers have the least significant bit (LSB) at bit0 and the most significant
bit (MSB) at bit7 (byte data) or bit15 (word data).
6-6
Hardware Multiplier Special Function Bits
**********************************************************
* EXAMPLE: MULTIPLY OPERAND1 AND OPERAND2
**********************************************************
PUSH R5 ; R5 WILL HOLD THE ADDRESS OF
MOV #RESLO,R5 ; THE RESLO REGISTER
MOV &OPER1,&MPY ; LOAD 1ST OPERAND,
; DEFINES ADD. UNSIGNED MULTIPLY
MOV &OPER2,&OP2 ; LOAD 2ND OPERAND AND START
; MULTIPLICATION
**********************************************************
* EXAMPLE TO ADD THE RESULT OF THE HARDWARE *
* MULTIPLICATION TO THE RAM DATA, 64BITS *
**********************************************************
NOP ; MIN. ONE CYCLES BETWEEN MOVING
; THE OPERAND2 TO HW–MULTIPLIER
; AND PROCESSING THE RESULT WITH
; INDIRECT ADDRESS MODE
ADD @R5+,&RAM ; ADD LOW RESULT TO RAM
ADDC @R5,&RAM+2 ; ADD HIGH RESULT TO RAM+2
ADC &RAM+4 ; ADD CARRY TO EXTENSION WORD
ADC &RAM+6 ; IF 64 BIT LENGTH IS USED
POP R5
1) Move operand OP1 to the hardware multiplier; this defines the type of mul-
tiplication.
The following considerations describe the main routines that use hardware
multiplication. If no hardware multiplication is used in the main routine,
multiplication in an interrupt routine is protected from further interrupts,
because the GIE bit is reset after entering the interrupt service routine.
Typically, a multiplication operation that uses the entire data process occurs
outside an interrupt routine and the interrupt routines are as short as possible.
The two LSBs of the first operand address define the type of multiplication
operation. This information cannot be recovered by any later operation.
Therefore an interrupt must not be accepted between the first two steps: move
operand OP1 and OP2 to the multiplier.
After the first two steps, the multiplication result is in the corresponding
registers RESLO, RESHI, and SUMEXT. It can be saved on the stack (using
the PUSH instruction) and can be restored after completing another
multiplication operation (using the POP instruction). However, this operation
takes additional code and cycles in the interrupt routine. You can avoid this,
by making an entire multiplication routine uninterruptible, by disabling any
interrupt (DINT) before entering the multiplication routine, and by enabling
interrupts (EINT) after the multiplication routine is completed. The negative
aspect of this method is that the critical interrupt latency is increased drastically
for events that occur during this period.
6-8
Hardware Multiplier Software Restrictions
This chapter discusses the FLL+ clock module used in the MSP430x4xx
families. The FLL+ clock module in the MSP430x4xx includes a watch-crystal
oscillator, a high-frequency crystal (or resonator) oscillator, an RC-type
digitally-controlled oscillator (DCO), and a frequency-locked-loop (FLL) to
ensure the accuracy of the DCO.
The FLL+ is an extended version of the FLL module in the MSP430x3xx family.
It supports a larger clock frequency range, and a watch crystal or high-
frequency crystal operation of the oscillator and oscillator fault detection.
Topic Page
7-2
FLL_DIV
f DCO+
DCOCLK = f crystal x D x (N+1)
1
fDCOCLK = fcrystal x (N+1)
0 SELS
0
455 kHz XT2IN DCOCLK 0
...8 MHz XT2 oscillator ¶ XT2CLK¶
SMCLK
1
XT2OUT Oscillator Fault 1
XT2Off § DCO Fault
DCOF SMCLKOFF
XTS_FLL OFIFG
† The clock source for MCLK is forced to DCOLCK if the selected clock source for MCLK fails. Failing includes the crystal oscillator has not started, or stopped working.
Note that if MCLK is automaticaly switched to DCLOCK because of a failure, the SELM bits will NOT change. They will retain their previous setting and should be reset
by doftware.
‡ OscOff bit switches off the LFXT1 oscillator only if the oscillator is unused by MCLK (SELM<>3 or CPUOff=1)
§ XT2Off bit switches off the XT2 oscillator only if it is unused by MCLK (SELM<>2 or CPUOff = 1) and SMCLK (SELS=0 or SMCLKOFF=1)
7-3
¶ The XT2 oscillator is implemented in the MSP430x43x and MSP430x44x devices. The LFxT1CLK signal is used in place of the XT2CLK signal on MSP430x41x devices.
LFXT1 Oscillator
Software can disable LFXT1 by setting OscOff, if this signal does not source
SMCLK or MCLK. The design of the LFXT1 oscillator (shown in Figure 7–2)
supports the low-current consumption feature and the use of a 32,768-Hz
watch crystal when in LF mode (XTS_FLL=0). A watch crystal connects to the
clock module via two terminals without any other external components.
Components necessary to stabilize the clock operation have been integrated
into the MSP430. The design of the LFXT1 oscillator also supports high-speed
crystals or resonators when in HF mode (XTS_FLL=1). The crystal or
resonator connects to the terminals and normally requires additional external
capacitors on both terminals. These capacitors (minus the internal ones)
should be sized according to crystal or resonator specifications.
Fault XT1OF
Detect LFOF
XTS_FLL
XOUT _FLL
MSP430
0V
32,768 Hz ∼0 pF, ∼10 pF, ∼14 pF, or ∼18 pF
or
450 kHz to 8 MHz
7-4
Digitally-Controlled Oscillator (DCO) and Frequency-Locked Loop
- Fast start-up. The MSP430x4xx DCO is active in less than 6 µs, which
supports extended sleep periods and burst performance.
- Digital control signals. The DCO starts at exactly the same setting as when
shutoff. Thus a long locking period is not required for normal operation.
User software can modify the DCO frequency used for MCLK/SMCLK by
changing the multipliers N and D plus DCO+ bit at any time. The exact
minimum and maximum frequency for MCLK/SMCLK is specified in the device
data sheet.
0
DCOCLK ’41x: to MCLK and SMCLK
7.3.1 FLL+Operation
As with any RC-type oscillator, frequency varies with temperature and voltage.
The FLL+ hardware automatically stabilizes MCLK/SMCLK. The FLL+
compares the ACLK to MCLK/(D×[N+1]) and counts up or down a 10-bit
frequency integrator. The MCLK/SMCLK is constantly adjusted to one of 1024
possible settings. The output of the frequency integrator that drives the DCO
can be read in SCFI1 and SCFI0. The count is adjusted +1 or –1 with each
crystal period (30.5 µs using 32,768 Hz). Of the 10-bits from the frequency
integrator, 5-bits are used for DCO frequency taps and 5-bits are used for a
modulator. The 5-bits for the DCO tap are contained in the SCFI1
(SCFI1.7 . . . SCFI11.3). There are 29 taps implemented in the DCO (TAPS
28, 29, 30, and 31 are equivalent), each being approximately 10% higher than
the previous. In most applications, a fraction tap may be required to achieve
the programmed MCLK/SMCLK over the full range of system operation (see
Figure 7–4).
DCO Output
Frequency Spectrum
Required Fractional Tap
31
24
16
15
2
Lower DCO Tap Frequency fn
Upper DCO Tap Frequency fn+1
1
7-8
Digitally-Controlled Oscillator (DCO) and Frequency-Locked Loop
The accumulated error in MCLK/SMCLK tends to zero over a long period. The
10-bit FLL+ integrator is automatically adjusted every period of the ACLK.
Thus, a positive frequency deviation over one ACLK period is compensated
with a negative deviation over the next ACLK period. Variation between
MCLK/SMCLK clock periods can be approximately 10% due to the modulator
mixing of DCO taps, while the accumulated system clock error over longer time
periods is zero.
Note:
MCLK/SMCLK is active even at the lowest DCO tap. The MCLK/SMCLK
signal is available for the CPU to execute code and service an NMI.
7-10
FLL+ Operating Modes
- Clock stability
on the stack and then clears the SCG1 bit in the SR, automatically starting the
DCO and MCLK/SMCLK. After the interrupt handler has completed, the saved
SR is popped from the stack with the RETI instruction, restoring the previous
operating mode.
ACLK/n
ACLK /1, /2, /4, /8 P1.5/TACLK/ACLK
FLL_DIV 0: /1
1: /2
2: /4
3: /8
7-12
FLL+ Module Control Registers
fSystem = D x (x⋅26 + x⋅25 + x⋅24 + x⋅23 + x⋅22 + x⋅21 + x⋅20 + 1) ⋅ fcrystal [DCO+=1]
The output of the frequency integrator controls the DCO. This value can be
read using the SCFI1 and SCFI0 addresses as shown in Figure 7–8.
If the modulation bit M is set, only the DCO taps determine the system
frequency. Adjacent DCO taps are not mixed. Note, however, that if the FLL+
remains active (SCG0=0), it will continue to adjust the DCO taps. If an
application requires the system frequency to remain constant for a short period
of time, both the modulation and the FLL+ should be disabled (M=1, SCG0=1).
NDCO
NOTE: DC0_Fault indicates that the upper (NDCO>0) and lower (NDCO = 0) limit of
the DCO frequency range is used.
Bits 0–3: The DCOF, LFOF, XT1OF, and XT2OF bits are used to signal an
oscillator fault. DCOF is used for the DCO, LFOF is ued for the
LFXT1 oscillator in LF mode, XT1OF is used for the LFXT1
oscillator in HF mode, and XT2OF is used for the XT2 oscillator.
The oscillator fault flag, OFIFG, is set if one or more of these fault
signals are set. These bits are read only and are set or reset
according to the fault condition.
0: No fault condition preset
1: Respective fault condition is preset
Note: The XT2OF bit is always read as 0 in MSP430x41x
devices because no XT2 oscillator is implemented on those
devices.
OscCap: The oscillator pins have internal capacitors that can be varied in
a small range. The capacitance at the pin can be varied from ~0
pF to ~18 pF. When combined with a typical capacitance value
of ~2 pF for the pin and circuit board, the effective crystal load
capacitance can be varied from ~1 pF to ~10 pF.
7-14
FLL+ Module Control Registers
0: LF mode is selected
1: HF mode is selected
DCO+: The DCO+ bit selects if the DCO output is predivided before
sourcing MCLK or SMCLK. The division rate, when used, is
selected with the FLL_DIV bits.
FLL DIV: The FLL_DIV bits select division rate of the LFXT1 frequency for
signal ACLK/n. Signal ACLK/n can be selected to be used at pin
P1.5/TACLK/ACLK.
SELS selects the clock source signal for peripheral module clock
0: SMCLK = DCOCLK
1: SMCLK = XT2CLK
SELM selects the clock source signal for MCLK, used by the
CPU
0,1: MCLK = DCOCLK
2: MCLK = XT2CLK
3: MCLK = ACLK (from LFXT1 oscillator)
IFG1 7 6 5 4 3 2 1 0
02h OFIFG
rw–1
The oscillator fault signal sets the OFIFG as long as the oscillator fault
condition is active. The detection and effect of the oscillator fault condition is
described in section 7.4. The oscillator fault interrupt requests a nonmaskable
interrupt if the OFIE bit is set. The oscillator interrupt-enable bit is reset
automatically if a non-maskable interrupt is accepted. The initial state of the
OFIE bit is reset, and no oscillator fault requests an interrupt even if a fault
condition occurs.
7-16
Chapter 8
Topic Page
8.1 Introduction
The general-purpose I/O ports of the MSP430 are designed to give maximum
flexibility. Each I/O line is individually configurable, and most have interrupt
capability.
There are two different types of I/O port modules in the MSP430x4xx family
devices. Ports P1 and P2 are of one type, and ports P3 to P6 are of another
type. Both types have the capability to control input/output direction and output
level, to read the level applied to a pin, and to control if a port or module function
is applied to a pin. The port module for P1 and P2 have interrupt capability; flag,
enable, and edge sensitivity are available individually for each bit.
See the device data sheet for the implementation of ports on a specific device.
8-2
Ports P1, P2
Seven registers are used to control the port I/O pins (see Section 8.2.1).
Ports P1 and P2 are connected to the processor core through the 8-bit MDB
and the MAB. They should be accessed using byte instructions in the absolute
address mode.
8
R 8
8
Input Register PnIN
R/W
8
n = 1: 020h
Output Register PnOUT
n = 2: 028h
R/W 8
n = 1: 021h Direction Register
n = 2: 029h PnDIR R/W
n = 1: 022h 8
n = 2: 02Ah Interrupt Flags PnIFG
R/W
n = 1: 023h Interrupt Edge Select 8
n = 2: 02Bh PnIES
R/W
n = 1: 024h
n = 2: 02Ch Interrupt Enable PnIE
R/W
n = 1: 025h
n = 2: 02Dh Function Select PnSEL
n = 1: 026h
n = 2: 02Eh
MSB LSB
Pn.7 Pn.0
Short Register
Register Form Type Address Initial State
Input P2IN Read only 028h –––––
Output P2OUT Read/write 029h Unchanged
Direction P2DIR Read/write 02Ah Reset
Interrupt flags P2IFG Read/write 02Bh Reset
Interrupt edge select P2IES Read/write 02Ch Unchanged
Interrupt enable P2IE Read/write 02Dh Reset
Function select P2SEL Read/write 02Eh Reset
These registers contain eight bits, and should be accessed using byte
instructions in absolute-address mode.
8-4
Ports P1, P2
Each output register shows the information of the output buffer. The output
buffer can be modified by all instructions that write to a destination. If read, the
contents of the output buffer are independent of pin direction. A direction
change does not modify the output buffer contents.
The direction registers contain eight independent bits that define the direction
of the I/O pin. All bits are reset by the PUC signal.
When:
Bit = 0: The port pin is switched to input direction (3-state)
Bit = 1: The port pin is switched to output direction
Each interrupt flag register contains eight flags that reflect whether or not an
interrupt is pending for the corresponding I/O pin, if the I/O is interrupt-enabled.
When:
Bit = 0: No interrupt is pending
Bit = 1: An interrupt is pending due to a transition at the I/O pin or from
software setting the bit.
Note:
Manipulating P1OUT and P1DIR, as well as P2OUT and P2DIR, can result
in setting the P1IFG or P2IFG bits.
Writing a zero to an interrupt flag resets it; writing a one to an interrupt flag sets
it and generates an interrupt.
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.
Each interrupt edge select register contains a bit for each corresponding I/O
pin to select what type of transition triggers the interrupt flag.
When:
Bit = 0: The interrupt flag is set with a low-to-high transition
Bit = 1: The interrupt flag is set with a high-to-low transition
Note:
Changing the P1IES and P2IES bits can result in setting the associated
interrupt flags.
Each interrupt enable register contains bits to enable the interrupt flag for each
I/O pin in the port. Each of the sixteen bits corresponding to pins P1.0 to P1.7
and P2.0 to P2.7 is located in the P1IE and P2IE registers.
When:
Bit = 0: The interrupt request is disabled
Bit = 1: The interrupt request is enabled
P1 and P2 port pins are often multiplexed with other peripheral modules to
reduce overall pin count on MSP430 devices (see the specific device data
sheet to determine which other peripherals also use the device pins). Control
registers P1SEL and P2SEL are used to select the desired pin function—I/O
port or other peripheral module. Each register contains eight bits
corresponding to each pin, and each pin’s function is individually selectable.
All bits in these registers are reset by the PUC signal. The bit definitions are:
Bit = 0: Port P1 or P2 function is selected for the pin
Bit = 1: Other peripheral module function is selected for the pin
8-6
Ports P1, P2
The pin logic of each individual port P1 and port P2 signal is identical. Each
bit can be read and written to as shown in Figure 8–2.
PnSEL.x
PnDIR.x Output
Direction Control MUX
From Module
Pad Logic
PnOUT.x Pn.x
Output
Module X OUT MUX
PnIN.x
EN
Module x IN Y
A
PnIRQ.x PnIE.x
Interrupt
Interrupt
Edge
PnIFG.x Flag
Select
PnIRQ.y
PnIES.x
Request PnSEL.x
Interrupt
Pn.07 PnIRQ.z
x = 0 to 7, according to bits 0 to 7
n = 1 for Port P1 and 2 for Port P2
The interrupt flags P1IFG.0 to P1IFG.7 source one interrupt and P2IFG.0 to
P2IFG.7 source one interrupt. Any interrupt event on one or more pins of P1.0
to P1.7 or P2.0 to P2.7 requests an interrupt when two conditions are met: the
appropriate individual bit PnIE.x is set, and the GIE bit is set. Interrupt flags
P1IFG.0 to P1IFG.7 or P2IFG.0 to P2IFG.7 are not automatically reset. The
software of the interrupt service routine should handle the detection of the
source, and reset the appropriate flag when it is serviced.
8-8
Ports P3, P4, P5, P6
Ports P3–P6 are connected to the processor core through the 8-bit MDB and
the MAB. They should be accessed with byte instructions using the absolute
address mode.
8
R 8
8
Input Register PnIN
R/W
8
n = 3: 018h
Output Register PnOUT
n = 4: 01Ch
n = 5: 030h R/W
n = 3: 019h Direction Register
n = 6: 034h
n = 4: 01Dh PnDIR
n = 5: 031h R/W
n = 3: 01Ah Function Select
n = 6: 035h n = 4: 01Eh Register PnSEL
n = 5: 032h
n = 6: 036h n = 3: 01Bh
n = 4: 01Fh
n = 5: 033h
n = 6: 037h
MSB LSB
Pn.7 Pn.0
The four registers for each port are shown in Table 8–3. They each contain
eight bits and should be accessed with byte instructions.
The input registers are read-only registers that reflect the signal at the I/O pins.
The output registers show the information of the output buffers. The output
buffers can be modified by all instructions that write to a destination. If read,
the contents of the output buffer are independent of the pin direction. A
direction change does not modify the output buffer contents.
The direction registers contain eight independent bits that define the direction
of each I/O pin. All bits are reset by the PUC signal.
When:
Bit = 0: The port pin is switched to input direction.
Bit = 1: The port pin is switched to output direction.
8-10
Ports P3, P4, P5, P6
Ports P3–P6 pins are often multiplexed with other peripheral modules to
reduce overall pin count on MSP430 devices (see the specific device data
sheet to determine which other peripherals also use the device pins). Control
registers PnSEL are used to select the desired pin function—I/O port or other
peripheral module. Each register contains eight bits corresponding to each
pin, and each pin’s function is individually selectable. All bits in these registers
are reset by the PUC signal. The bit definitions are:
The pin logic of each individual port signal is shown in Figure 8–4.
PnIN.x
EN
Module x IN Y
A
n = 3 for Port3, 4 for Port P4, 5 for Port P5, and 6 for Port P6
x = 0 to 7, according to bits 0 to 7
Watchdog Timer
Topic Page
SMCLK 1
HOLD
ACLK 1 NMIES
NMI
A EN
TMSEL
CNTCL
SSEL PUC
IS1
LSB
IS0
Watchdog Timer
Control Register
9-2
The Watchdog Timer
WDTCTL
HOLD NMIES NMI TMSEL CNTCL SSEL IS1 IS0
0120h
rw–0 rw–0 rw–0 rw–0 r0(w) rw–0 rw–0 rw–0
WDTCTL 069h
read
WDTCTL
05Ah
write
Bits 0, 1: Bits IS0 and IS1 select one of four taps from the WDTCNT, as
described in Table 9–1. Assuming fcrystal = 32,768 Hz and
fSMCLK = 1 MHz, the following intervals are possible:
Bit 2: The SSEL bit selects the clock source for WDTCNT.
SSEL = 0: WDTCNT is clocked by SMCLK .
SSEL = 1: WDTCNT is clocked by ACLK.
Bit 3: Counter clear bit. In both operating modes, writing a 1 to this bit
restarts the WDTCNT at 00000h. The value read is not defined.
Bit 4: The TMSEL bit selects the operating mode: watchdog or timer.
TMSEL = 0: Watchdog mode
TMSEL = 1: Interval-timer mode
Bit 5: The NMI bit selects the function of the RST/NMI input pin. It is
cleared by the PUC signal.
NMI = 0: The RST/NMI input works as reset input.
As long as the RST/NMI pin is held low, the internal
signal is active (level sensitive).
NMI = 1: The RST/NMI input works as an edge-sensitive non-
maskable interrupt input.
Bit 6: If the NMI function is selected, this bit selects the activating edge
of the RST/NMI input. It is cleared by the PUC signal.
NMIES = 0: A rising edge triggers an NMI interrupt.
NMIES = 1: A falling edge triggers an NMI interrupt.
CAUTION: Changing the NMIES bit with software can generate
an NMI interrupt.
Bit 7: This bit stops the operation of the watchdog counter. The clock
multiplexer is disabled and the counter stops incrementing. It holds
the last value until the hold bit is reset and the operation continues.
It is cleared by the PUC signal.
HOLD = 0: The WDT is fully active.
HOLD = 1: The clock multiplexer and counter are stopped.
The WDTCTL register can be read or written to. As illustrated in Figure 9–3,
WDTCTL can be read without the use of a password. A read access is
performed by accessing word address 0120h. The low byte contains the value
of WDTCTL. The value of the high byte is always read as 069h.
Write access to WDTCTL, illustrated in Figure 9–4, is only possible using the
correct high-byte password. To change register WDTCTL, write to word
address 0120h. The low byte contains the data to write to WDTCTL. The high
byte is the password, which is 05Ah. A system reset (PUC) is generated if any
value other than 05Ah is written to the high byte of address 0120h.
9-4
The Watchdog Timer
When using the watchdog mode, the WDTIFG flag is 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 the flag is cleared, then
the PUC was caused by a different source. See Chapter 3 for more details on
the PUC and POR signals.
When using the Watchdog Timer in interval-timer mode, the WDTIFG flag is
set after the selected time interval and a watchdog interval-timer interrupt is
requested. The interrupt vector address in interval-timer mode is different from
that in watchdog mode. In interval-timer mode, the WDTIFG flag is reset
automatically when the interrupt is serviced.
The WDTIE bit is used to enable or disable the interrupt from the Watchdog
Timer when it is being used in interval-timer mode. Also, the GIE bit enables
or disables the interrupt from the Watchdog Timer when it is being used in
interval-timer mode.
When the module is used in watchdog mode, the software should periodically
reset the WDTCNT by writing a 1 to bit CNTCL of WDTCTL to prevent
expiration of the selected time interval. If a software problem occurs and the
time interval expires because the counter is no longer being reset, a system
reset is generated and a system PUC signal is activated. The system restarts
at the same program address that follows a power up. The cause of reset can
be determined by testing bit 0 of interrupt flag register 1 in the SFRs. The
appropriate time interval is selected by setting bits SSEL, IS0, and IS1
accordingly.
Setting WDTCTL register bit TMSEL to 1 selects the timer mode. This mode
provides periodic interrupts at the selected time interval. A time interval can
also be initiated by writing a 1 to bit CNTCL in the WDTCTL register.
When the WDT is configured to operate in timer mode, the WDTIFG flag is set
after the selected time interval, and it requests a standard interrupt service.
The WDT interrupt flag is a single-source interrupt flag and is automatically
reset when it is serviced. The enable bit remains unchanged. In interval-timer
mode, the WDT interrupt-enable bit and the GIE bit must be set to allow the
WDT to request an interrupt. The interrupt vector address in timer mode is
different from that in watchdog mode.
The MSP430 devices have several low-power modes. Different clock signals
are available in different low-power modes. The requirements of the user’s
application and the type of clocking circuit on the MSP430 device determine
how the Watchdog Timer and clocking signals should be configured. Review
the device data sheet and clock-system chapter to determine the clocking
circuit, clock signals, and low-power modes available. For example, the WDT
should not be configured in watchdog mode with SMCLK as its clock source
if the user wants to use low-power mode 3 because SMCLK is not active in
LPM3, therefore the WDT would not function properly.
The WDT hold condition can also be used to support low power operation. The
hold condition can be used in conjunction with low-power modes when
needed.
9-6
The Watchdog Timer
Basic Timer1
Topic Page
Control Register
BTCTL
SSEL DIV 1 0 2 1 0
Hold FRFQ IP IP IP
DIV
Hold EN1
BTCNT1
ACLK CLK1
Q4 Q5 Q6 Q7
FRFQ1
FRFQ0
0 1 2 3
SSEL DIV fLCD
0
1 Hold EN2
ACLK:256 BTCNT2
2 CLK2
SMCLK Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7
3
IP2
IP1
IP0 Set Interrupt
0 1 2 3 4 5 6 7 Flag BTIFG
10-2
Basic Timer1
Note: The user’s software should configure these registers at power-up, as there is no defined
initial state.
The information stored in the control register determines the operation of Basic
Timer1. The state of the different bits selects the frequency source, the
interrupt frequency, and the framing frequency of the LCD control circuitry as
shown in Figure 10–2.
Bits 0 to 2:The three least-significant bits IP2 to IP0 determine the interrupt
interval time. It is the interval of consecutive settings of the
interrupt-request flag BTIFG, as illustrated in Figure 10–3.
Bits 3 to 4:The two bits FRFQ1 and FRFQ0 select the frequency fLCD as
described in Figure 10–3. Devices with the LCD peripheral on the
chip use this frequency to generate the timing of the common and
select lines.
Bit 7: The SSEL and DIV bits select the frequency source for BTCNT2,
as described in Table 10–2.
0 0 fLCD = fACLK/32
0 1 fLCD = fACL/64
1 0 fLCD = fACLK/128
1 1 fLCD = fACLK/256
The Basic Timer1 counter BTCNT1, shown in Figure 10–4 divides the auxiliary
clock ACLK. The frame frequency for the LCD-drive is selected from four
outputs of the counter’s bits. The output of the most significant bit can be used
for the clock input to the second counter BTCNT2. The value of bits Q0 to Q7
can be read, and the software can write to bits Q0 to Q7.
10-4
Basic Timer1
The Basic Timer1 counter BTCNT2, shown in Figure 10–5, divides the input-
clock frequency. The input-clock source can be SMCLK, ACLK, or ACLK/256.
The interrupt period can be selected using IP0 to IP2, located in the Basic
Timer1 control register BTCTL. It selects one of the eight bits of BTCNT2 as
the source signal to set the Basic Timer1 interrupt flag BTIFG. The value of the
counter bits can be read, as well as written.
The BTIFG flag indicates that a Basic Timer1 interrupt is pending and is reset
automatically when the interrupt is accepted.
The BTIE bit enables or disables the interrupt from the Basic Timer1 and is
reset with a PUC. The Basic Timer1 interrupt is also enabled or disabled with
the general interrupt enable bit, GIE.
The hold bit inhibits all functions of the module and reduces power
consumption. The Basic Timer1 registers may be accessed at any time,
regardless of the state of the hold bit.
One of the eight counter outputs can be selected to set the Basic Timer1
interrupt flag. Read and write access can be asynchronous when ACLK or
ACLK/256 is selected.
The 16-bit timer/counter mode is selected when control bit DIV is set. In this
mode, the clock source of counters BTCNT1 and BTCNT2 is the ACLK signal.
See the Liquid Crystal Display Drive chapter for more details on the LCD driver.
10-6
Chapter 11
Timer_A
Note:
Throughout this chapter, the word count is used in the text. As used in these
instances, it refers to the literal act of counting. It means that 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 the associated action will not take place.
For example, the CCR0 interrupt flag is set when the timer counts up to the
value in CCR0. The counter must count from CCR0–1 to CCR0. If the CCR0
value were simply written directly to the timer with software, the interrupt flag
would not be set, even though the values in the timer and the CCR0 registers
are the same.
Topic Page
Timer_A 11-1
Introduction
11.1 Introduction
Timer_A is an extremely versatile timer made up of :
- 16-bit counter with 4 operating modes
0 15 0
TACLK
1 16-Bit Timer
ACLK Input Mode
2 Divider CLK Control
SMCLK RC Equ0
3 1
INCLK
ID1 ID0 Carry/Zero Set_TAIFG
POR/CLR MC1 MC0
Timer Bus
11-2
Timer_A Operation
15 0
Timer Clock 16-Bit Timer Mode
CLK
RC Control Equ0
Carry/Zero Set_TAIFG
MC1 MC0
POR
0 0 Stop Mode
0 1 Up Mode
1 0 Continuous Mode
1 1 Up/Down Mode
Mode Control
MC1 MC0 Mode Description
0 0 Stop The timer is halted.
0 1 Up The timer counts upward until value is equal to
value of compare register CCR0.
1 0 Continuous The timer counts upward continuously.
1 1 Up/Down The timer counts up until the timer value is
equal to compare register 0 and then it counts
down to zero.
Timer_A 11-3
Timer_A Operation
The selected clock source may be passed directly to the timer or divided by
2,4, or 8, as shown in Figure 11–4. The ID0 and ID1 bits in the TACTL register
select the clock division. Note that the input divider is reset by a POR signal
(see chapter 3, System Resets, Interrupts, and Operating Modes for more
information on the POR signal) or by setting the CLR bit in the TACTL register.
Otherwise, the input divider remains unchanged when the timer is modified.
The state of the input divider is invisible to software.
0 0 15
TACLK
Input 16-Bit Timer Mode
1 CLK
ACLK Divider RC Control Equ0
SMCLK 2
ID1 ID0 Carry/Zero Set_TAIFG
MC1 MC0
POR/CLR
3 0 0 Pass 0 0 Stop Mode
INCLK
0 1 1/2 0 1 Up Mode
1 0 1/4 1 0 Continuous Mode
1 1 1/8 1 1 Up/Down Mode
INCLK 3
POR CLR
ID1 ID0
0 0 Pass
0 1 1/2
1 0 1/4
1 1 1/8
11-4
Timer Modes
- Release Halt Mode: The timer counts in the selected direction when a
timer mode other than stop mode is selected with the MCx bits.
- Setting the CLR bit in TACTL register: Setting the CLR bit in the TACTL
register clears the timer value and input clock divider value. The timer
increments upward from zero with the next clock cycle as long as
stop-mode is not selected with the MCx bits.
- TAR is loaded with 0: When the counter (TAR register) is loaded with zero
with a software instruction the timer increments upward from zero with the
next clock cycle as long as stop-mode is not selected with the MCx bits.
Stopping and starting the timer is done simply by changing the mode control
bits (MCx). The value of the timer is not affected.
When the timer is stopped from up/down mode and then restarted in up/down
mode, the timer counts in the same direction as it was counting before it was
stopped. For example, if the timer is in up/down mode and counting in the down
direction when the MCx bits are reset, when they are set back to the up/down
direction, the timer starts counting in the down direction from its previous
value. If this is not desired in an application, the CLR bit in the TACTL register
can be used to clear this direction memory feature.
The up mode is used if the timer period must be different from the 65,536
(16-bit) clock cycles of the continuous mode period. The capture/compare
register CCR0 data define the timer period.
Timer_A 11-5
Timer Modes
CCR0
0h
Flag CCIFG0 is set when the timer equals the CCR0 value. The TAIFG flag is
set when the timer counts from CCR0 to zero. All interrupt flags are set
independently of the corresponding interrupt enable bit, but an interrupt is
requested only if the corresponding interrupt enable bit and the GIE bit are set.
Figure 11–6 shows the flag set cycle.
Set Flag
TAIFG
Set Flag
CCIFG0
Changing the timer period register CCR0 while the timer is running can be a
little tricky. When the new period is greater than or equal to the old period, the
timer simply counts up to the new period and no special attention is required
(see Figure 11–7). However, when the new period is less than the old period,
the phase of the timer clock during the CCR0 update affects how the timer
reacts to the new period.
If the new, smaller period is written to CCR0 during a high phase of the timer
clock, then the timer rolls to zero (or begins counting down when in the
up/down mode) on the next rising edge of the timer clock. However, if the new,
smaller period is written during a low phase of the timer clock, then the timer
continues to increment with the old period for one more clock cycle before
adopting the new period and rolling to zero (or beginning counting down). This
is shown in Figure 11–8.
11-6
Timer Modes
ÏÏÏÏÏ
ÏÏÏÏÏ
0 1 2 0 1 2 3 0 1 2 3 0 1
CCR0 2 3
0 1 2 3 4 5 01 2 3 01 2 01 2 01 0 1 2 3 4 5 0 1 2 3 40 1 2 0 1 20 1
CCR0 5 2 CCR0 5 2
CCR0 Loaded With 2 During High Clock Phase CCR0 Loaded With 2 During Low Clock Phase
Timer_A 11-7
Timer Modes
The capture/compare registers and different output modes of each output unit
are useful to capture timer data based on external events or to generate
various different types of output signals. Examples of the different output
modes used with timer-continuous mode are shown in Figure 11–25.
In continuous mode, the timer starts counting from its present value. The
counter counts up to 0FFFFh and restarts by counting from zero as shown in
Figure 11–9.
0FFFFh
0h
The TAIFG flag is set when the timer counts from 0FFFFh to zero. The interrupt
flag is set independently of the corresponding interrupt enable bit, as shown
in Figure 11–10. An interrupt is requested if the corresponding interrupt enable
bit and the GIE bit are set.
Set Interrupt
Flag TAIFG
11-8
Timer Modes
The continuous mode can be used to generate time intervals for the
application software. Each time an interval is completed, an interrupt can be
generated. In the interrupt service routine of this event, the time until the next
event is added to capture/compare register CCRx as shown in Figure 11–11.
Up to five independent time events can be generated using all five
capture/compare blocks.
Interrupt Events ∆t ∆t ∆t ∆t ∆t ∆t ∆t ∆t ∆t ∆t ∆t ∆t
Time intervals can be produced with other modes as well, where CCR0 is used
as the period register. Their handling is more complex since the sum of the old
CCRx data and the new period can be higher than the CCR0 value. When the
sum CCRxold plus ∆t is greater than the CCR0 data, the CCR0 value must be
subtracted to obtain the correct time interval. The period is twice the value in
the CCR0 register.
0h
Timer_A 11-9
Timer Modes
The up/down mode also supports applications that require dead times
between output signals. For example, to avoid overload conditions, two
outputs driving an H-bridge must never be in a high state simultaneously. In
the following example (see Figure 11–13), the tdead is:
CCR1
CCR2
0h
Dead Time
The count direction is always latched with a flip-flop (Figure 11–14). This is
useful because it allows the user to stop the timer and then restart it in the same
direction it was counting before it was stopped. For example, if the timer was
counting down when the MCx bits were reset, then it will continue counting in
the down direction if it is restarted in up/down mode. If this is not desired, the
CLR bit in the TACTL register must be used to clear the direction. Note that the
CLR bit affects other setup conditions of the timer. Refer to Section 11.6 for a
discussion of the Timer_A registers.
11-10
Timer Modes
In up/down mode, the interrupt flags (CCIFG0 and TAIFG) are set at equal time
intervals (Figure 11–15). Each flag is set only once during the period, but they
are separated by 1/2 the timer period. CCIFG0 is set when the timer counts
from CCR0–1 to CCR0, and TAIFG is set when the timer completes counting
down from 0001h to 0000h. Each flag is capable of producing a CPU interrupt
when enabled.
Up/Down
Set
CCIFG0
Set
TAIFG
11.3.4.1 Timer In Up/Down Mode – Changing the Value of Period Register CCR0
Changing the period value while the timer is running in up/down mode is even
trickier than in up mode. As in up mode, the phase of the timer clock when
CCR0 is changed affects the timer’s behavior. Additionally, in up/down mode,
the direction of the timer also affects the behavior.
If the timer is counting in the up direction when the new period is written to
CCR0, the conditions in the up/down mode are identical to those in the up
mode. See Section 11.3.2.1 for details. However, if the timer is counting in the
down direction when CCR0 is updated, it continues its descent until it reaches
zero. The new period takes effect only after the counter finishes counting down
to zero. See Figure 11–16.
5
4
3
2
1
0
0 1 2 3 4 5 4 3 2 1 0 1 2 34 3 2 1 0 1 2 3 21 0 1 2 1 0 1 2 3 4 5 4 3 2 1 0 1 2 1
CCR0 5 2 4 2 5 2
Timer_A 11-11
Timer Modes
Both the interrupt enable bit CCIEx and the interrupt flag CCIFGx are used for
capture and compare modes. CCIEx enables the corresponding interrupt.
CCIFGx is set on a capture or compare event.
The capture inputs CCIxA and CCIxB are connected to external pins or internal
signals. Different MSP430 devices may have different signals connected to
CCIxA and CCIxB. The data sheet should always be consulted to determine
the Timer_A connections for a particular device.
EN
Y SCCIx
A
CCIx
11-12
Timer Modes
If a capture is performed:
- An interrupt is requested if both interrupt enable bits CCIEx and GIE are
set.
The input signal to the capture/compare block is selected using control bits
CCISx1 and CCISx0, as shown in Figure 11–18. The input signal can be read
at any time by the software by reading bit CCIx. The input signal may also be
latched with compare signal EQUx (see SCCIx bit below) when in compare
mode. This feature was designed specifically to support implementing serial
communications with Timer_A. See section 11.6, Timer_A UART, for more
details on using Timer_A as a UART.
CCIx
The capture signal can also be synchronized with the timer clock to avoid race
conditions between the timer data and the capture signal. This is illustrated in
Figure 11–19. The bit SCSx in capture/compare control register CCTLx
selects the capture signal synchronization.
Timer_A 11-13
Timer Modes
n-2 n-1
ÎÎÎ
Timer n n+1 n+2 n+3 n+4 n+5 n+6
CCIx
Capture
ÎÎÎ
Set
CCIFGx
Applications with slow timer clocks can use the nonsynchronized capture
signal. In this scenario the software can validate the data and correct it if
necessary as shown in the following example:
; Software example for the handling of asynchronous
; capture signals
;
; The data of the capture/compare register CCRx are taken
; by the software in the according interrupt routine
; – they are taken only after a CCIFG was set.
; The timer clock is much slower than the system clock
; SMCLK.
;
CCRx_Int_hand ... ; Start of interrupt
; handler
...
...
CMP &CCRx,&TAR ; Test if the data
; CCRX = TAR
JEQ Data_Valid
MOV &TAR,&CCRx ; The data in CCRx is
; wrong, use the timer data
Data_Valid ... ... ; The data in CCRx are valid
...
...
RETI
;
Overflow logic is provided with each capture/compare register to flag the user
if a second capture is performed before data from the first capture was read
successfully. Bit COVx in register CCTLx is set when this occurs as shown in
Figure 11–20.
11-14
Timer Modes
No Read
Capture
Capture Taken
Taken
Taken Capture
Capture
Capture
Clear Bit COV
in Register CCTL
Second
Capture Idle
Taken
COV = 1
...
...
; RETI
Timer_A 11-15
Timer Modes
Two bits, CCISx1 and CCISx0, and the capture mode selected by bits CCMx1
and CCMx0 are used by the software to initiate the capture. The simplest
realization is when the capture mode is selected to capture on both edges of
CCIx and bit CCISx1 is set. Software then toggles bit CCISx0 to switch the
capture signal between VCC and GND, initiating a capture each time the input
is toggled, as shown in Figure 11–21.
CCISx0
CCIx
Capture
CCISx1 CCISx0
CMPx
0
CCIxA
1
CCIxB Capture
2 Capture
GND Mode
3
VCC
CCIx
CCMx1 CCMx0
Both Edges Selected 1 1
11-16
Timer Modes
The compare mode is most often used to generate interrupts at specific time
intervals or used in conjunction with the output unit to generate output signals
such as PWM signals. If the timer becomes equal to the value in compare
register x, then:
- Interrupt flag CCIFGx, located in control word CCTLx, is set.
- An interrupt is requested if interrupt enable bits CCIEx and GIE are set.
- Signal EQUx is output to the output unit. This signal affects the output
OUTx, depending on the selected output mode.
The EQU0 signal is true when the timer value is greater or equal to the CCR0
value. The EQU1 to EQU2 signals are true when the timer value is equal to
the corresponding CCR1 to CCR2 values.
OUTx Signal
Set
Output D Q
EQU0 Control
EQUx Timer Clock
Block Reset
POR
OUTx
OMx2 OMx1 OMx0
0 0 0 Output mode: OUTx signal reflects the value of the OUTx bit
0 0 1 Set mode: OUT x signal reflects the value of signal EQUx
0 1 0 PWM toggle/reset: EQUx toggles OUTx. EQU0 resets OUTx.
0 1 1 PWM set/reset: EQUx sets OUTx. EQU0 resets OUTx
1 0 0 Toggle: EQUx toggles OUTx signal.
1 0 1 Reset: EQUx resets OUTx.
1 1 0 PWM toggle/set: EQUx toggles OUTx. EQU0 sets OUTx.
1 1 1 PWM reset/set: EQUx resets OUTx. EQU0 sets OUTx.
Note: OUTx signal updates with rising edge of timer clock for all modes except
mode 0.
Modes 2, 3, 6, 7 not useful for output unit 0.
Timer_A 11-17
Timer Modes
11-18
Timer Modes
OUTx Signal
Set
Output D Q
EQU0 Control
EQUx Timer Clock
Block Reset
POR
OUTx
OMx2 OMx1 OMx0
The timer is Incremented with the rising edge of the timer clock.
Timer
Clock
Timer
n–2 n–1 n n+1 FFFF or CCR0 0 1
TAR
TAR = n
EQUx
CCRx = n
EQU0 TAR = 0
or
TAR = CCR0
EQU0, Delayed
Used in Up Mode Only
EQU0 delayed is used in up mode, not EQU0. EQU0 is active high when
TAR = CCR0. EQU0 delayed is active high when TAR = 0.
Timer_A 11-19
Timer Modes
The OUTx signal is changed when the timer counts up to the CCRx value, and
rolls from CCR0 to zero, depending on the output mode, as shown in
Figure 11–24.
11-20
Timer Modes
CCR1
0h
The OUTx signal is changed when the timer reaches the CCRx and CCR0
values, depending on the output mode, as shown in Figure 11–25.
CCR1
0h
Timer_A 11-21
Timer_A Registers
The OUTx signal changes when the timer equals CCRx in either count
direction and when the timer equals CCR0, depending on the output mode, as
shown in Figure 11–26.
CCR2
0h
11-22
Timer_A Registers
Bit 1: Timer overflow interrupt enable (TAIE) bit. An interrupt request from
the timer overflow bit is enabled if this bit is set, and is disabled if
reset.
Bit 2: Timer clear (CLR) bit. The timer and input divider are reset with the
POR signal, or if bit CLR is set. The CLR bit is automatically reset
and is always read as zero. The timer starts in the upward direction
with the next valid clock edge, unless halted by cleared mode
control bits.
Bits 4, 5: Mode control: Table 11–4 describes the mode control bits.
Timer_A 11-23
Timer_A Registers
Bits 6, 7: Input divider control bits. Table 11–5 describes the input divider
control bits.
Bits 8, 9: Clock source selection bits. Table 11–6 describes the clock source
selections.
11-24
Timer_A Registers
Timer_A 11-25
Timer_A Registers
Bit 2: The OUTx bit determines the value of the OUTx signal if the
output mode is 0.
11-26
Timer_A Registers
Timer_A 11-27
Timer_A Registers
2) Capture
For example:
BIS #CAP,&CCTL2 ; Select capture with register CCR2
XOR #CCIS1,&CCTL2 ; Software capture: CCIS0 = 0
; Capture mode = 3
11-28
Timer_A Registers
The CCIFGx (other than CCIFG0) and TAIFG interrupt flags are prioritized and
combined to source a single interrupt as shown in Figure 11–31. The interrupt
vector register TAIV (shown in Figure 11–32) is used to determine which flag
requested an interrupt.
IRACC Interrupt_Service_Request
S CCIFG2
CCI2
EQ2 S
Priority and
CMP2 Sel CCIE2 Vector Word
Timer Clock R Generator
IRACC
Interrupt_Vector_Address
S TAIFG
Timer FFFF
Timer = CCR0 S
XXX Sel TAIE
Timer Clock R
IRACC
The flag with the highest priority generates a number from 2 to 12 in the TAIV
register as shown in Table 11–9. (If the value of the TAIV register is 0, no
interrupt is pending.) This number can be added to the program counter to
automatically enter the appropriate software routine without the need for
reading and evaluating the interrupt vector. The software example in Section
11.5.4.3 shows this technique.
Timer_A 11-29
Timer_A Registers
Accessing the TAIV register automatically resets the highest pending interrupt
flag. If another interrupt flag is set, then another interrupt will be immediately
generated after servicing the initial interrupt. For example, if both CCIFG1 and
CCIFG2 are set, when the interrupt service routine accesses the TAIV register
(either by reading it or by adding it directly to the PC), CCIFG1 will be reset
automatically. After the RETI instruction of the interrupt service routine is
executed, the CCIFG2 flag will generate another interrupt.
11-30
Timer_A Registers
If the FLL is turned off, then two additional cycles need to be added for a
synchronous start of the CPU and system clock MCLK.
With the TAIV register and the previous software, the shortest repetitive time
distance tCRmin between two events using a compare register is:
With: ttaskmax Maximum (worst case) time to perform the task during the
interrupt routine (for example, incrementing a counter)
The shortest repetitive time distance tCLmin between two events using a
capture register is:
Timer_A 11-31
Timer_A UART
- Full-duplex operation
The transmit feature uses one compare function to shift data through the
output unit to the selected pin. The baud rate is ensured by reconfiguring the
compare data with each interrupt.
The receive feature uses one capture/compare function to shift pin data into
memory through bit SCCIx. The receive start time is recognized by capturing
the timer data with the negative edge of the input signal. The same
capture/compare block is then switched to compare mode and the receive bits
are latched automatically with the EQUx signal. The interrupt routine collects
the bits for later software processing. Figure 11–33 illustrates the UART
implementation.
11-32
Timer_A UART
Logic COVx
CCISx1 CCISx0 Timer Bus
CAPx
0 15 0
CCIxA
1
CCIxB Capture Capture/Compare Register
2 Mode CCRx
GND
3 Capture
VCC
CCMx1 CCMx0
0 0 Disabled
0 1 Positive Edge Comparator x
1 0 Negative Edge
1 1 Both Edges
CAPx
EQUx 0
1
Set_CCIFGx
Receive Data Path
EN
Y SCCIx
A
CCIx
OUTx Signal
Set
D Q
0 0 1 Set, EQUx set OUTx signal clock synchronized with timer clock
1 0 1 Reset, EQUx resets OUTx signal clock synchronized with
timer clock
Timer_A 11-33
Timer_A UART
URXD Signal
Capture
Compare
Receive
Capture Compare Compare Compare
Compare Compare Compare Compare
UTXD Signal
Transmit
Compare Compare Compare Compare
Compare Compare Compare Compare
11-34
Chapter 12
Timer_B
Note:
Throughout this chapter, the word count is used in the text. As used in these
instances, it refers to the literal act of counting. It means that 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 the associated action will not take place.
For example, the TBCCR0 interrupt flag is set when the timer counts up to
the value in TBCCR0 compare latch TBCL0. The counter must count from
TBCL0 –1 to TBCL0. If the TBCL0 value were simply written directly to the
timer with software, the interrupt flag would not be set, even though the val-
ues in the timer and TBCL0 would be the same.
Topic Page
Timer_B 12-1
Introduction
12.1 Introduction
Timer_B is an extremely versatile timer made up of :
- 16-bit counter with 4 operating modes and four selectable lengths (8-bit,
10-bit, 12-bit, or 16-bit)
On Timer_A, the capture/compare register CCRx holds the data for the
comparison to the timer value. On Timer_B, each TBCCRx acts as a buffer for
a compare latch, and the compare latch holds the data used for the
comparison. So, compare data is written to each capture/compare register in
both timers; however, in Timer_B, the compare data is then transferred to the
compare latch for the comparison. The timing of the transfer of the compare
12-2
Introduction
data from each TBCCRx register to the corresponding compare latch (TBCLx)
is user-selectable to be either immediate, or on a timer event. See section
12.4.2.1 for a complete discussion on using and configuring the compare
latches.
The addition of the compare latch gives the user more control over when
exactly a compare period updates. In addition, multiple compare latches may
be grouped together allowing the compare period of multiple compare
registers to be updated simultaneously. This is useful, for example, when there
is a need to change the period or duty cycle of multiple PWM signals
simultaneously.
Timer_B 12-3
Introduction
Module 2
Module 3
Module 4
Module 5
12-4
Timer_B Operation
Ti
Timer_B
BCConfiguration
fi ti TBR(max)
16-bit 0FFFFh
12-bit 0FFFh
10-bit 03FFh
8-bit 0FFh
15 0
Timer Clock 16-Bit Timer† Mode
CLK
RC Control Equ0
Carry/Zero Set_TBIFG
MC1 MC0
POR
0 0 Stop Mode
0 1 Up Mode
1 0 Continuous Mode
1 1 Up/Down Mode
† Length is selectable for 8-, 10-, 12-, or 16-bit operation.
Timer_B 12-5
Timer_B Operation
Mode Control
MC1 MC0 Mode Description
0 0 Stop The timer is halted.
0 1 Up The timer counts upward until its value is equal to
the value of compare latch TBCL0.
Note: If TBCL0 > TBR(max), the counter counts to
zero with the next rising edge of timer clock.
1 0 Continuous The timer counts upward continuously.
The maximum value of TBR [TBR(max)] is:
0FFFFh for 16-bit configuration
00FFFh for 12-bit configuration
003FFh for 10-bit configuration
000FFh for 8-bit configuration
1 1 Up/Down The timer counts up until the timer value is equal
to compare latch 0 and then it counts down to zero.
Note: If TBCL0 > TBR(max), the counter operates
as if it were configured for continuous mode. It will
not count down from TBR(max) to zero.
The selected clock source may be passed directly to the timer or divided by
2,4, or 8, as shown in Figure 12–4. The ID0 and ID1 bits in the TBCTL register
select the clock division. Note that the input divider is reset by a POR signal
or by setting the TBCLR bit in the TBCTL register (see chapter 3, System
Resets, Interrupts, and Operating Modes, for more information on the POR
signal). Otherwise, the input divider remains unchanged when the timer is
modified. The state of the input divider is invisible to software.
SMCLK 2
ID1 ID0 Carry/Zero Set_TBIFG
MC1 MC0
POR/TBCLR
INCLK 3 0 0 Pass 0 0 Stop Mode
0 1 1/2 0 1 Up Mode
1 0 1/4 1 0 Continuous Mode
1 1 1/8 1 1 Up/Down Mode
† Length is selectable for 8-, 10-, 12-, or 16-bit operation.
12-6
Timer_B Operation
INCLK 3
POR TBCLR
ID1 ID0
0 0 Pass
0 1 1/2
1 0 1/4
1 1 1/8
- Release Halt Mode: The timer counts in the selected direction when a
timer mode other than stop mode is selected with the MCx bits.
- Setting the TBCLR bit in TBCTL register: Setting the TBCLR bit in the
TBCTL register clears the timer value and input clock divider value. The
timer increments upward from zero with the next clock cycle as long as
stop-mode is not selected with the MCx bits.
- TBR is loaded with 0: When the counter (TBR register) is loaded with zero
with a software instruction the timer increments upward from zero with the
next clock cycle as long as stop-mode is not selected with the MCx bits.
Timer_B 12-7
Timer Modes
TBCL0
0h
Flag CCIFG0 is set when the timer equals the TBCL0 value. The TBIFG flag
is set when the timer counts from TBCL0 to zero. All interrupt flags are set
independently of the corresponding interrupt enable bit, but an interrupt is
requested only if the corresponding interrupt enable bit and the GIE bit are set.
Figure 12–6 shows the flag set cycle.
12-8
Timer Modes
Changing the timer period register TBCL0 while the timer is running and when
the transfer mode from TBCCR0 is immediate can be a little tricky. When the
new period is greater than or equal to the old period, the timer simply counts
up to the new period and no special attention is required (see Figure 12–7).
However, when the new period is less than the old period, the phase of the
timer clock during the TBCL0 update affects how the timer reacts to the new
period.
If the new, smaller period is transferred from TBCCR0 to TBCL0 during a high
phase of the timer clock, then the timer rolls to zero (or begins counting down
when in the up/down mode) on the next rising edge of the timer clock.
However, if the new, smaller period is written during a low phase of the timer
clock, then the timer continues to increment with the old period for one more
clock cycle before adopting the new period and rolling to zero (or beginning
counting down). This is shown in Figure 12–8.
Note:
If TBCL0 > TBR(max), the counter rolls to zero with the next rising edge of
timer clock.
0 1
ÏÏÏÏ
2 0 1 2 3 0 1 2 3 0 1
TBCL0 2
ÏÏÏÏ 3
Timer_B 12-9
Timer Modes
0 1 2 3 4 5 01 2 3 01 2 01 2 01 0 1 2 3 4 5 0 1 2 3 40 1 2 0 1 20 1
TBCL0 5 2 TBCL0 5 2
TBCL0 Loaded With 2 During High Clock Phase TBCL0 Loaded With 2 During Low Clock Phase
The capture/compare blocks and different output modes of each output unit
are useful to capture timer data based on external events or to generate
various different types of output signals. Examples of the different output
modes used with timer-continuous mode are shown in Figure 12–25.
In continuous mode, the timer starts counting from its present value. The
counter counts up to TBR(max) and restarts by counting from zero as shown
in Figure 12–9.
TBR(max)
0h
12-10
Timer Modes
The TBIFG flag is set when the timer counts from TBR(max) to zero. The
interrupt flag is set independently of the corresponding interrupt enable bit, as
shown in Figure 12–10. An interrupt is requested if the corresponding interrupt
enable bit and the GIE bit are set.
The continuous mode can be used to generate time intervals for the
application software. Each time an interval is completed, an interrupt can be
generated. In the interrupt service routine of this event, the time until the next
event is added to capture/compare register TBCCRx (and subsequently
compare latch TBCLx) as shown in Figure 12–11. Up to seven independent
time events can be generated using all seven capture/compare blocks.
Interrupt Events ∆t ∆t ∆t ∆t ∆t ∆t ∆t ∆t ∆t ∆t ∆t ∆t
Time intervals can be produced with other modes as well, where capture/
compare block 0 is used to determine the period. Their handling is more
complex since the sum of the old TBCCRx data and the new period can be
higher than the TBCL0 value. When the sum TBCCRxold plus ∆t is greater
than the TBCL0 data, the old TBCCR0 value must be subtracted to obtain the
correct time interval.
Timer_B 12-11
Timer Modes
Note:
If TBCL0 > TBR(max), the counter operates as if it were configured for
continuous mode. It will not count down from TBR(max) to zero.
0h
The up/down mode also supports applications that require dead times
between output signals. For example, to avoid overload conditions, two
outputs driving an H-bridge must never be in a high state simultaneously. In
the following example (see Figure 12–13), the tdead is:
tdead = ttimer × (TBCL1 – TBCL3)=
With: tdead Time during which both outputs need to be inactive
ttimer Cycle time of the timer clock
TBCLx Content of compare latch x
Note:
The dead time is ensured by the ability to simultaneously load the compare
latches.
TBCL1
TBCL3
0h
Dead Time
12-12
Timer Modes
The count direction is always latched with a flip-flop (Figure 12–14). This is
useful because it allows the user to stop the timer and then restart it in the same
direction it was counting before it was stopped. For example, if the timer was
counting down when the MCx bits were reset, then it will continue counting in
the down direction if it is restarted in up/down mode. If this is not desired, the
TBCLR bit in the TBCTL register must be used to clear the direction. Note that
the TBCLR bit affects other setup conditions of the timer. Refer to section 12.6
for a discussion of the Timer_B registers.
In up/down mode, the interrupt flags (CCIFG0 and TBIFG) are set at equal time
intervals (Figure 12–15). Each flag is set only once during the period, but they
are separated by 1/2 the timer period. CCIFG0 is set when the timer counts
from TBCL0–1 to TBCL0, and TBIFG is set when the timer completes counting
down from 0001h to 0000h. Each flag is capable of producing a CPU interrupt
when enabled.
Up/Down
Set
CCIFG0
Set
TBIFG
Changing the period value while the timer is running in up/down mode and the
transfer mode for TBCL0 is immediate is even trickier than in up mode. Like
in up mode, the phase of the timer clock when TBCL0 is changed affects the
timer’s behavior. Additionally, in up/down mode, the direction of the timer also
affects the behavior.
If the timer is counting in the up direction when the new period is transferred
from TBCCR0 to TBCL0, the conditions in the up/down mode are identical to
Timer_B 12-13
Timer Modes
those in the up mode. See section 12.3.2.1 for details. However, if the timer
is counting in the down direction when TBCL0 is updated, it continues its
descent until it reaches zero. The new period takes effect only after the counter
finishes counting down to zero. See Figure 12–16.
Note:
If TBCL0 > TBR(max), the counter operates as if it were configured for
continuous mode. It will not count down from TBR(max) to zero.
5
4
3
2
1
0
0 1 2 3 4 5 4 3 2 1 0 1 2 34 3 2 1 0 1 2 3 21 0 1 2 1 0 1 2 3 4 5 4 3 2 1 0 1 2 1
TBCL0 5 2 4 2 5 2
12-14
Timer Modes
Both the interrupt enable bit CCIEx and the interrupt flag CCIFGx are used for
capture and compare modes. CCIEx enables the corresponding interrupt.
CCIFGx is set on a capture or compare event.
The capture inputs CCIxA and CCIxB are connected to external pins or internal
signals. Different MSP430 devices may have different signals connected to
CCIxA and CCIxB. The data sheet should always be consulted to determine
the Timer_B connections for a particular device.
High Comparator x
Zero
EQU0 CAPx
Up/Down EQUx 0
1
CCIx
Set_CCIFGx
Timer_B 12-15
Timer Modes
If a capture is performed:
- An interrupt is requested if both interrupt enable bits CCIEx and GIE are
set.
The input signal to the capture/compare block is selected using control bits
CCISx1 and CCISx0, as shown in Figure 12–18. The input signal can be read
at any time by the software by reading bit CCIx.
CCIx
The capture signal can also be synchronized with the timer clock to avoid race
conditions between the timer data and the capture signal. This is illustrated in
Figure 12–19. The bit SCSx in capture/compare control register TBCCTLx
selects the capture signal synchronization.
CCIx
Capture
ÎÎÎ
Set
CCIFGx
12-16
Timer Modes
Applications with slow timer clocks can use the nonsynchronized capture
signal. In this scenario the software can validate the data and correct it if
necessary as shown in the following example:
Overflow logic is provided with each capture/compare register to flag the user
if a second capture is performed before data from the first capture was read
successfully. Bit COVx in register TBCCTLx is set when this occurs as shown
in Figure 12–20.
Idle
No Read
Capture
Capture Taken
Taken
Taken Capture
Capture
Capture
Clear Bit COV
in Register TBCCTL
Second
Capture Idle
Taken
COV = 1
Timer_B 12-17
Timer Modes
... ; Proceed
; RETI
Two bits, CCISx1 and CCISx0, and the capture mode selected by bits CCMx1
and CCMx0 are used by the software to initiate the capture. The simplest
realization is when the capture mode is selected to capture on both edges of
CCIx and bit CCISx1 is set. Software then toggles bit CCISx0 to switch the
capture signal between VCC and GND, initiating a capture each time the input
is toggled, as shown in Figure 12–21.
12-18
Timer Modes
CCISx0
CCIx
Capture
CCISx1 CCISx0
CMPx
0
CCIxA
1
CCIxB Capture
2 Capture
GND Mode
3
VCC
CCIx
CCMx1 CCMx0
Both Edges Selected 1 1
The compare mode is most often used to generate interrupts at specific time
intervals or used in conjunction with the output unit to generate output signals
such as PWM signals.
The compare data is double-buffered. The software writes the compare data
to the capture/compare register, but the data is transferred to the compare
latch TBCLx to be compared by the compare logic. The transfer of the compare
data from the TBCCRx register to the compare latch is user-selectable to be
either immediate or dependent upon a timer event. This double buffering
allows the user to update multiple compare values simultaneously. This is
useful for example with PWM signals where the period or duty cycle of multiple
signals needs to be updated simultaneously. See section 12.4.2.1 for more
discussion on how to use and configure the compare latches.
If the timer becomes equal to the value in compare latch TBCLx, then:
Timer_B 12-19
Timer Modes
- An interrupt is requested if interrupt enable bits CCIEx and GIE are set.
- Signal EQUx is output to the output unit. This signal affects the output
OUTx, depending on the selected output mode.
The EQU0 signal is true when the timer value is greater or equal to the TBCL0
value. The EQU1 to EQUx signals are true when the timer value is equal to the
corresponding TBCL1 to TBCLx values.
The compare logic uses the data in the compare latch for its comparison with
the timer value. The compare data is first written by software to the capture/
compare register TBCCRx and then automatically transferred to the compare
latch on a user-selectable load event. The load event is selected with the
CLLDx bits in each TBCCTLx register.
When using groups, two conditions must exist for the compare latches to be
loaded. First, all TBCCRx registers of the group must be updated (except
when using immediate mode); second, the load event must occur. This means
that if a user intends to retain any TBCCRx register data of a group when up-
dating the group, the old data must be written to the TBCCRx register again.
Otherwise, the compare latches will not be updated.
The CLLDx bits in the applicable TBCCTLx register select the load event.
There are four choices for the load event:
- Immediate
12-20
The groupings and load conditions are summarized below in Table 12–2.
TBR counts to TBR counts to TBR counts to TBR counts to TBR counts to TBR counts to TBR counts to
3 1–3
TBCL0 TBCL1 TBCL2 TBCL3 TBCL4 TBCL5 TBCL6
TBCL1, TBCL2 loaded immediately TBCL3, TBCL4 loaded immediately TBCL5, TBCL6 loaded immediately
0 0–3 Immediate when the corresponding TBCCRx when the corresponding TBCCRx when the corresponding TBCCRx
register is loaded register is loaded register is loaded
TBCL1, TBCL2 updated TBCL3, TBCL4 updated TBCL5, TBCL6 updated
1 1–3 TBR counts to 0 simultaneously when TBR counts simultaneously when TBR counts simultaneously when TBR counts
to 0 to 0 to 0
TBCL1, TBCL2 updated TBCL3, TBCL4 updated TBCL5, TBCL6 updated
1 1,2 TBR counts to 0 simultaneously when TBR simultaneously when simultaneously when
counts to 0 TBR counts to 0 TBR counts to 0
2
TBCL1, TBCL2 updated TBCL3, TBCL4 updated TBCL5, TBCL6 updated
TBR counts to 0
3 simultaneously when TBR counts to simultaneously when TBR counts to simultaneously when TBR counts to
or to TBCL0
0 or to TBCL0 0 or to TBCL0 0 or to TBCL0
TBR counts to TBR counts to TBR counts to TBR counts to TBR counts to TBR counts to TBR counts to
3 1–3
TBCL0 TBCL1 TBCL2 TBCL3 TBCL4 TBCL5 TBCL6
† Timer_B3 has only three CCR blocks: TBCCR0, TBCCR1, and TBCCR2. The load conditions for TBCL3/4/5/6 are not relevant and can be ignored.
Timer_B
Timer Modes
12-21
12-22
Timer Modes
Table 12–2. Compare Latch Operating Modes (Continued)
CLLDx From Load Conditions (load TBCCRx data to compare latch TBCLx)
Lowest Counter
TBCLGRP TBCCTL iin
TBCCTLx Mode
Timer_B
Group (see MCx x=0 x=1 x=2 x=3 x=4 x=5 x=6
Note 1)
TBCL1, TBCL2, TBCL3 loaded immediately when the TBCL4, TBCL5, TBCL6 loaded immediately when the
0 0–3 Immediate
corresponding TBCCRx register is loaded corresponding TBCCRx register is loaded
TBCL1, TBCL2, TBCL3 updated simultaneously when TBCL4, TBCL5, TBCL6 updated simultaneously when
1 1–3 TBR counts to 0
TBR counts to 0 TBR counts to 0
TBCL1, TBCL2, TBCL3 updated simultaneously when TBCL4, TBCL5, TBCL6 updated simultaneously when
2† 1,2 TBR counts to 0
TBR counts to 0 TBR counts to 0
2
TBR counts to 0 TBCL1, TBCL2, TBCL3 updated simultaneously when TBCL4, TBCL5, TBCL6 updated simultaneously when
3
or to TBCL0 TBR counts to 0 or to TBCL0 TBR counts to 0 or to TBCL0
TBR counts to TBR counts to TBR counts to TBR counts to TBR counts to TBR counts to TBR counts to
3 1–3
TBCL0 TBCL1 TBCL2 TBCL3 TBCL4 TBCL5 TBCL6
0 0–3 TBCL0, TBCL1, TBCL2, TBCL3, TBCL4, TBCL5, TBCL6 Loaded immediately when the corresponding TBCCRx register is loaded.
1 1–3 TBCL0,TBCL1, TBCL2, TBCL3, TBCL4, TBCL5, TBCL6 updated simultaneously when TBR counts to 0
1,2 TBCL0,TBCL1, TBCL2, TBCL3, TBCL4, TBCL5, TBCL6 updated simultaneously when TBR counts to 0
3‡ 2
3 TBCL0,TBCL1, TBCL2, TBCL3, TBCL4, TBCL5, TBCL6 updated simultaneously when TBR counts to 0 or to TBCL0
TBR counts to TBR counts to TBR counts to TBR counts to TBR counts to TBR counts to TBR counts to
3 1–3
TBCL0 TBCL1 TBCL2 TBCL3 TBCL4 TBCL5 TBCL6
† Timer_B3 has only three CCR blocks: No triple group is possible with 3 CCR’s. If TBCLGRP=2 then it is treated as TBCLGRP=1.
‡ Timer_B3 has only three CCR blocks: TBCCR0, TBCCR1, and TBCCR2 are one group (TBCLGRP=3, CLLDx={0, 1, 2}).
Notes: 1) When using groups, load mode for the group is selected with the CLLDx bits of the lowest numbered TBCCTLx register in the group (except when TBCLGRP=3). For example,
when grouped by 2, the CLLDx bits of TBCCTL3 determine the load mode for TBCL3 and TBCL4. When grouped by 3, the CLLDx bits of TBCCTL4 determine the load mode
for TBCL4, TBCL5, and TBCL6, etc. When TBCLGRP=3 the CLLDx bits from TBCTL1 are used.
2) When using groups, all TBCCRx registers must be updated with new data before the load will take place (except when using immediate mode), even if new data = old data.
When using immediate mode, each compare latch is updated immediately when its corresponding TBCCRx register is updated.
3) When using groups, different load modes may be selected for each group. For example, when grouped by 3, immediate mode may be selected (via CLLDx bits in TBCCTL1)
for TBCL1, TBCL2, and TBCL3, and mode 2 may be selected (via CLLDx bits in TBCCTL4) for TBCL4, TBCL5, and TBCL6.
The Output Unit
OUTx Signal
Set
Output D Q
EQU0 Control
EQUx Timer Clock
Block Reset
POR
OUTx
OMx2 OMx1 OMx0
0 0 0 Output mode: OUTx signal reflects the value of the OUTx bit
0 0 1 Set mode: OUT x signal reflects the value of signal EQUx
0 1 0 PWM toggle/reset: EQUx toggles OUTx. EQU0 resets OUTx.
0 1 1 PWM set/reset: EQUx sets OUTx. EQU0 resets OUTx
1 0 0 Toggle: EQUx toggles OUTx signal.
1 0 1 Reset: EQUx resets OUTx.
1 1 0 PWM toggle/set: EQUx toggles OUTx. EQU0 sets OUTx.
1 1 1 PWM reset/set: EQUx resets OUTx. EQU0 sets OUTx.
Note: OUTx signal updates with rising edge of timer clock for all modes except
mode 0.
Modes 2, 3, 6, 7 not useful for output unit 0.
Timer_B 12-23
The Output Unit
The output modes are defined by the OMx bits and are discussed below. 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.
Output mode 0: Output mode:
The output signal OUTx is defined by the OUTx bit in control
register TBCCTLx. The OUTx signal updates immediately
upon completion of writing the bit information.
Output mode 1: Set mode:
The output is set when the timer value becomes equal to
compare data TBCLx. It remains set until a reset of the timer,
or until another output mode is selected to control the output.
Output mode 2: PWM toggle/reset mode:
The output is toggled when the timer value becomes equal
to compare data TBCLx. It is reset when the timer value
becomes equal to TBCL0.
Output mode 3: PWM set/reset mode:
The output is set when the timer value becomes equal to
compare data TBCLx. It is reset when the timer value
becomes equal to TBCL0.
Output mode 4: Toggle mode:
The output is toggled when the timer value becomes equal
to compare data TBCLx. The output period is double the
timer period.
Output mode 5: Reset mode:
The output is reset when the timer value becomes equal to
compare data TBCLx. It remains reset until another output
mode is selected to control the output.
12-24
The Output Unit
OUTx Signal
Set
Output D Q
EQU0 Control
EQUx Timer Clock
Block Reset
POR
OUTx
OMx2 OMx1 OMx0
The timer is Incremented with the rising edge of the timer clock.
Timer
Clock
Timer TBR(max)
n–2 n–1 n n+1 0 1
TBR or TBCL0
TBR = n
EQUx
TBCLx = n
EQU0 TBR = 0
or
TBR = TBCL0
EQU0, Delayed
Used in Up Mode Only
EQU0 delayed is used in up mode, not EQU0. EQU0 is active high when
TBR = TBCL0. EQU0 delayed is active high when TBR = 0.
Timer_B 12-25
The Output Unit
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, as shown in
Figure 12–24.
12-26
The Output Unit
TBCL1
0h
The OUTx signal is changed when the timer reaches the TBCLx and TBCL0
values, depending on the output mode, as shown in Figure 12–25.
TBCL1
0h
Timer_B 12-27
The Output Unit
The OUTx signal changes when the timer equals TBCLx in either count
direction and when the timer equals TBCL0, depending on the output mode,
as shown in Figure 12–26.
TBCL3
0h
12-28
Timer_B Registers
Timer_B 12-29
Timer_B Registers
Bit 2: Timer clear (TBCLR) bit. The timer and input divider are reset with
the POR signal, or if bit TBCLR is set. The TBCLR bit is
automatically reset and is always read as zero. The timer starts in
the upward direction with the next valid clock edge, unless halted
by cleared mode control bits.
Bits 4, 5: Mode control: Table 12–5 describes the mode control bits.
Bits 6, 7: Input divider control bits. Table 12–6 describes the clock-divider
bits.
Bits 8, 9: Clock source selection bits. Table 12–7 describes the clock source
selections.
12-30
Timer_B Registers
Bits 11, 12: Configure 16-bit timer (TBR) for 8-bit, 10-bit, 12-bit, or 16-bit
operation
CNTL = 0: 16-bit length, TBR(max) is 0FFFFH
CNTL = 1: 12-bit length, TBR(max) is 0FFFH
CNTL = 2: 10-bit length, TBR(max) is 03FFH
CNTL = 3: 8-bit length, TBR(max) is 0FFH
Bits 13, 14: Load compare latches, individually or in groups. The load signal
is controlled via the CLLDx bits located in the appropriate
capture/compare control register TBCCTLx.
Timer_B 12-31
Timer_B Registers
1) Modify the control register and stop the timer with one instruction.
12-32
Timer_B Registers
Bit 2: The OUTx bit determines the value of the OUTx signal if the
output mode is 0.
Timer_B 12-33
Timer_B Registers
Bits 9, 10: CLLD: Select load source for compare latch TBCLx
(also see description of bits TBCLGRP, 13 and 14, in TBCTL)
CLLD = 0: Immediate
CLLD = 1: Load TBCCRx data to TBCLx when TBR counts to 0
CLLD = 2: UP/DOWN mode: load TBCCRx data to TBCLx when
TBR counts to TBCL0 or to 0
Continuous mode or UP-mode: load TBCCRx data
to TBCLx when TBR counts to 0
CLLD = 3: TBCCRx data are loaded to TBCLx when TBR counts
to TBCLx
12-34
Timer_B Registers
Timer_B 12-35
Timer_B Registers
IRACC
S CCIFG2
CCI2
EQ2 S
CMP2 Sel CCIE2
Timer Clock R
IRACC Interrupt_Service_Request
Module 3
Priority and
Module 4 Vector Word
Generator
Module 5
Interrupt_Vector_Address
S CCIFG6
CCI6
EQ6 S
CMP6 Sel CCIE6
Timer Clock R
IRACC
S TBIFG
TBR(MAX)
Timer = TBCL0 S
XXX Sel TBIE
Timer Clock R
IRACC
The flag with the highest priority generates a number from 2 to 14 in the TBIV
register as shown in Table 12–10. (If the value of the TBIV register is 0, no
interrupt is pending.) This number can be added to the program counter to
automatically enter the appropriate software routine without the need for
reading and evaluating the interrupt vector. The software example in section
12.6.4.3 shows this technique.
12-36
Timer_B Registers
Accessing the TBIV register automatically resets the highest pending interrupt
flag. If another interrupt flag is set, then another interrupt will be immediately
generated after servicing the initial interrupt. For example, if both CCIFG2 and
CCIFG3 are set, when the interrupt service routine accesses the TBIV register
(either by reading it or by adding it directly to the PC), CCIFG2 will be reset
automatically. After the RETI instruction of the interrupt service routine is
executed, the CCIFG3 flag will generate another interrupt.
Timer_B 12-37
Timer_B Registers
12-38
Timer_B Registers
If the FLL (on applicable devices) is turned off, then two additional cycles need
to be added for a synchronous start of the CPU and system clock MCLK.
If the CPU clock MCLK was turned off in devices with the Basic Clock Module
(CPUOFF=1), then 2 or 3 additional cycles need to be added for synchronous
start of the CPU. The delta of one clock cycle is caused when clocks are
asynchronous to the restart of CPU clock MCLK.
Timer_B 12-39
Timer_B Registers
With the TBIV register and the previous software, the shortest repetitive time
distance tCRmin between two events using a compare register is:
tCRmin = ttaskmax + 16 × tcycle
With: ttaskmax Maximum (worst case) time to perform the task during the
interrupt routine (for example, incrementing a counter)
The shortest repetitive time distance tCLmin between two events using a
capture register is:
12-40
Chapter 13
Bit SYNC in control register UCTL (U0CTL for USART0 or U1CTL for
USART1) selects the required mode:
SYNC = 0: UART – asynchronous mode selected
SYNC = 1: SPI – synchronous mode selected
The ’43x has one USART, named USART0. The ’44x has two USARTs imple-
mented: USART0 and USART1.
Topic Page
1 SIMO
WUT Transmit Shift Register
0
Transmit Buffer
TXWake CKPH SYNC CKPL
U0TXBUF or U1TXBUF
UCLK
UCLKI
Clock Phase and Polarity
UCLKS
13-2
USART Peripheral Interface, UART Mode
- Two shift registers that shift a serial data stream into URXD and out of
UTXD
- Status flags
LSB First
WUT Transmit Shift Register UTXD
Transmit Buffer
TXWake CKPL
U0TXBUF or U1TXBUF
UCLKI
Clock Polarity UCLK
UCLKS
The receive (RX) operation is initiated by the receipt of a valid start bit. It begins
with a negative edge at URXD, followed by the taking of a majority vote from
three samples where two of the samples must be zero. These samples occur
at n/2–X, n/2, and n/2+X of the BRCLK periods following the negative edge.
This sequence provides false start-bit rejection, and also locates the center of
the bits in the frame, where the bits can be read on a majority basis. The timing
of X is 1/32 to 1/63 times that of the BRCLK, depending on the division rate
of the baud rate generator and provides complete coverage of at least two
BRCLK periods. Figure 13–4 shows an asynchronous bit format.
URXD H
L
Data Bit Period = n or n+1 BRCLK Periods
13-4
Asynchronous Operation
Typical baud-rate generation uses a prescaler from any clock source and a
fixed, second-clock divider that is usually divide-by-16. Figure 13–5 shows a
typical baud-rate generation.
H
Start
L
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1
H
BRSCLK
L
Figure 13–6. MSP430 Baud Rate Generation. Example for n or n + 1 Clock Periods
0 7 0 7
SSEL1 SSEL0 UxBR0 UxBR1 Start
0 1 7 8 15
UCLKI
1 BRCLK
ACLK 15-Bit Prescaler/Divider
2
SMCLK
3 Q1 Q15
SMCLK
Compare 0 or 1 Toggle
FF
BITCLK
0 7
Modulation Register
U0MCTL or U1MCTL
H
Start L
H
BRCLK
L
Counter n/2 n/2-1 n/2-2 1 0 n/2 n/2-1 2 1 0 n/2
1 n/2 n/2-1 n/2-2 1 0 n/2 n/2-1
1 n/2 n/2-1 n/2-2 1 n/2 n/2-1 n/2-2
H
BITCLK L
INT(n/2), m = 0
INT(n/2)+m(=1)
Divide By n(Even), m = 0
n(Odd) or n(Even)+m(=1)
n(Odd)+m(=1)
The modulation register LSB is first used for modulation, which begins with the
start bit. A set modulation bit increases the division factor by one.
13-6
Asynchronous Operation
The control register bit MM defines the address bit or idle-line multiprocessor
format. Both use the wake-up-on-transfer mode by activating the TXWake bit
(address feature function) and RXWake bit. The URXWIE and URXIE bits
control the transmit and receive features of these asynchronous
communication formats.
In the idle-line multiprocessor format, shown in Figure 13–7, blocks of data are
separated by an idle time. An idle-receive line is detected when ten or more
1s in a row are received after the first stop bit of a character.
UTXD/URXD
UTXD/URXD
ST Address SP ST Data SP ST Data SP
First Frame Within Block Frame Within Block Frame Within Block
is Address. It Follows Idle
Period of 10 Bits or More Idle Period Less Than 10 Bits
When two stop bits are used for the idle line, as shown in Figure 13–8, the
second one is counted as the first mark bit of the idle period. The first character
received after an idle period is an address character. The RXWake bit can be
used as an address tag for the character. In the idle-line multiprocessor format,
the RXWake bit is set when a received character is an address character and
is transferred into the receive buffer.
Normally, if the USART URXWIE bit is set in the receive control register,
characters are assembled as usual by the receiver. They are not, however,
transferred to the receiver buffer, UxRXBUF, nor are interrupts generated.
When an address character is received, the receiver is temporarily activated
to transfer the character to UxRXBUF and to set the URXIFG interrupt flag.
Applicable error status flags are set. The application software can validate the
received address. If there is a match, the application software further
processes the data and executes the operation. If there is no match, the
processor waits for the next address character to arrive. The URXWIE bit is
not modified by the USART: it must be modified manually to receive
nonaddress or address characters.
13-8
Asynchronous Operation
1) Set the TXWake bit and then write any word (don’t care) to the UxTXBUF
(UTXIFG must be set).
When the transmitter shift register is empty, the contents of UxTXBUF are
shifted to the transmit shift register and the TXWake value is shifted to
WUT.
2) Set bit WUT, which suppresses the start, data, and parity bits and
transmits an idle period of exactly 11 bits, as shown in Figure 13–10.
The next data word, shifted out of the serial port after the address-
character identifying idle period, is the second word written to the
UxTXBUF after the TXWake bit has been set. The first data word written is
suppressed while the address identifier is sent out and ignored thereafter.
Writing the first don’t care word to UxTXBUF is necessary to shift the
TXWAKE bit to WUT and generate an idle-line condition.
Usually, if the USART URXWIE bit is set, data characters are assembled by
the receiver but are not transferred to the receiver buffer UxRXBUF, nor are
interrupts generated. When a character that has an address bit set is received,
the receiver is temporarily activated to transfer the character to UxRXBUF and
to set the URXIFG. Error status flags are set as applicable. The application
software processes the succeeding operation to optimize resource handling
or reduce current consumption. The application software can validate the
received address. If there is a match, the processor can read the remainder
of the data block. If there is not a match, the processor waits for the next
address character to arrive.
UTXD/URXD
UTXD/URXD
ST Address 1 SP ST Data 0 SP ST Data 0 SP
13-10
Interrupt and Enable Functions
The USART receiver and transmitter operate independently, but use the same
baud rate.
URXE = 1
URXE = 1
Idle State Valid Start Bit Receiver
Receive Handle Interrupt
(Receiver Collects
Disable Conditions
Enabled) Character
URXE = 0
Character
URXE = 1 Received
URXE = 0
When UTXE is reset and the current transmission is completed, new data
written to the transmit buffer will not be transmitted. Once the UTXE bit is set,
the data in the transmit buffer are immediately loaded into the transmit shift
register and character transmission is started.
13-12
Interrupt and Enable Functions
URXWIE Clear
RXWake SWRST
Character Received PUC
Each Character or Address
or UxRXBUF
Will Set Flag URXIFG
Break Detected URXSE
IRQA
Clear
PUC or SWRST
Request_
Set UTXIFG Interrupt_Service
VCC D Q
The transmit interrupt enable UTXIE bit controls the ability of the UTXIFG to
request an interrupt, but does not prevent the flag UTXIFG from being set. The
UTXIE is reset with a PUC signal or a software reset (SWRST) bit. The
UTXIFG bit is set after a system reset PUC signal or software reset (SWRST),
but the UTXIE bit is reset to ensure full interrupt-control capability.
13-14
Control and Status Registers
The USART control and status registers are byte structured and should be
accessed using byte processing instructions (suffix B). Table 13–3 lists the
registers and their access modes.
Short Register
Register Form Type Address Initial State
USART control U0CTL Read/write 070h See section 13.5.1.
Transmit control U0TCTL Read/write 071h See section 13.5.2.
Receive control U0RCTL Read/write 072h See section 13.5.3.
Modulation control U0MCTL Read/write 073h Unchanged
Baud rate 0 U0BR0 Read/write 074h Unchanged
Baud rate 1 U0BR1 Read/write 075h Unchanged
Receive buffer U0RXBUF Read/write 076h Unchanged
Transmit buffer U0TXBUF Read 077h Unchanged
Short Register
Register Form Type Address Initial State
USART control U1CTL Read/write 078h See section 13.5.1.
Transmit control U1TCTL Read/write 079h See section 13.5.2.
Receive control U1RCTL Read/write 07Ah See section 13.5.3.
Modulation control U1MCTL Read/write 07Bh Unchanged
Baud rate 0 U1BR0 Read/write 07Ch Unchanged
Baud rate 1 U1BR1 Read/write 07Dh Unchanged
Receive buffer U1RXBUF Read/write 07Eh Unchanged
Transmit buffer U1TXBUF Read 07Fh Unchanged
All bits are random after a PUC signal, unless otherwise noted by the detailed
functional description.
The information stored in the USART control register (U0CTL for USART0 and
U1CTL for USART1), shown in Figure 13–16, determines the basic operation
of the USART module. The register bits select the communications protocol,
communication format, and parity bit. All bits must be programmed according
to the selected mode before resetting the SWRST bit to disable the reset.
Bit 0: The USART state machines and operating flags are initialized
to the reset condition (URXIFG = URXIE = UTXIE = 0, UTXIFG
= 1) if the software reset bit is set. Until the SWRST bit is reset,
all affected logic is held in the reset state. This implies that after
a system reset the USART must be reenabled by resetting this
bit. The receive and transmit enable flags URXE and UTXE are
not altered by SWRST.
The SWRST bit resets the following bits and flags: URXIE,
UTXIE, URXIFG, RXWAKE, TXWAKE, RXERR, BRK, PE, OE,
and FE
Note:
The USART initialization sequence should be:
— Initialize per application requirements while leaving SWRST=1
— Clear SWRST
— Enable interrupts if desired.
13-16
Control and Status Registers
Bit 3: The listen bit selects if the transmitted data is fed back internally
to the receiver.
Listen = 0: No feedback
Listen = 1: Transmit signal is internally fed back to the receiver.
This is commonly known as loopback mode.
Bit 4: Character length
This register bit selects the length of the character to be
transmitted as either 7 or 8 bits. 7-bit characters do not use the
eighth bit in UxRXBUF and UxTXBUF. This bit is padded with 0.
CHAR = 0: 7-bit data
CHAR = 1: 8-bit data
Bit 5: Number of stop bits
This bit determines the number of stop bits transmitted. The
receiver checks for one stop bit only.
SP = 0: one stop bit
SP = 1: two stop bits
Bit 6: Parity odd/even
If the PENA bit is set (parity bit is enabled), the PEV bit defines
odd or even parity according to the number of odd or even 1 bits
(in both the transmitted and received characters), the address
bit (address-bit multiprocessor mode), and the parity bit.
PEV = 0: odd parity
PEV = 1: even parity
Bit 0: The transmitter empty (TXEPT) flag is set when the transmitter
shift register and UxTXBUF are empty, and is reset when data
is written to UxTXBUF. It is set by a SWRST.
Bit 1: Unused
Bit 2: The TXWake bit controls the transmit features of the
multiprocessor communication modes. Each transmission
—started by loading the UxTXBUF—uses the state of the
TXWake bit to initialize the address-identification feature. It must
not be cleared—the USART hardware clears this bit once it is
transferred to the WUT; a SWRST also clears the TXWake bit.
Bit 3: The receive-start edge-control bit, if set, requests a receive
interrupt service. For a successful interrupt service, the
corresponding enable bits URXIE and GIE must be set. The
advantage of this bit is that it starts the controller clock system,
including MCLK, along with the interrupt service, and keeps it
running by modifying the mode control bits. If the selected clock
source is activated then the receive operation starts even from
low-power modes.
Bits 4, 5: Source select 0 and 1
The source select bit defines which clock source is used for
baud-rate generation:
SSEL1, SSEL0 0 External clock, UCLKI
1 ACLK
2, 3 SMCLK
Bit 7: Unused
13-18
Control and Status Registers
Bit 0: The receive error bit (RXERR) indicates that one or more error
flags (FE, PE, OE, or BRK) is set. It is not reset when the error
flags are cleared by instruction.
Bit 1: Receiver wake-up detect
The RXWake bit is set when a received character is an address
character and is transferred into the receive buffer.
Address-bit multiprocessor mode: RXWake is set when the
address bit is set in the
character received.
Idle-line multiprocessor mode: RXWake is set if an idle
URXD line is detected
(11 bits of mark level) in
front of the received
character.
RXWake is reset by accessing the receive buffer (UxRXBUF),
by a USART software reset, or by a system-reset PUC signal.
Bit 2: The receive wake-up interrupt-enable bit (URXWIE) selects the
type of character to set the interrupt flag (URXIFG):
URXWIE = 0: Each character received sets the URXIFG
URXWIE = 1: Only characters that are marked as address
characters set the interrupt flag URXIFG. It
operates identically in both multiprocessor
modes.
The wake-up interrupt enable feature depends on the receive
erroneous-character feature. See also Bit 3, URXEIE.
Bit 3: The receive erroneous-character interrupt-enable bit URXEIE
selects whether an erroneous character is to set the interrupt
flag URXIFG.
URXEIE = 0: Each erroneous character received does not
alter the interrupt flag URXIFG.
URXEIE = 1: All characters can set the interrupt flag URXIFG
as described in Table 13–4, depending on the
conditions set by the URXWIE bit.
Bit 4: The break detect bit (BRK) is set when a break condition occurs
and the URXEIE bit is set. The break condition is recognized if
the RXD line remains continuously low for at least 10 bits,
beginning after a missing first stop bit. It is not cleared by receipt
of a character after the break is detected, but is reset by a
SWRST, a system reset, or by reading the UxRXBUF. The
receive interrupt flag URXIFG is set if a break is detected.
Bit 6: The parity error flag bit PE is set when a character is received
with a mismatch between the number of 1s and its parity bit. The
parity checker includes the address bit, used in the address-bit
multiprocessor mode, in the calculation. The flag is disabled if
parity generation and detection are not enabled. In this case the
flag is read as 0. It is reset by a SWRST, a system reset, or by
reading the UxRXBUF.
Bit 7: The framing error flag bit FE is set when a character is received
with a 0 stop bit and is loaded into the receive buffer. Only the
first stop bit is checked when more than one is used. The missing
stop bit indicates that the start-bit synchronization is lost and the
character is incorrectly framed. FE is reset by a SWRST, a
system reset, or by reading the UxRXBUF.
13-20
Control and Status Registers
7 0
U0BR1, 075h
215 214 213 212 211 210 29 28
U1BR1, 07Dh
rw rw rw rw rw rw rw rw
BRCLK
Baud rate = n–1 with UxBR= [UxBR1, UxBR0]
UxBR ) 1n S mi
i+0
Note:
Unpredictable receive and transmission occur if UxBR <3.
The modulation control register, shown in Figure 13–20, ensures proper timing
generation with the UxBR0 and UxBR1, even with crystal frequencies that are
not integer multiples of the required baud rate.
The timing of the running bit is expanded by one clock cycle of the baud-rate-
divider input clock if bit mi is set.
Each time a bit is received or transmitted, the next bit in the modulation control
register determines the present bit timing. The first bit time in the protocol—the
start bit time—is determined by UxBR plus m0; the next bit is determined by
UxBR plus m1, and so on.
m0 – m1 – m2 – m3 – m4 – m5 – m6 – m7 – m0 – m1 – m2 – .....
The UTXIFG flag indicates that the UxTXBUF buffer is ready to accept another
character for transmission.
13-22
Utilizing Features of Low-Power Modes
- Use the lowest input clock frequency for the required baud rate
URXWIE Clear
RXWake SWRST
Character Received PUC
Each Character or Address
Will Set Flag URXIFG or UxRXBUF Read
Break Detected URXSE
IRQA
The URXD signal feeds into the USART module by first going into a deglitch
circuit. Glitches cannot trigger the receive-start condition flag URXS, which
prevents the module from being started from small glitches on the URXD line.
Because glitches do not start the system or the USART module, current
consumption is reduced in noisy environments. Figure 13–24 shows the
accepted receive-start timing condition.
Figure 13–24. Receive-Start Timing Using URXS Flag, Start Bit Accepted
Majority Vote
URXD
URXS
The UART stops receiving a character when the URXD signal exceeds the
deglitch time tτ but the majority vote on the signal fails to detect a start bit, as
shown in Figure 13–25. The software should handle this condition and return
the system to the appropriate low-power mode. The interrupt flag URXIFG is
not set.
Figure 13–25. Receive Start Timing Using URXS Flag, Start Bit Not Accepted
Majority Vote
URXD
URXS
Glitches at the URXD line are suppressed automatically and no further activity
occurs in the MSP430 as shown in Figure 13–26. The data for the deglitch time
tτ is noted in the corresponding device specification.
Figure 13–26. Receive Start Timing Using URXS Flag, Glitch Suppression
Majority Vote
URXD
URXS
tτ
The interrupt handler must reset the URXSE bit in control register UxCTL to
prevent further interrupt service requests from the URXS signal and to enable
the basic function of the receive interrupt flag URXIFG.
13-24
Utilizing Features of Low-Power Modes
**********************************************************
* Interrupt handler for frame start condition and *
* Character receive *
**********************************************************
U0RX_Int BIT.B #URXIFG0,&IFG2 ; test URXIFG signal to
JNE ST_COND ; check if frame start
; condition
.....
.....
ST_COND BIC.B #URXSE,&U0TCTL ; clear ff/signal URXS,
; stop further interrupt
; requests
BIS.B #URXSE,&U0TCTL ; Prepare FF_URXS for next
; frame start bits and set
..... ; the conditions to run the
..... ; clock needed for UART RX
The MSP430 USART can generate baud rates up to one third of the clock
frequency. An additional modulation of the baud-rate timing adjusts timing for
individual bits within a frame. The timing is adjusted from bit to bit to meet
timing requirements even when a noninteger division is needed. Baud rates
up to 4800 baud can be generated from a 32,768 Hz crystal with maximum
errors of 11 percent. Standard UARTs—even with the worst maximum error
(–14.6 percent)—can obtain maximum baud rates of 75 baud.
N= BRCLK
baud rate
The required division factor N usually has an integer part and a fraction. The
divider in the baud rate generator realizes the integer portion of the division
factor N, and the modulator meets the fractional part as closely as possible.
The factor N is defined as:
n–1
N + UxBR ) 1
n S mi i+0
Where:
N: Target division factor
UxBR: 16-bit representation of registers UxBR1 and UxBR0
i: Actual bit in the frame
n: Number of bits in the frame
mi : Data of the actual modulation bit
13-26
Baud Rate Considerations
BRCLK
ti t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12
Mark
URXD ST D0 D6 D7
Space
[2nd Stop Bit, SP = 1]
[Parity Bit, PE = 1]
[Address Bit, MM = 1]
[8th Data Bit, Char = 1]
i 0 1 8 9 10 11
Even small errors per bit (relative errors) can result in large cumulative errors.
They must be considered to be cumulative, not relative. The error of an
individual bit can be calculated by:
n–1 n–1
S t actual * S t targeti
i
Error[%] + i+0 i+0
100%
t baud rate
or,
NJ
Error [%] + baud rate
BRCLK
ƪ(i ) 1 ) n–1
ƫ
UxBR ) S m i * ( i ) 1 )
i+0
Nj 100%
With:
baud rate: Required baud rate
BRCLK: Input frequency – selected for UCLK, ACLK, or MCLK
i = 0 for the start bit, 1 for the data bit D0, and so on
UxBR: Division factor in registers UxBR1 and UxBR0
ǒ
Start bit Error [%] + baud rate
BRCLK
((0 ) 1) UxBR ) 1)–1 Ǔ 100% + 2.54%
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Ǔ 100% + 0.29%
BRCLK
Data bit D2 Error [%] + ǒbaud rate ((3 ) 1) UxBR ) 3)–4Ǔ 100% + 2.83%
BRCLK
Data bit D3 Error [%] + ǒbaud rate ((4 ) 1) UxBR ) 3)–5Ǔ 100% +*1.95%
BRCLK
Data bit D4 Error [%] + ǒbaud rate ((5 ) 1) UxBR ) 4)–6Ǔ 100% + 0.59%
BRCLK
Data bit D5 Error [%] + ǒ baud rate ((6 ) 1) UxBR ) 5)–7Ǔ 100% + 3.13%
BRCLK
Data bit D6 Error [%] + ǒbaud rate ((7 ) 1) UxBR ) 5)–8Ǔ 100% + *1.66%
BRCLK
Data bit D7 Error [%] + ǒbaud rate ((8 ) 1) UxBR ) 6)–9Ǔ 100% + 0.88%
BRCLK
Parity bit Error [%] + ǒbaud rate ((9 ) 1) UxBR ) 7)–10Ǔ 100% + 3.42%
BRCLK
Stop bit 1 Error [%] + ǒbaud rate ((10 ) 1) UxBR ) 7)–11Ǔ 100% + *1.37%
BRCLK
Stop bit 2 Error [%] + ǒbaud rate ((11 ) 1) UxBR ) 8)–12Ǔ 100% + 1.17%
BRCLK
13-28
Baud Rate Considerations
Table 13–6.Commonly Used Baud Rates, Baud Rate Data, and Errors
Divide by ACLK (32,768 Hz) MCLK (1,048,576 Hz)
The maximum error is calculated for the receive and transmit modes. The
receive-mode error is the accumulated time versus the ideal scanning time in
the middle of each bit. The transmit error is the accumulated timing error
versus the ideal time of the bit period.
The MSP430 USART peripheral interface allows baud rates nearly as high as
the clock rate. It has a low error accumulation as a result of modulating the
individual bit timing. In practice, an error margin of 20% to 30% supports
standard serial communication.
i 0 1 2
ttarget t0 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
BRSCLK
URXD ST D0 D2
URXDS ST D0 D2
tactual t0 t1 t2
Synchronization Error ± 0.5x BLSCLK
Sample
URXDS
Int(UxBR/2)+m0 = UxBR +m1 = 13+1 = 14 UxBR +m2 = 13+0 = 13
Int (13/2)+1 = 6+1 = 7
Majority Vote Taken Majority Vote Taken Majority Vote Taken
13-30
Baud Rate Considerations
ǒ ǓNj * 1–i Ǔ
OR
Error [%] + baud rate
BRCLK
NJ2 ƪm0 ) int ǒ UxBRń2 Ǔƫ ) i ǒ n–1
UxBR ) S m i
i+1
100%
Where:
baud rate is the required baud rate
BRCLK is the input frequency—selected for UCLK, ACLK, or MCLK
i = 0 for the start bit, 1 for data bit D0, and so on
UxBR is the division factor in registers UxBR1 and UxBR0
ǒ
Start bit Error [%] + baud rate
BRCLK
[2x(1 ) 6) ) (0 UxBR ) 0 –0)]–1 Ǔ 100% + 2.54%
Data bit D0 Error [%] + ǒbaud rate [2x(1 ) 6) ) (1 UxBR ) 1)]–1–1 Ǔ 100% + 5.08%
BRCLK
ǒ
Data bit D1 Error [%] + baud rate
BRCLK
[2x(1 ) 6) ) (2 UxBR ) 1)]–1–2Ǔ 100% + 0.29%
Data bit D2 Error [%] + ǒbaud rate [2x(1 ) 6) ) (3 UxBR ) 2)]–1–3Ǔ 100% + 2.83%
BRCLK
Data bit D3 Error [%] + ǒ baud rate [2x(1 ) 6) ) (4 UxBR ) 2)]–1–4Ǔ 100% + –1.95%
BRCLK
Data bit D4 Error [%] + ǒbaud rate [2x(1 ) 6) ) (5 UxBR ) 3)]–1–5Ǔ 100% + 0.59%
BRCLK
Data bit D5 Error [%] + ǒbaud rate [2x(1 ) 6) ) (6 UxBR ) 4)]–1–6Ǔ 100% + 3.13%
BRCLK
Data bit D6 Error [%] + ǒbaud rate [2x(1 ) 6) ) (7 UxBR ) 4)]–1–7Ǔ 100% + –1.66%
BRCLK
Data bit D7 Error [%] + ǒbaud rate [2x(1 ) 6) ) (8 UxBR ) 5)]–1–8Ǔ 100% + 0.88%
BRCLK
Parity bit Error [%] + ǒbaud rate [2x(1 ) 6) ) (9 UxBR ) 6)]–1–9Ǔ 100% + 3.42%
BRCLK
Stop bit 1 Error [%] + ǒ baud rate [2x(1 ) 6) ) (10 UxBR ) 6)]–1–10Ǔ 100% + –1.37%
BRCLK
Stop bit 2 Error [%] + ǒbaud rate [2x(1 ) 6) ) (11 UxBR ) 7)]–1–11Ǔ 100% + –1.17%
BRCLK
Bit SYNC in control register U0CTL for UART0 and U1CTL for USART1
selects the required mode:
SYNC = 0: UART—asynchronous mode selected
SYNC = 1: SPI—synchronous mode selected
Topic Page
1 SIMO
WUT Transmit Shift Register
0
Transmit Buffer
TXWake CKPH SYNC CKPL
U1TXBUF or U0TXBUF
UCLK
UCLKI
Clock Phase and Polarity
UCLKS
14-2
14.2 USART Peripheral Interface, SPI Mode
The USART peripheral interface is a serial channel that shifts a serial bit
stream of 7 or 8 bits in and out of the MSP430. The SPI mode is chosen when
control bit SYNC in the USART control register (U0CTL for UART0 and U1CTL
for USART1) is set.
- Supports three-pin and four-pin SPI operations via SOMI, SIMO, UCLK,
and STE
SYNC = 1
1 0
SSEL1 SSEL0 SYNC
Baud-Rate Generator
0
UCLKI
1 STE
ACLK
2 Baud-Rate Register
SMCLK
3
SMCLK
SYNC
Baud-Rate Generator
UCLKS
0
Transmit Buffer
U1TXBUF or U0TXBUF CKPH SYNC CKPL
UCLK
(UCLKI)
Clock Phase and Polarity
UCLKS
The four-pin SPI mode also uses a control line to enable a slave to receive and
transmit data. The line is controlled by the master.
- UCLK USART clock. The master drives this signal and the slave uses
it to receive and transmit data.
The direction is defined by UCLKDIR (UCLKDIR=0 input
direction) UCLKDIR = [SYNC .and. MM .and. (STC .or. STE)]
Output direction is selected when SPI + Master Mode is selected.
When 4-pin SPI is selected (STC=0) input direction is forced by
a low level on external STE pin.
14-4
Synchronous Operation
Figure 14–3. MSP430 USART as Master, External Device With SPI as Slave
MASTER SIMO SIMO SLAVE
Px.x STE
SS
STE
Port.x
SOMI SOMI
Receive Shift Register Transmit Shift Register Data Shift Register (DSR)
UCLK SCLK
MSP430 USART COMMON SPI
The master initiates the transfer by sending the UCLK signal. For the master,
data is shifted out of the transmit shift register on one clock edge, and shifted
into the receive shift register on the opposite edge. For the slave, the data
shifting operation is the same and uses one common register for transmitting
and receiving data. Master and slave send and receive data at the same time.
Figures 14–4 and 14–5 show an example of a serial synchronous data transfer
for a character length of seven bits. The initial content of the receive shift
register is 00. The following events occur in order:
A) Slave writes 98h to the data shift register (DSR) and waits for the master
to shift data out.
E) Slave writes 54h to the DSR and waits for the master to shift out data.
F) Master reads 4Ch from the receive buffer UxRXBUF (right justified).
G) Master writes E8h to the transmit buffer UxTXBUF and starts the
transmission.
Note: If USART is in slave mode, no UCLK is needed after D), until G).
However, in master mode, two clocks are used internally (not on UCLK
signal) to end transmit/receive of first character and prepare the
transmit/receive of the next character.
†
C,F: UxRXBUF 0 1 0 0 1 1 0 0 M C,D: DSR 0 1 0 1 1 0 0 0 S
†
H,I: UxRXBUF 0 0 1 0 1 0 1 0 M H,I: DSR 0 1 1 1 0 1 0 0 S
14-6
Synchronous Operation
Px.x STE
SS
STE
Port.x
SOMI SOMI
Data Shift Register DSR Transmit Shift Register Receive Shift Register
The data written to the transmit buffer (UxTXBUF) is moved to the transmit shift
register as soon as the shift register is empty. This initiates the data transfer
on the SIMO pin starting with the most-significant bit. At the same time,
received data is shifted into the receive shift register and, upon receiving the
selected number of bits, the data is transferred to the receive buffer
(UxRXBUF) setting the receive interrupt flag (URXIFG). Data is shifted into the
receive shift register starting with the most-significant bit. It is stored and
right-justified in the receive buffer (UxRXBUF). When previous data is not read
from the receive buffer (UxRXBUF), the overrun error bit (OE) is set.
The protocol can be controlled using the transmit-interrupt flag UTXIFG, or the
receive-interrupt flag URXIFG. By using UTXIFG immediately after sending
the shift-register data to the slave, the buffer data is transferred to the shift
register and the transmission starts. The slave receive timing should ensure
that there is a timely pick-up of the data. The URXIFG flag indicates when the
data shifts out and in completely. The master can use URXIFG to ensure that
the slave is ready to correctly receive the next data.
The signal on STE is used by the active master to prevent bus conflicts with
another master. The STE pin is an input when the corresponding PnSEL bit
(in the I/O registers) selects the module function. The master operates
normally while the STE signal is high. Whenever the STE signal is low, for
example, when another device makes a request to become master, the actual
master reacts such that:
- The pins that drive the SPI bus lines SIMO and UCLK are set to inputs.
- The error bit FE and the interrupt flag URXIFG in registers U0RCTL and
U1RCTL, respectively, are set.
The bus conflict is then removed: SIMO and UCLK do not drive the bus lines,
and the error flag indicates the system integrity violation to the software. Pins
SIMO and UCLK are forced to the input state while STE is in a low state, and
they return to the conditions defined by the corresponding control bits when
STE returns to a high state.
The UCLK pin is used as the input for the serial-shift clock supplied by an
external master. The data-transfer rate is determined by this clock and not by
the internal bit-rate generator. The data, loaded into the transmit shift register
through the transmit buffer (UxTXBUF) before the start of UCLK, is transmitted
on the SOMI pin using the UCLK supplied from the master. Simultaneously,
the serial data applied to the SIMO pin are shifted into the receive shift register
on the opposite edge of the clock.
The receive-interrupt flag URXIFG indicates when the data is received and
transferred into the receive buffer. The overrun-error bit is set when the
previously-received data is not read before the new data is written to the
receive buffer.
In the four-pin SPI mode, the STE signal is used by the slave to enable the
transmit and receive operations. It is applied from the SPI master. The receive
and transmit operations are disabled when the STE signal is high, and enabled
when it is low. Whenever the STE signal becomes high, any receive operation
in progress is halted and then continues when the STE signal is low again. The
STE signal enables one slave to access the data lines. The SOMI is input if
STE is set high.
14-8
Interrupt and Control Functions
The interrupt control bits and flags and enable bits of the USART peripheral
interface are located in the SFR address range. The bit functions are
described below in Table 14–1. See the peripheral-file map in Appendix A for
the exact bit locations.
The USART receiver and transmitter operate in parallel and use the same
baud-rate generator in synchronous master mode. In synchronous slave
mode, the external clock applied to UCLK is used for the receiver and the
transmitter. The receiver and transmitter are enabled and disabled together
with the USPIIE bit.
The receive operation functions identically for three-pin and four-pin modes,
as shown in Figure 14–7, when the MSP430 USART is selected to be the SPI
master.
USPIIE = 1 Receiver
Idle State USPIIE = 1 Handle Interrupt
Receive Collects
(Receiver Conditions
Disable Character
Enabled)
USPIIE = 0
Character
SWRST USPIIE = 1 Received
PUC
USPIIE = 0
The receive operation functions differently for three-pin and four-pin modes
when the MSP430 USART module is selected to be the SPI slave. In the
three-pin mode, shown in Figure 14–8, no external SPI receive-control signal
stops an active receive operation. A PUC signal, a software reset (SWRST),
or a receive/transmit enable (USPIIE) signal can stop a receive operation and
reset the USART.
USPIIE = 1 Receiver
Idle State USPIIE = 1 Handle Interrupt
Receive Collects
(Receive Conditions
Disable External Clock Character
Enabled)
USPIIE = 0 Present
Character
SWRST USPIIE = 1 Received
PUC
USPIIE = 0
In the four-pin mode, shown in Figure 14–9, the external SPI receive-control
signal applied to pin STE stops a started receive operation. A PUC signal, a
software reset (SWRST), or a receive/transmit enable (USPIIE) can stop a
receive operation and reset the operation-control state machine. Whenever
the STE signal is set to high, the receive operation is halted.
14-10
Interrupt and Control Functions
Figure 14–10 shows the transmit-enable activity when the MSP430 is master.
USPIIE = 1
Idle State USPIIE = 1 Handle Interrupt
Transmit Transmission
(Transmitter Conditions
Disable External Clock Active
Enabled)
USPIIE = 0 Present
Character
SWRST USPIIE = 1 Transmitted
PUC
USPIIE = 0
When USPIIE is reset, any data can be written regularly into the transmit
buffer, but no transmission is started. Once the USPIIE bit is set, the data in
the transmit buffer are immediately loaded into the transmit shift register and
character transmission is started.
14-12
Interrupt and Control Functions
URXIE Request_
PE
FE SYNC Interrupt_Service
BRK
URXEIE (S)
URXIFG
URXWIE
Clear
RXWake
SWRST
Character Received PUC
or UxRXBUF Read
Master Overrun USPIIE
IRQA
USPIIE = 0
USPIIE = 1 PUC
Receive Interrupt
USPIIE = 1 and Service Started,
Character URXIFG = 1
Completed GIE = 1 and GIE = 0
Priority Valid URXIFG = 0
Priority
Too GIE = 0
Low
Clear
PUC or SWRST
Request_
Set UTXIFG Interrupt_Service
VCC D Q
The transmit-interrupt enable bit UTXIE controls the ability of the UTXIFG to
request an interrupt, but does not prevent the UTXIFG flag from being set. The
USPIIE is reset with a PUC signal or a SWRST. The UTXIFG bit is set after a
system reset PUC signal or a SWRST, but the USPIIE bit is reset to ensure full
interrupt-control capability.
14-14
Control and Status Registers
Short Register
Register Address Initial State
Form Type
Short Register
Register Address Initial State
Form Type
All bits are random following the PUC signal, unless otherwise noted by the
detailed functional description.
Reset of the USART module is performed by the PUC signal or a SWRST. After
a PUC signal, the SWRST bit remains set and the USART module remains in
the reset condition. It is disabled by resetting the SWRST bit. The SPI mode
is disabled after the PUC signal.
Bit 0: The USART state machines and operating flags are initialized
to the reset condition (URXIFG=USPIIE=0, UTXIFG=1) if the
software reset bit is set. Until the SWRST bit is reset, all affected
logic is held in the reset state. This implies that after a system
reset the USART must be reenabled by resetting this bit.
Note:
The USART initialization sequence should be:
— Initialize per application requirements while leaving SWRST=1
— Clear SWRST
— Enable interrupts if desired.
Bit 1: Master mode is selected when the MM bit is set. The USART
module slave mode is selected when the MM bit is reset.
Bit 3: The listen bit determines the transmitted data to feed back
internally to the receiver. This is commonly called loopback
mode.
Bit 5: Unused
Bit 6: Unused
Bit 7: Unused
14-16
Control and Status Registers
Cycle# 1 2 3 4 5 6 7 8
CKPL CKPH
UCLK
0 0
1 0 UCLK
0 1 UCLK
1 1 UCLK
SIMO/
MSB LSB
x 0 SOMI *
SIMO/
x 1 SOMI * MSB LSB
Data to
TXBUF
Receive
Sample Points
*Previous Data Bit
When operating with the CKPH bit set, the USART (synchronous mode)
makes the first bit of data available after the transmit shift register is loaded and
before the first edge of the UCLK. In this mode, data is latched on the first edge
of UCLK and transmitted on the second edge.
Bit 2: Unused
Bit 3: Unused
Bit 7: Frame error. The FE bit is set when four-pin mode is selected
and a bus conflict stops an active master by applying a negative
transition signal to pin STE. FE is reset by a SWRST, a system
reset, by reading the UxRXBUF, or by an instruction.
14-18
Control and Status Registers
7 0
U0BR1, 075h 215 214 213 212 211 210 29 28
U1BR1, 07Dh
rw rw rw rw rw rw rw rw
The maximum baud rate that can be selected for transmission in master mode
is half of the clock-input frequency of the baud-rate generator. In slave mode,
the rate is determined by the external clock applied to UCLK.
The modulation control register, shown in Figure 14–20, is not used for serial
synchronous communication. It is best kept in reset mode (bits m0 to m7 = 0).
The UTXIFG bit indicates that UxTXBUF is ready to accept another character
for transmission. In master mode, the transmission is initialized by writing data
to UxTXBUF. The transmission of this data is started on the next bit clock if the
transmit shift register is empty.
When seven-bit character-length is used, the data moved into the transmit
buffer must be left-justified since the MSB is shifted out first.
14-20
Chapter 15
Comparator_A
Topic Page
Comparator_A 15-1
Comparator_A Overview
P2CA0 0 1 CAF
CAEX
CAON
0 CA0
0 CAOUT to
Low Pass Filter
CA0 1 Internal Module
1
0 0
+
0 _
CA1 1 1
0 CAOUT to
1 External Pin
CA1 0V
1
3 2 1 0
CAREF
1 2
0 1 0.25 x VCC
VCAREF
3
0V 0V
The input and output pins of Comparator_A are often multiplexed with other
pin functions on the MSP430. Additionally, the internal connections to
Comparator_A can differ among MSP430 devices. The data sheet of a desired
device should always be consulted to determine the specific connection
implementations.
15-2
Comparator_A Description
Note:
Ensure that the comparator input terminals are connected to signal, power,
or ground level. Otherwise, floating levels may cause unexpected interrupts
and current consumption may increase.
Comparator_A 15-3
Comparator_A Description
A comparator output will oscillate if the voltage difference across the input
terminals is small. Internal and external parasitic effects and cross coupling on
and between signal lines, power-supply lines, and other parts of the system
are responsible for this behavior (see Figure 15–2). The comparator output
oscillation reduces accuracy and resolution of the comparison result.
Selecting the output filter can reduce errors associated with comparator
oscillation.
Comparator Output
Unfiltered at CAOUT
Comparator Output
Filtered at CAOUT
15-4
Comparator_A Control Registers
Short Initial
Register Form Register Type Address State
Comparator_A 15-5
Comparator_A Control Registers
7 0
CACTL1 CA CA CA
CAEX CAON CAIES CAIE CAIFG
059h RSEL REF1 REF0
rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0)
15-6
Comparator_A Control Registers
CAOUT, bit0: The comparator output. Writing to this bit, for example
when writing a new register value, has no affect or
negative impact.
CAF, bit1: The comparator output filter is bypassed (CAF=0) or
switched into the output path (CAF=1).
P2CA0,, bit2: Pin to CA0
0: The external, pin signal is not connected to the
Comparator_A
1: The external, pin signal is connected to the
Comparator_A
P2CA1,, bit3: Pin to CA1
0: The external, pin signal is not connected to the
Comparator_A
1: The external, pin signal is connected to the
Comparator_A
Bits 4–7: See device data sheet for implementation.
Comparator_A 15-7
Comparator_A Control Registers
The typical digital I/O ports on MSP430 do not have the ability to disable the
input buffer. However, on devices with the Comparator_A, the capability has
been added and is controlled with the CAPD.x bits.
The control bits CAPD.0 to CAPD.7 are initially reset, enabling all the input
buffers for the associated port. The port input buffer is disabled if the according
CAPD.x bit is set. See device data sheet for port associations.
The ability to disable the input buffer for the device pin applies to up to eight
inputs of the associated digital I/O port (check device data sheet for
implementation details). For example, the ’41x devices have CA1 multiplexed
on pin P1.7 and CA0 multiplexed on pin P1.6, so the Comparator_A is
associated with port P1. On this device, all input buffers associated with all P1
pins (P1.x) may have the capability to be disabled with the CAPD register.
7 0
CAPD
CAPD.7 CAPD.6 CAPD.5 CAPD.4 CAPD.3 CAPD.2 CAPD.1 CAPD.0
05Bh
rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0)
15-8
Comparator_A in Applications
ICC
VI VO
VI
0 VCC
VSS
VI VO ICC
ICC
VI
VCC
0 VCC
CAPD.x = 1 VSS
Disabling the input buffer for a specific pin will disable the parasitic current flow
and therefore reduce overall current consumption. It is important to disable the
buffer for any I/O pin that is not being actively driven if current consumption is
critical (see Figure 15–6).
Comparator_A 15-9
Comparator_A in Applications
Figure 15–6. Application Example With One Active(Driving R3) and Three Passive Pins
With Applied Analog Signals
Control1 = 0
R1
CAPD.x = 0
Control2 = 0
R2
CAPD.x = 0
Control3 = 1
R3
CAPD.x = 0 or 1
Control4 = 0
R4
C
CAPD.x = 1
15-10
Comparator_A in Applications
0 V VCC
0 1
P2CA0 e.g.
R(ref) CAON
0 CAF Capture
R(meas) 0 Input of
CA0 1
0 0 Timer_A
1 +
C 0 _ CAOUT to
0 External Pin
1 1
CA1 1 Set
1
P2CA1 CAIFG
τ ∼ 2 µs
0 V VCC
0 1
CAON
3 2 1 0
CAREF
N meas
R meas + R ref
N ref
Comparator_A 15-11
Comparator_A in Applications
VC
VCC
tref tmeas
Digital I/O:
- Two digital outputs to charge and discharge the capacitor. Port pins are
set to provide a VCC output (charge a capacitor), reset to discharge a
capacitor, and switched to high-impedance (including correct state of
CAPD.x bit) when not in use. One output discharges the capacitor via
reference resistor R(ref), the other output discharges it via R(meas).
Comparator_A:
- The output filter should be used to minimize multiple switching when the
voltages at the comparator inputs are close together.
15-12
Comparator_A in Applications
VCC VCC
0 V VCC
0 1
P2CA0 e.g.
R1(meas) R1(ref) CAEX
CAON CAF
0 Capture
0 Input of
CA0 1
0 0 Timer_A
1 +
C1 0 _ CAOUT to
0 External Pin
1 1
CA11 Set
1
P2CA1 CAIFG
VCC VCC τ ∼ 2 µs
0 V VCC
0 1
CAON
R2(meas) R2(ref) 3 2 1 0
CAREF
C2
CARSEL 0.5 × VCC
0
1 VCAREF 2
0 1 0.25 × VCC
3
Comparator_A 15-13
Comparator_A in Applications
In Figure 15–10, the active signal paths are shown when the upper
independent system is selected for conversion. This example uses the
0.25×VCC internal reference, and shows the software selectable RC-filter as
active.
0 V VCC
0 1
P2CA0 CAEX
R1(meas) R1(ref) CAON e.g.
0 CAF
Capture
0
CA0 1 Input of
1 0 0 Timer_A
+
C1 0 _ CAOUT to
0 External Pin
1 1
CA11 Set
1
P2CA1 CAIFG
VCC VCC τ ∼ 2 µs
0 V VCC
0 1
CAON
R2(meas) R2(ref) 3 2 1 0
CAREF
C2
CARSEL 0.5 × VCC
0
1 VCAREF 2
0 1 0.25 × VCC
3
15-14
Comparator_A in Applications
Figure 15–11 shows the active signal paths for the lower independent system.
This example uses the 0.25×VCC internal reference and shows the software
selectable RC-filter as active.
VCC VCC
0 V VCC
0 1
P2CA0
R1(meas) R1(ref) CAEX CAON e.g.
0 CAF Capture
0 Input of
CA0 1
1 0 0 Timer_A
+
C1 0 _ CAOUT to
0 External Pin
1 1
CA11 Set
1
P2CA1 CAIFG
VCC VCC τ ∼ 2 µs
0 V VCC
0 1
CAON
R2(meas) R2(ref) 3 2 1 0
CAREF
C2
CARSEL 0.5 × VCC
0
1 VCAREF 2
0 1 0.25 × VCC
3
Comparator_A 15-15
Comparator_A in Applications
0 V VCC
0 1
P2CA0 CAEX
CAON e.g.
0 CAF
Capture
0
CA0 1 Input of
1 0 0 Timer_A
+
Signal 0 _ CAOUT to
V 0
Voltage 1 1 External Pin
CA11 Set
1
P2CA1 CAIFG
τ ∼ 2 µs
0 V VCC
Reference 0 1
V
Voltage CAON
3 2 1 0
CAREF
15-16
Comparator_A in Applications
VCC
0 V VCC
0 1
P2CA0 CAEX
CAON e.g.
0 CAF
Capture
0
CA0 1 Input of
1 0 0 Timer_A
+
R(sense) 0 _ CAOUT to
0 External Pin
1 1
CA11 Set
1
P2CA1 CAIFG
τ ∼ 2 µs
Optional
R(hyst) 0 V VCC
0 1
Px.y CAON
3 2 1 0
CAREF
Comparator_A 15-17
Comparator_A in Applications
VCC
0 V VCC
0 1
P2CA0 CAEX
I CAON e.g.
0 CAF
Capture
0
CA0 1 Input of
1 0 0 Timer_A
+
R(sense) 0 _ CAOUT to
0 External Pin
1 1
CA11 Set
1
P2CA1 CAIFG
τ ∼ 2 µs
VCC
0 V VCC
0 1
CAON
R(meas) 3 2 1 0
CAREF
ȡ t 1t )tln 0.5ȣ
I+ 1 V CC ȧ1– e 1 2 ȧ
R(sense)
Ȣ Ȥ
Figure 15–15. Timing for Measuring a Current Source
Vc
VCC
0.5 × VCC
I×R
t1 t2
15-18
Comparator_A in Applications
0 V VCC
P2CA0 0 1
CAEX CAON e.g.
0 CAF
R1 Capture
0
CA0 1 Input of
1 0 0 Timer_A
+
R2 0 _ CAOUT to
0 External Pin
1 1
CA1 1 Set
1
P2CA1 CAIFG
τ ∼ 2 µs
VCC
0 V VCC
0 1
CAON
3 2 1 0
CAREF
0.5 × VCC
VR
t1 t2
Comparator_A 15-19
Comparator_A in Applications
The input offset voltage of the comparator varies with each device and also
with temperature, supply voltage, and input voltage. If the input voltage is
stable (reference voltage), it will not influence the offset voltage significantly.
To increase the precision of voltage measurements, the comparator offset
voltage can be measured by the following steps. To simply compensate for the
offset without measuring it, see Section 15.4.7
Vref
The Voffset in this configuration is in series with Vref as shown in Figure 15–19.
0 V VCC
0 1
CAON e.g.
CAEX CAF
Capture
Input of
0 0 Timer_A
+
_ CAOUT to
1 External Pin
1
Set
VCA0 Vref Voffset
CAIFG
τ ∼ 2 µs
15-20
Comparator_A in Applications
The Voffset in this configuration is in series with VCA0 as shown in Figure 15–21.
Vref = VCA0 + Voffset
VCA0 = Vref – Voffset
V ref ) V offset
N1 + –R VCA0 C ln f osc
V CC
V ref–V offset
N2 + –R VCA0 C ln f osc
V CC
V offset + V CC e
ǒ 2N1
V
N1)N2 ln ref
V
CC –V
Ǔ
ref
N = timer counts
Comparator_A 15-21
Comparator_A in Applications
Adding the result of two conversions (one with each input configuration) and
dividing by two will cancel the effect of the offset voltage.
V CA0 + V ref ) V offset
) V CA0 + V ref * V offset
å N1 ) N2 + Conversion without offset
2
2 V CA0 + 2 V ref
N = Timer count
- The current consumption increases, since the signal path driven by the
comparator output is constantly charged and discharged.
- The software receives constant requests for service either via interrupt
service requests, or after successful polling of CAOUT or CAIFG.
15-22
Comparator_A in Applications
Figure 15–22 shows how to add hysteresis to the comparator to prevent output
oscillation.
Figure 15–22. Use CAOUT at an External Pin to Add Hysteresis to the Reference Level
If Feedback is Possible
0 V VCC
0 1
P2CA0
CAEX CAON e.g.
R1 0 CAF Capture
0 Input of
R2 CA0 1
0 0 Timer_A
1 +
Reference 0 _ CAOUT to
V 0
Voltage 1 External Pin
1
CA11 Set
1
P2CA1 CAIFG
τ ∼ 2 µs
0 V VCC
Signal 0 1
V
Voltage CAON
3 2 1 0
CAREF
V (hyst) +" R2 V CC
R1 ) R2
Comparator_A 15-23
15-24
Chapter 16
This chapter describes the MSP430x4xx liquid crystal display (LCD) driver.
The ’41x devices can control 96 segments, the ’43x devices can control 128
or 160 segments (varies with package option), and the ’44x devices can con-
trol 160 segments. The multiplex rates are 1, 2, 3, and 4. All or most of the LCD
signals are shared at the pin with digital functions.
Topic Page
LCDs with more common planes realize greater pin-count reductions. For
example, a possible pin configuration of a 4-MUX, 16-segment LCD is shown
below. This LCD has 8 total pins for a reduction of 2 pins over the 2-MUX
configuration above. Two pins is generally not significant, however, in the case
of a 128-segment LCD for example, the required pins for a 2-MUX version
would be 66 (128/2 +2), whereas the required pins for a 4-MUX version would
be 36 (128/4 +4).
16-2
LCD Drive Basics
Because of the multiplexing of segments with segment pins, the required drive
signals for the segment pins and common pins can be complicated. Each
segment and common pin of a multiplexed LCD requires a time-division-
multiplexed signal in order to only turn on the desired segments and to avoid
having a dc voltage on any segment. Some examples of segment and
common signals are shown below. Fortunately for the user, the MSP430
creates all these signals automatically.
With static LCDs, each segment pin drives one segment. Figure 16–1 shows
some example waveforms with a typical pin assignment.
COM0 GND
fframe
VDD
SP1 GND
COM0 VDD
SP2 GND
SP1
SP6 a
VDD
b SP2 Resulting Voltage for
Segment a (COM0–SP1), 0V
SP7
Segment Is On.
SP3
–VDD
With 2-MUX LCDs, each segment pin drives two segments (see Figure 16–2).
VDD
SP2
b GND
SP1
VDD
Resulting Voltage for VDD/2
h
Segment h (COM0–SP2), 0V
SP4
SP2 Segment Is On. VDD/2
SP3 –VDD
SP = Segment Pin
VDD
Resulting Voltage for VDD/2
Segment b (COM1–SP2), 0V
Segment Is Off. VDD/2
–VDD
16-4
LCD Drive Basics
VDD
Resulting Voltage for
Segment c (COM1–SP2), 0V
Segment Is On.
–VDD
16-6
LCD Controller/Driver
Segment S39†
Seg 39
Mux DCTL Segment S38†
Group 7
Display Segment
Memory Output
20x8 Bit Control
Seg 2
Mux DCTL
Group 1
Mux Seg 1
Segment S1
Mux Seg 0
Segment S0
ADR
091h–0A4h
Group 1–7
LCD 7
Control LCDM2 Group1–7 COM3
Common
and 7 COM2
Output
Mode Group 1–7 COM1
Control
Register COM0
PUC ADR: 90h
LCDM0
LCDM3
LCDM4
LCDM1 R33
R23
Analog Voltage
Multiplexer R13
R03
Timing Generator
fLCD
OscOff
† The maximum number of segments lines available on devices’ pins may be different:
’41x device: S0 to S23
’43x device: S0 to S31 (80-pin package) or S0 to S39 (100-pin package)
’44x device: S0 to S39
- Display memory
J Static
J 2 MUX, 1/2 bias
J 3 MUX, 1/3 bias
J 4 MUX, 1/3 bias
- Operates using the basic timer with the auxiliary clock (ACLK).
16-8
LCD Controller/Driver
When pins R33 and R03 are not preset, voltage V1 is tied to VCC and voltage
V5 is tied to VSS internally. When these pins are present, they provide two
advantages to the user. First, R33 is a switched-VCC output. This allows the
power to the resistor ladder to be turned off reducing current consumption.
Also, when these pins are present, R03 is not tied internally to VSS. This allows
the user to control the offset of the LCD voltages, thereby providing for
temperature compensation or contrast adjustment. If this not desired, the user
may simply connect R03 to VSS.
R23
V2 (R23
open Open)
V3 R R
Analog MUX
R13
V4 open
R R
LCD Phases
LCDM0 R03‡
LCDM3 V5 VSS
LCDM4
OscOff
Digital outputs are standard port outputs. LCD segments, common lines, and
the analog level pins (R33...R03) may be shared with digital port functions.
See the device data sheet.
Note:
After a PUC, shared LCD/port pins are configured as port function, input di-
rection, and are high impedence.
16-10
LCD Controller/Driver
The primary function of the LCDM2 bit is to support flashing or blinking the
LCD. The LCDM2 bit is logically ANDed with each segment’s display memory
value to turn each LCD segment on or off (see Figure 16–8). When LCDM2=1,
each LCD segment is on or off according to the LCD display memory. When
LCDM2=0, each LCD segment is off, therefore blanking the LCD.
Figure 16–8. Information Control
Segment
Information To Output Control
LCDM2
LCDM5 to 7: These three bits select groups of outputs to be used for LCD
segment drive or as port function (general-purpose I/O), as
described in Table 16–2. The pins selected as
general-purpose I/O function as discussed in Chapter 8 and
no longer function as part of the LCD segment lines
LCDM7 LCDM6 LCDM5 Segment Group0 Group1 Group2 Group3 Group4 Group5 Group6 Group7
Function
0 0 0 Port only 0 0 0 0 0 0 0 0 ←reset
condition
0 0 1 S0–S15 1 0 0 0 0 0 0 0
0 1 0 S0–S19 1 1 0 0 0 0 0 0
0 1 1 S0–S23 1 1 1 0 0 0 0 0
1 0 0 S0–S27 1 1 1 1 0 0 0 0
1 0 1 S0–S31 1 1 1 1 1 0 0 0
1 1 0 S0–S35 1 1 1 1 1 1 0 0
1 1 1 S0–S39 1 1 1 1 1 1 1 0
Figure 16–9. Display Memory Bits Attached to Segment Lines in ’4xx Family
Associated 3 2 1 0 3 2 1 0
Common Pin Associated ’4xx
Address Segment Line
7 0 n
0A4h -- -- -- -- -- -- -- -- 38 39, 38
0A3h -- -- -- -- -- -- -- -- 36 37, 36
0A2h -- -- -- -- -- -- -- -- 34 35, 34
0A1h -- -- -- -- -- -- -- -- 32 33, 32
0A0h -- -- -- -- -- -- -- -- 30 31, 30
09Fh -- -- -- -- -- -- -- -- 28 29, 28
09Eh -- -- -- -- -- -- -- -- 26 27, 26
09Dh -- -- -- -- -- -- -- -- 24 25, 24
09Ch -- -- -- -- -- -- -- -- 22 23, 22
09Bh -- -- -- -- -- -- -- -- 20 21, 20
09Ah -- -- -- -- -- -- -- -- 18 19, 18
099h -- -- -- -- -- -- -- -- 16 17, 16
098h -- -- -- -- -- -- -- -- 14 15, 14
097h -- -- -- -- -- -- -- -- 12 13, 12
096h -- -- -- -- -- -- -- -- 10 11, 10
095h -- -- -- -- -- -- -- -- 8 9, 8
094h -- -- -- -- -- -- -- -- 6 7, 6
093h -- -- -- -- -- -- -- -- 4 5, 4
092h -- -- -- -- -- -- -- -- 2 3, 2
091h -- -- -- -- -- -- -- -- 0 1, 0
Sn+1 Sn
16-12
LCD Controller/Driver
The static drive mode uses one common line, COM0. In this mode, only bit 0
and bit 4 are used for segment information. The other bits can be used like any
other memory.
f g b f g b f g b f g b
e c e c e c e c
d h d h d h d h
16-14
LCD Controller/Driver
f g b f g b
e c e c
d h d h
DIGIT8 DIGIT1
16-16
LCD Controller/Driver
f g b f g b
e c e c
d h d h
DIGIT10 DIGIT1
The four-MUX drive mode uses all four common lines. In this mode, bits 0
through 7 are used for segment information.
LCD
a a
f g b f g b
e c e c
d h d h
DIGIT15 DIGIT1
Connections COM 3 2 1 0 3 2 1 0
’430 Pins LCD Pinout
PIN COM0 COM1 COM2 COM3 MAB 09Fh a b c h f g e d n = 30 Digit 16
S0 1 1d 1e 1g 1f 09Eh a b c h f g e d 28 Digit 15
S1 2 1h 1c 1b 1a a b c h f g e d 26 Digit 14
09Dh
S2 3 2d 2e 2g 2f
09Ch a b c h f g e d 24 Digit 13
S3 4 2h 2c 2b 2a
S4 5 3d 3e 3g 3f a b c h f g e d 22 Digit 12
09Bh
S5 6 3h 3c 3b 3a a b c h f g e d 20 Digit 11
S6 7 4d 4e 4g 4f 09Ah
a b c h f g e d 18 Digit 10
S7 8 4h 4c 4b 4a 099h
S8 9 5d 5e 5g 5f a b c h f g e d 16 Digit 9
098h
S9 10 5h 5c 5b 5a a b c h f g e d 14 Digit 8
S10 11 6d 6e 6g 6f 097h a b c h f g e d 12 Digit 7
S11 12 6h 6c 6b 6a
096h a b c h f g e d 10 Digit 6
S12 13 7d 7e 7g 7f
S13 14 7h 7c 7b 7a 095h a b c h f g e d 8 Digit 5
S14 15 8d 8e 8g 8f 094h a b c h f g e d 6 Digit 4
S15 16 8h 8c 8b 8a
S16 17 9d 9e 9g 9f 093h a b c h f g e d 4 Digit 3
S17 18 9h 9c 9b 9a 092h a b c h f g e d 2 Digit 2
S18 19 10d 10e 10g 10f
091h a b c h f g e d 0 Digit 1
S19 20 10h 10c 10b 10a
S20 21 11d 11e 11g 11f
S21 22 11h 11c 11b 11a 3 2 1 0 3 2 1 0
12f A 0 0 A Parallel-
S22 23 12d 12e 12g
G G Serial
S23 24 12h 12c 12b 12a B 3 3 B Conversion
S24 25 13d 13e 13g 13f
S25 26 13h 13c 13b 13a
S26 27 14d 14e 14g 14f
S27 28 14h 14c 14b 14a Sn+1 Sn
S28 29 15d 15e 15g 15f
S29 30 15h 15c 15b 15a
COM0 31 COM0
COM1 32 COM1
COM2 33 COM2
COM3 34 COM3
16-18
Code Examples
...........
...........
;
Table DB a+b+c+d+e+f ; displays ”0”
DB b+c; ; displays ”1”
...........
...........
DB
...........
16-20
Code Examples
16-22
Chapter 17
ADC12
Topic Page
ADC12 17-1
Introduction
17.1 Introduction
The ADC12 12-bit analog-to-digital converter (shown in Figure 17–1) has five
main functional blocks that can be individually configured and optimized:
- ADC core with sample-and-hold
- Conversion memory and configuration
- Reference voltage and configuration
- Conversion clock source select and control
- Sample timing and conversion control
VREF+ VREF+ on on
AVCC
VREF– / Ve REF– 1.5V or 2.5V Reference
Ref_X
ADC12CTLx.0..3 AVSS AVCC
AVSS Internal
ADC12SSEL
a0 Oscillator
ADC12ON ADC12DIV
a1 ADC12CTLx.4..6 ADC12OSC
a2
a3 ADC12CLK Divide by ACLK
VR– VR+
a4 Analog 1,2,3,4,5,6,7,8 MCLK
Multiplexer Sample
a5 12–bit A/D converter core SHT0 SMCLK
and
12 : 1 SHT1
a6 Hold
a7 SHP
S/H ISSH ADC12SC
a8 Sampling
The ADC12 can convert one of eight external analog inputs, or one of four
internal voltages. The four internal channels are used for temperature
measurement (via on-chip temperature diode), and for measurement of Vcc
(via Vcc/2) and the positive and negative references applied on VeREF+ and
VREF–/VeREF–.
The ADC12 can use its internal reference, or it can use external reference(s)
or a combination of internal and external reference-voltage levels.
17-2
Introduction
The ADC12 has versatile sample-and-hold circuitry giving the user many
options for control of the sample timing. The sample timing may be directly
controlled by software (via a control bit), or any one of three internal or external
signals (depending on device configuration—see the Sampling section and
check the data sheet for details). Typically, the internal timing signals come
from other MSP430 timers such as Timer_A. Additionally, the sample timing
may be programmed as a multiple of the ADC12 conversion clock.
As with sample timing, the user has several choices for the ADC12 conversion
clock. The ADC12 conversion clock may be chosen from any available internal
MSP430 clock, or may be selected from a dedicated oscillator contained in the
ADC12 peripheral. Additionally, the chosen clock source may be divided by
any factor from 1 to 8.
The ADC12 has four operating modes. It can be configured to perform a single
conversion on a single channel, or multiple conversions on a single channel.
The ADC12 can also be configured to perform conversions on a sequence-of-
channels, running through the sequence once, or repeatedly. When
performing conversions on a sequence-of-channels, the sequence is
completely definable by the user. For example, a possible sequence-of-
channels could be a1–a3–a1–a6–a2, etc. In addition, each channel may be
individually configured for which reference(s) are to be used for the
conversion.
- 12-bit converter with ±1LSB differential nonlinearity (DNL) and ±1LSB in-
tegral nonlinearity (INL)
ADC12 17-3
ADC12 Description and Operation
a0 from Reference
ADC12ON
a1
a2
a3 VR– VR+
ADC12CLK
a4
Sample
a5 and 12–bit A/D converter core
Analog Hold
a6 Multiplexer
a7 12 : 1
S/H
VeREF+ a8
SAMPCON
VeREF–/ a9
VREF–
a10
Temperature SAR
a11
AVCC/2
to ADC12MEMx
It is important to note that the 3 LSBs of the conversion are resolved resistively.
Therefore, when the 3 LSBs are being resolved during a conversion,
approximately 200 µA will be required from the reference. The user should
keep this in mind when choosing and decoupling an external reference. Refer
to the device data sheet for more details on ADC12 specifications.
17-4
ADC12 Description and Operation
When the ADC12 is turned on with the ADC12ON bit, the turnon
time noted in the data sheet (tADC12ON) must be observed before a
conversion is started. Otherwise, the results will be false.
17.2.2 Reference
The ADC12 A/D converter contains a built-in reference with two selectable
reference-voltage levels (1.5 V and 2.5 V). Either of these reference voltages
may be applied to VR+ of the A/D core and also may be available externally on
pin VREF+ (check device data sheet for availability of VREF+ pin). Additionally,
an external reference may be supplied for VR+ through pin VeREF+ (check data
sheet for availability of VeREF+ pin).
Configuration of the reference voltage(s) is done with the Sref bits (bits 4, 5,
and 6) in the ADC12MCTLx registers. Up to six combinations of positive and
negative reference voltages are supported as described in Table 17–1.
The voltage levels VR+ and VR– establish the upper and lower limits of the
analog inputs to produce a full-scale and zero-scale reading, respectively. The
values of VR+, VR–, and the analog input should not exceed the positive supply
or be lower than AVSS, consistent with the absolute maximum ratings specified
in the device data sheet. The digital output is full scale when the input signal
is equal to or higher than VR+, and zero when the input signal is equal to or
lower than VR–.
ADC12 17-5
Analog Inputs and Multiplexer
When the built-in reference is turned on with the VREFON bit, the
settling timing noted in the data sheet must be observed before
starting a conversion. Otherwise, the results will be false until the
reference settles. Once all internal and external references have
settled, no additional settling time is required when selecting or
changing the conversion range for each channel.
Input
ESD protection
17-6
Analog Inputs and Multiplexer
Additionally, source impedances also affect the accuracy of the converter. The
source signal can drop at the input of the device due to leakage current or
averaged dc-input currents (due to input switching currents). For a 12-bit
converter, the error in LSBs due to leakage current is:
Error(LSBs) = 4.096 x (µA of leakage current) × (kΩ of source
resistance)/(VR+ – VR–)
For example, a 50-nA leakage current with a 10-kΩ source resistance and a
1.5-V VREF gives 1.4 LSBs of error.
These errors due to source impedance also apply to the output impedance of
any external-voltage reference source applied to VeREF+. The output
impedance must be low enough to enable the transients to settle within
0.2/ADCLK and generate leakage current induced errors of <<1LSB.
See the Sampling section for more details on sample timing and sampling con-
siderations.
See the device data sheet for the temperature diode specifications.
ADC12 17-7
Conversion Memory
17-8
Conversion Modes
- Single-channel, single-conversion
- Single-channel, repeated-conversions
- Sequence-of-channels, single-sequence
- Sequence-of-channels, repeated-sequence
Each mode is summarized in Table 17–2 and described in detail in the follow-
ing sections.
Repeat single channel 10 The conversion of one single channel is permanently repeated until repeat is off or
ENC is reset
x = CstartAdd; points to the conversion start address
Result is in ADC12MEMx; interrupt flag is ADC12IFG.x
Channel (INCH) and reference voltage (Sref) are selected in ADC12MCTLx
ADC12 17-9
Conversion Modes
ENC
SAMPCON
Operational Mode Sample Period Conversion Period Sample Period Conversion Period
ENC is reset before conversion period is completed: ENC is reset after conversion period is completed:
no conversion executed or unreliable conversion result. conversion is executed regularly.
Sample-and-conversion (SAMPCOM) signal can be reset Sample-and-conversion (SAMPCOM) signal can be reset
and conversion started when appropriate. and conversion started when appropriate.
ENC
SAMPCON
Operational Mode Sample Period Conversion Period Sample Period Conversion Period
ENC is reset before conversion period is completed: ENC is reset after conversion period is completed:
no conversion executed or unreliable conversion result. conversion is executed regularly.
Sample-and-conversion (SAMPCOM) signal can be reset Sample-and-conversion (SAMPCOM) signal can be reset
and conversion started when appropriate. and conversion started when appropriate.
When the conversion is complete and the results are written to the selected
conversion-memory register, the corresponding interrupt flag ADC12IFG.x is
set, and, if the appropriate interrupt enables are set, an interrupt request is
generated (see the ADC12 Interrupt Vector Register ADC12IV section).
The conversion mode may be changed after the conversion begins but before
it has completed, and the new mode will take effect after the current conversion
has completed. See also the Switching between Conversion Modes section.
17-10
Conversion Modes
CONSEQ = 0
ADC12
Off
ENC =
ADC12ON = 1
x = CStartAdd
Wait for Enable
ENC =
SHS = 0
and ENC =
ENC = 1 or
and
ADC12SC = Wait for Trigger
ENC = 0 SAMPCON =
SAMPCON = 1
Sample, Input
Channel Defined in
ADC12MCTLx
ENC = 0†
SAMPCON =
< 12 x ADC12CLK
Convert, Use
12 x ADC12CLK
ENC = 0†
1 x ADC12CLK
Conversion
Completed,
Result Stored Into
ADC12MEMx,
ADC12IFG.x Is Set
ADC12 17-11
Conversion Modes
16 x 12–bit 16 x 8–bit
ADC Memory ADC Memory Controls
17-12
Conversion Modes
If the conversion mode is changed after the sequence begins but before it has
completed and the ENC bit is left high, the sequence completes normally, and
the new mode takes effect after the sequence completes, unless the new
mode is single-channel single-conversion. If the new mode is single-channel
single-conversion, the current sequence-of-channels stops proceeding when
no sample-and-conversion is active, or after an active sample-and-conversion
is completed. The original sequence may not be completed, but all completed
conversion results are valid. See also the Switching Between Conversion
Modes section.
If the conversion mode is changed after the sequence begins, but before it has
completed, and the ENC bit is toggled, then the original sequence completes
normally and the new mode takes effect and is started after the original
sequence completes – unless the new mode is single-channel
single-conversion. If the new mode is single-channel single-conversion, then
the original sequence stops when no sample-and-conversion is active, or after
an active sample-and-conversion is completed, or when the ENC bit is reset,
whichever comes first. Then, the single conversion begins when the ENC bit
is set again. See also the Switching Between Conversion Modes section.
ENC
SAMPCON
Sample Conversion Sample Conversion Sample Conversion Sample Conversion Sample Conversion
Single Conversion Single Conversion Single Conversion Single Conversion Single Conversion
Time Time Time Time Time
Single Period Single Period Single Period Single Period
of Sequence of Sequence of Sequence of Sequence
Period of Sequences Next Period of Sequences
First +SAMPCON with ADC12SC reset ADC12SC set ADC12SC reset ADC12SC set ADC12SC reset
ENC set start S&C starts conversion starts sampling starts conversion starts sampling starts conversion
ENC
SAMPCON
Sample Conversion Sample Conversion Sample Conversion Sample Conversion Sample Conversion
Single Conversion Single Conversion Single Conversion Single Conversion Single Conversion
Time Time Time Time Time
Single Period Single Period Single Period Single Period
of Sequence of Sequence of Sequence of Sequence
Period of Sequences Next Period of Sequences
Each time a conversion is completed, the results are loaded into the
appropriate ADC12MEMx register and the corresponding interrupt flag
ADC12 17-13
Conversion Modes
CONSEQ = 1 ADC12
Off
ADC12ON = 1
ENC =
x = CStartAdd
Wait for Enable
ENC =
SHS = 0
and ENC =
ENC = 1 or
and
ADC12SC = Wait for Trigger
SAMPCON = EOS.x = 1
SAMPCON = 1
Sample, Input
Channel Defined in
If x < 15 then x = x + 1 ADC12MCTLx If x < 15 then x = x + 1
else x = 0 else x = 0
SAMPCON =
< 12 x ADC12CLK
MSC = 1
and Convert, Use (MSC = 0
SHP = 1 12 x ADC12CLK or
and SHP = 0)
EOS.x = 0 and
1 x ADC12CLK EOS.x = 0
Conversion
Completed,
Result Stored Into
ADC12MEMx,
ADC12IFG.x Is Set
17-14
Conversion Modes
SAMPCON
Define basic conversion conditions Sample Conversion
via control registers ADC12CTL0/1
x = 6 ( CStartAdd = 6 )
Sample and convert channel
using ADC12MCTLx, and store
conversion result in ADC12MEMx
No
Yes
ENC 0 →1
Stop conversion sequence
ADC12 17-15
Conversion Modes
17-16
Conversion Modes
CONSEQ = 2 ADC12
Off
ADC12ON = 1
ENC =
x = CStartAdd
Wait for Enable
ENC =
SHS = 0
and ENC =
ENC = 1 or
and
ADC12SC = Wait for Trigger
SAMPCON = ENC = 0
SAMPCON = 1
Sample, Input
Channel Defined in
ADC12MCTLx
SAMPCON =
< 12 x ADC12CLK
MSC = 1
and Convert, Use (MSC = 0
SHP = 1 12 x ADC12CLK or
and SHP = 0)
ENC = 1 and
1 x ADC12CLK ENC = 1
Conversion
Completed,
Result Stored Into
ADC12MEMx,
ADC12IFG.x Is Set
ADC12 17-17
Conversion Modes
2) Reset ENC bit (ADC12CTL0.1). This stops the conversions after the
current sequence is completed. The conversion results of all conversions
in the sequence are stored in their appropriate ADC12MEMx register and
the associated interrupt flags ADC12IFG.x are set.
17-18
Conversion Modes
CONSEQ = 3 ADC12
Off
ADC12ON = 1
ENC =
x = CStartAdd
Wait for Enable
ENC =
SHS = 0
and ENC =
ENC = 1 or
and
ADC12SC = Wait for Trigger
SAMPCON = ENC = 0
and
SAMPCON = 1 EOS.x = 1
Sample, Input
Channel Defined in If EOS.x = 1 then x = CStartAdd
ADC12MCTLx else {if x < 15 then x = x + 1
else x = 0}
SAMPCON =
If EOS.x = 1 then x = CStartAdd < 12 x ADC12CLK
else {if x < 15 then x = x + 1
else x = 0} Convert, Use (MSC = 0
12 x ADC12CLK or
SHP = 0)
MSC = 1
and
and
1 x ADC12CLK (ENC = 1
SHP = 1
Conversion or
and
Completed, EOS.x = 0)
(ENC = 1
or Result Stored Into
EOS.x = 0) ADC12MEMx,
ADC12IFG.x Is Set
ADC12 17-19
Conversion Modes
Therefore, the following mode changes should be avoided while the converter
is running: 0 → 3, 1 → 2, 2 → 1, and 3 → 0.
The intermediate modes are caused by the asynchronous clocks for the CPU
and the ADC12. These intermediate modes can be avoided simply by
changing only one CONSEQ bit per instruction. For example, to change from
mode 0 to mode 3 while the converter is actively running, the following
instructions could be used:
BIS #CONSEQ_0,&ADC12CTL1 ; Example: 0 → 3, first
................................ ; step is 0 → 1
BIS #CONSEQ_1,&ADC12CTL1 ... ; second step is 1 → 3
Caution!
Do not power-down the converter or the reference generator while
the converter is active. Conversion results will be false.
17-20
Conversion Clock and Conversion Speed
Caution!
The following must be considered when turning the ADC12 and
voltage reference on or off.
ADC12 turnon time: when the ADC12 is turned on with the
ADC12ON bit, the turnon time noted in the data sheet (tADC12ON)
must be observed before a conversion is started. Otherwise, the
results will be false.
Reference-voltage settling Time: When the built-in reference is
turned on with the VREFON bit, the settling timing noted in the data
sheet must be observed before a conversion is started. Otherwise,
the results will be false until the reference settles. Once all internal
and external references have settled, no additional settling time is
required when selecting or changing the conversion range for each
channel.
Settling time of external signals: external signals must be settled
before performing the first conversion after turning on the ADC12.
Otherwise, the conversion results will be false.
The internal oscillator generates the ADC12OSC signal and is in the 5-MHz
range (see device data sheet for specifications). The internal-oscillator
frequency will vary with individual devices, supply voltage, and temperature.
A stable clock source should be used for the conversion clock when accurate
conversion timing is required.
to Sample&Hold
ADC12 17-21
Sampling
The conversion starts with the falling edge of the sample signal SAMPCON
(see the Sampling section and Figure 17–14). Thirteen conversion clocks
(ADC12CLK) are required to complete a conversion. The conversion time is:
tconversion = 13 × (ADC12DIV/fADC12CLK )
17.7 Sampling
The ADC12 sample-and-hold (S/H) circuitry (shown in Figure 17–14) is flex-
ible and configurable. The configuration is done by software via control bits in
the ADC12CTL0 and ADC12CTL1 registers. Configuration and operation of
the S/H circuitry is discussed in this section.
Internal
ADC12SSEL
Oscillator
ADC12ON ADC12DIV
ADC12OSC
SHS
The sample-and-hold circuitry samples the analog signal when the sampling
signal SAMPCON (see Figure 17–14) is high. Conversion starts immediately
with the falling edge of SAMPCON. The sample-and-hold holds the signal
value when SAMPCON is low. Conversion takes 13 ADC12CLK cycles (see
Figure 17–15).
17-22
Sampling
SAMPCON
Conversion
Sample
and Hold
The analog input signal must be valid and steady during the sampling period
in order to obtain an accurate conversion. It is also desirable not to have any
digital activity on any adjacent channels during the whole conversion period
to ensure that errors due to supply glitching, ground bounce, or crosstalk do
not corrupt the conversion results.
In addition, gains and losses in internal charge limit the hold time. The user
should ensure that the data sheet limits are not violated. Otherwise, the
sampled analog voltage may increase or decrease, resulting in false conver-
sion values.
The sample-signal input is selected by the SHS bits in ADC12CTL1. There are
four choices for the sample-signal input: ADC12SC, Timer_A.OUT1,
Timer_B.OUT0, and Timer_B.OUT1. The polarity of the sample-signal input
may be selected by the ISSH bit (see Figure 17–16). Also, the sample-signal
input is passed to the sampling timer or to the SAMPCON signal under control
of the ENC bit. This is discussed in detail further ahead.
ADC12 17-23
Sampling
Figure 17–16. Synchronized Sample and Conversion Signal With Enable Conversion
Enable Conversion
ENC t ENC
Sample-Signal
Input
t ssync t esync
SHI
Sample and conversions
Trigger signal enabled
In the pulse-sample mode, the sample-input signal, selected by the SHS bits,
triggers the sampling timer with its rising edge. The sampling timer then
generates the sample timing. The sampling time is programmable by the
SHT0 or SHT1 bits located in ADC12CTL0. When conversion-memory
registers ADC12MEM0 to ADC12MEM7 are selected to store the conversion
result(s), the SHT0 bits are used to program the sampling time. When
conversion-memory registers ADC12MEM8 to ADC12MEM15 are selected
for the conversion data, the SHT1 bits are used to program the sampling
timing. Therefore, it is possible to program two different sampling times for a
sequence of conversions by using both upper and lower conversion-memory
registers in the sequence. This feature is useful when different external-source
impedance conditions exist and require different sample timings.
17-24
Sampling
The sampling signal SAMPCON remains in the sampling state (high) for the
synchronization time tsync and the selected sample time tsample, as shown in
Figure 17–17. The conversion takes 13 × ADC12CLK cycles (tconvert). It is im-
portant to note that after a sample-and-conversion cycle has been triggered
by the sample-input signal, additional triggers (via a rising edge on the sample-
input signal) will be missed/ignored until the prior sample-and-conversion
cycle is completed.
SAMPCON
ADC12CLK
t sample t convert
t sync
ADC12CLK
VR– VR+ Divider by ACLK
SHS
ADC12 17-25
Sampling
SAMPCON
ADC12CLK
tsample tconvert Next sync and sample
tsync
In extended-sample mode, the input signal selected by the SHS bits is used
to control the sampling (SAMPCON signal) directly. The internal sampling
timer is not used. As shown in Figure 17–20, the sampling period is active while
SAMPCON is high. Hold mode is active when SAMPCON is low. The
conversion starts with the falling edge of SAMPCON after a synchronization
time tsync. The conversion takes 13 × ADC12CLK (tconvert).
SAMPCON
ADC12CLK
t sample t convert
t sync
The extended-sample mode allows total control of the sampling period and the
start of a conversion. The extended-sample mode is useful in applications that
require an extended sampling period to accommodate different input-source
impedances, or in applications where the maximum sampling period supplied
by the internal sampling timer is insufficient.
17-26
Sampling
SHP
S/H ISSH ADC12SC
Sampling
SAMPCON Timer Timer_A.OUT1
SYNC
Timer_B.OUT0
SHI
Timer_B.OUT1
MSC
ENC
12–bit S A R Conversion CTL
SHS
Timer_B.OUT0
ADC12CLK
t sample t convert
t sync
If MSC = 0, then a rising edge of the SHI signal is required to trigger each
sample-and-conversion, regardless of what mode the converter is in. When
MSC = 1 and CONSEQ > 0, the first rising edge of the SHI signal triggers the
first conversion, but successive conversions are triggered automatically as
soon as the prior conversion is completed. Additional rising edges on SHI are
ignored until the sequence is completed or until the ENC bit is toggled
(depending on mode). The function of the ENC bit is unchanged when using
the MSC bit. See Figures 17–23 and 17–24.
ADC12 17-27
Sampling
ENC
SHI
1 2 3 4 Sequence of
SAMPCON MSC = 0
Channel
S/C S/C S/C S/C S/C S/C
1 2 3 4 1 2 3 4 Sequence of
MSC = 1
SAMPCON Channel
S/C S/C S/C S/C S/C S/C S/C S/C
S/C
Conversion Period
Sample Period
ENC
SHI
Repeat Single
SAMPCON MSC = 0
Channel
S/C
Repeat Single
SAMPCON MSC = 1
Channel
S/C S/C S/C S/C S/C S/C S/C S/C S/C S/C S/C S/C S/C
1 2 3 1 2 3 1 Repeat Sequence
MSC = 0
SAMPCON of Channel
S/C S/C S/C S/C
1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 Repeat Sequence
MSC = 1
of Channels
S/C S/C S/C S/C S/C S/C S/C S/C S/C S/C S/C S/C S/C S/C S/C S/C
S/C
Conversion Period
Sample Period
17-28
Sampling
It is imperative that the proper sample timing be used for accurate conver-
sions. The next section discusses how to calculate the sample timing.
MSP430
VI = Input voltage at pin Ax
Rs Zi VS = External driving-source voltage
VI
VS VC Rs = Source resistance (must be real at input frequency)
Zi = Input resistance (MUX-on resistance)
Ci Ci = Input capacitance
VC= Capacitance-charging voltage
V
C
+V ǒ ǒ
S
1–EXP
Rt
–tc
C
ǓǓ
i
(1)
Where:
Rt = Rs + Zi
tc = Cycle time
The input impedance Zi is ~1 kΩ at 3.0 V, and is higher (~ 2 kΩ) at 1.8 V. The
final voltage to 1/2 LSB is given by:
V
C
(1ń2LSB) + V –
V
S
S 8192
ǒ Ǔ (2)
V –
V
S
S 8192
ǒ Ǔ ǒ +V
S
1–EXP ǒ Rt
–tc
C
ǓǓ
i
(3)
ADC12 17-29
ADC12 Control Registers
and the time to charge to 1/2 LSB (minimum sampling time) is:
tch(1/2 LSB) = Rt x Ci x In(8192)
Where:
In(8192) = 9.011
Therefore, with the values given, the time for the analog input signal to settle
is:
tch(1/2 LSB) = Rt × Ci × 9.011 (4)
ADC interrupt flag register ADC12IFG Read/write 01A4h Reset with POR
ADC interrupt enable register ADC12IE Read/write 01A6h Reset with POR
ADC interrupt vector word ADC12IV Read 01A8h Reset with POR
Note: All registers may be accessed by any instruction subject to register-access restrictions.
17-30
ADC12 Control Registers
ADC12SC bit0 Sample and convert. The ADC12SC bit can be used to control the
conversion with software if ENC is set. It is recommended to have ISSH=0.
If the sampling signal SAMPCON is generated by the sampling timer
(SHP=1), changing the ADC12SC bit from 0 to 1 starts the sample-and-
conversion operation. When the A/D conversion is complete (BUSY=0) the
ADC12SC bit is automatically reset.
If the sample signal is directly controlled by ADC12SC (SHP=0), then the
high level of the ADC12SC bit defines the sample time. The conversion
starts once it is reset.
All automatic-sequence functions (CONSEQ={1,2,3}) and multiple sample-
and-conversion functions (MSC=1) are executed normally. Therefore, when
using ADC12SC the software must ensure that the frequency of the timing
of the ADC12SC bit meets the applicable timing requirements.
NOTE: The start of a conversion by software (SHS=0, in ADC12CTL1) is
possible by setting both ENC and ADC12SC control bits within one
instruction.
ENC bit1 Enable conversion. The software (via ADC12SC) or external signals can
start a conversion only if the enable-conversion bit ENC is high. Most of the
control bits in ADC12CTL0 and ADC12CTL 1, and all bits in ADCMCTL.x
may be changed only if ENC is low.
0 : No conversion can be started. This is the initial state.
1 : The first sample and conversion starts with the first rising edge of the
SAMPCON signal. The selected operation proceeds as long as ENC is set.
CONSEQ=0, ADC12BUSY=1, ENC= 1→ 0:
In this mode, if ENC is reset, the current conversion is immediately stopped.
The conversion results are unpredictable.
CONSEQ≠0, ADC12BUSY=x, ENC= 1→ 0:
In these modes, if ENC is reset, the current conversion or sequence is
completed and the conversion results are valid. The conversion activities
are stopped after the current conversion or sequence is completed.
ADC12 17-31
ADC12 Control Registers
17-32
ADC12 Control Registers
SHT0 bits Sample-and-hold Time0. These bits define the sample timing for
8–11 conversions whose results are stored in conversion-memory registers
ADC12MEM0 to ADC12MEM7.
The sample time is a multiple of the ADC12CLK × 4:
tsample = 4 × tADC12CLK × n
SHT0 0 1 2 3 4 5 6 7 8 9 10 11 12–15
n 1 2 4 8 16 24 32 48 64 96 128 192 256
SHT1 bits Sample-and-hold Time1. These bits define the sample timing for
12–15 conversions whose results are stored in conversion-memory registers
ADC12MEM8 to ADC12MEM15.
The sample time is a multiple of the ADC12CLK × 4:
tsample = 4 × tADC12CLK × n
SHT1 0 1 2 3 4 5 6 7 8 9 10 11 12–15
n 1 2 4 8 16 24 32 48 64 96 128 192 256
15 8 7 0
ADC12CTL1 ADC12
CSStartAdd SHS SHP ISSH ADC12DIV ADC12SSEL CONSEQ
BUSY
01A2h
rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) r –(0)
ADC12BUSY bit0 The ADC12BUSY bit indicates an active sample or conversion operation. It
is used specifically when the conversion mode is single-channel-
single-conversion, because if the ENC bit is reset in this mode, the
conversion stops immediately and the results are invalid. Therefore, the
ADC12BUSY bit should be tested to verify that it is 0 before resetting the
ENC bit when in single-channel-single-conversion mode.
The busy bit is not useful in all other operating modes because resetting the
ENC bit does not immediately affect any other mode.
0: No operation is active.
1: A sample period, conversion or conversion sequence is active.
CONSEQ bits The CONSEQ bits select the conversion mode. Repeat mode is on if the
1–2 CONSEQ.1 is set.
0: Single-channel-single-conversion mode. One single channel is
converted once.
1: Sequence-of-channels mode. A sequence of conversions is executed
once.
2: Repeat-single-channel mode. Conversions on a single channel are
repeated until CONSEQ is set to 0 or 1.
3: Repeat-sequence-of-channels. A sequence of conversions is repeated
until CONSEQ is set to 0 or 1.
NOTE: See also section Conversion Modes.
ADC12 17-33
ADC12 Control Registers
ADC12SSEL bits Select the clock source for the converter core
3–4
0: ADC12 internal oscillator, ADC12OSC
1: ACLK
2: MCLK
3: SMCLK
ADC12DIV bits Select the division rate for the clock source selected by ADC12SSEL bits.
5–7
0 to 7: Divide selected clock source by 1 to 8
The divider’s output signal name is ADC12CLK. Thirteen of these clocks are
required for a conversion.
ISSH bit8 Invert sample-input signal.
0: The sample-input signal is not inverted.
1: The sample-input signal is inverted.
SHP bit9 The SHP 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: SAMPCOM signal is sourced directly from the sample-input signal.
1: SAMPCON signal is sourced from the sampling timer. The rising edge
of the sample-input signal triggers the sampling timer.
SHS bits Source select for the sample-input signal.
10–11
0: Control bit ADC12SC is selected.
1: Timer_A.OUT1
2: Timer_B.OUT0
3: Timer_B.OUT1
CStartAdd bits Conversion start address CStartAdd is used to define which ADC12
12–15 conversion-memory register (ADC12MEMx) is used for a single conversion
or for the first conversion in a sequence of conversions. The value of
CStartAdd is 0 to 0Fh, corresponding to ADC12MEM0 to ADC12MEM15.
Since there is one corresponding conversion-memory control register
(ADC12MCTLx) for each conversion-memory register (ADC12MEMx),
CStartAdd also points to the corresponding ADC12MCTLx register.
17-34
ADC12 Control Registers
ADC12MEM0, bits Conversion results. The 12-bit conversion results are right-justified and
to 0–15 the four MSBs are always read as 0.
ADC12MEM15
The ADC12OV interrupt flag will be set in time to indicate that a overflow
situation occurred. Software can detect it if it reads the conversion result
and then tests for overflow condition. The corresponding interrupt flag
is reset if ADC12MEMx is accessed.
All control bits in ADC12CTLx are reset during POR (see Chapter 3 for POR
details). The control registers ADC12MCTL.x can be modified only if the en-
able conversion control bit ENC is reset. Any instruction that writes to an
ADC12MCTL register while the ENC bit is set will have no effect.
ADC12 17-35
ADC12 Control Registers
7 0
ADC12MCTLx
EOS Sref, source of reference INCH, input channel a0 to a11
080h...08Fh
rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
INCH, bits 0–3 The INCH (input channel) bits select one of eight external, or one of four internal
analog signals for conversion.
0–7: a0 to a7
8: VeREF+
9: VREF– /VeREF–
10: Temperature diode
11–15: (AVCC – AVSS) / 2
Note: Selecting channel 10 automatically turns on the on-chip reference
generator for a voltage source for the temperature diode. However, it
does not enable the VREF+ output or effect the reference selections for
the conversion.
Sref, bits4–6 The Sref bits select one of six reference voltage combinations used for
conversion. The conversion is done between the selected voltage range VR+
and VR–.
0: VR+ = AVCC and VR– = AVSS
1: VR+ = VREF+ and VR– = AVSS
2,3: VR+ = VeREF+ and VR– = AVSS
4: VR+ = AVCC and VR– = VREF–/ VeREF–
5: VR+ = VREF+ and VR– = VREF–/ VeREF–
6,7: VR+ = VeREF+ and VR– = VREF–/ VeREF–
EOS, bit7 The end-of-sequence bit, when set, indicates the last conversion in a sequence
of conversions.
Note: A sequence will roll over from ADC12MEM15/ADC12MCTL15 to
ADC12MEM0/ADC12MCTL0 if the EOS bit in ADC12MCTL15 is not set.
Note: If none of the EOS bits is set and a sequence-of-channels
(CONSEQ={1,3}) is selected, resetting the ENC bit will not stop the
sequence. To stop the sequence, first select a single-channel mode
(CONSEQ={0,2}) and then reset ENC. See also the ENC bit description.
17-36
ADC12 Control Registers
All interrupt flags and interrupt-enable bits are reset during POR.
15 0
ADC12IFG
ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC
0184h IFG.15 IFG.14 IFG.13 IFG.12 IFG.11 IFG.10 IFG.9 IFG.8 IFG.7 IFG.6 IFG.5 IFG.4 IFG.3 IFG.2 IFG.1 IFG.0
rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0)
ADC12IFG.x, bits 0–15 The ADC12IFG.x interrupt flag is set if a conversion-result register
ADC12MEMx is loaded with the result of a conversion. The range for x
is 0 to 15.
The interrupt flags are reset if their corresponding ADC12MEMx
conversion-result register is accessed. To enable correct handling of
overflow conditions, they are not reset by accessing the interrupt vector
word ADC12IV. The overflow condition exists if another conversion result
is written to ADC12MEMx and the corresponding ADC12IFG.x is not
reset.
15 0
ADC12IE ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC ADC
IE.15 IE.14 IE.13 IE.12 IE.11 IE.10 IE.9 IE.8 IE.7 IE.6 IE.5 IE.4 IE.3 IE.2 IE.1 IE.0
01A6h
rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0) rw –(0)
ADC12IE.x, bits 0–15 The ADC12IE.x interrupt-enable bit enables or disables the interrupt-
request service generated if the corresponding interrupt flag ADC12IFG.x
is set. The range for x is 0 to 15.
ADC12 17-37
ADC12 Control Registers
Also note that the flags ADC12OVIFG and ADC12TOVIFG can not be
accessed by software. They are visible only via the interrupt vector word
ADC12IV data.
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
x x x x x x x x x x x x x x x x x 1 2
x x x x x x x x x x x x x x x x 1 0 4
x x x x x x x x x x x x x x x 1 0 0 6
x x x x x x x x x x x x x x 1 0 0 0 8
: : : : : : : : : : : : : : : : : : :
x 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 34
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 36
17-38
ADC12 Control Registers
The following software example shows the use of vector word ADC12IV and
the associated software overhead. The numbers at the right margin show the
cycles required for every instruction. The example shows a basic interrupt
handler structure that can be adopted to individual application requirements.
The software overhead for the different interrupt sources, including interrupt
latency and return-from-interrupt cycles (but not the task handling itself), is:
- ADC12IFG.15 14 cycles
; Interrupt handler for the 12-bit ADC.
; The flag, which is enabled and has the highest priority,
; determines the interrupt vector word and is reset by
; hardware after accessing (instruction
; ADD &TADC12IV,PC). Flags ADC12OV, ADC12TOV, and
; ADC12IFG.x are reset by hardware.
ADC_HND $ ; Interrupt latency 6
ADD &ADC12IV,PC ; Add offset to Jump table 3
RETI ; Vector 0: No interrupt 5
JMP ADC12OV ; Vector 2: ADC overflow 2
JMP ADC12TOV ; Vector 4: ADC timing overflow 2
JMP ADC12MOD0 ; Vector 6: ADC12MEM0 was loaded
...................... ; (ADC12IFG.0) 2
JMP ADC12MOD1 ; Vector 8: ADC12MEM1 was loaded
...................... ; (ADC12IFG.1) 2
:
:
JMP ADC12MOD13 ; Vector 34: ADC12MEM14 was loaded
; (ADC12IFG.14) 2
JMP ADC12MOD14 ; Vector 36: ADC12MEM15 was loaded
; (ADC12IFG.15) 2
;
; Module 15. Handler for ADC12IFG.15 starts here. Note a JMP
; instruction is not needed to get here because the PC is
; already here after the ADD&ADC12IV,PC instruction.
;
ADC12OV ... ; Vector 2: ADC12OV Flag
... ; First instruction to handle ADC12
; overflow condition
RETI 5
;
ADC12TOV ... ; Vector 4: ADC12OV Flag
... ; First instruction to handle ADC12 timing
; overflow condition
RETI 5
;
ADC12MOD2 ; Vector 10: ADC12MEM2 was loaded
; (ADC12IFG.2)
MOV &ADC12MEM2,R6 ; ADC12IFG2 is reset due to access
; of ADC memory
... ; Task starts here
ADC12 17-39
ADC12 Control Registers
17-40
A/D Grounding and Noise Considerations
Ground Loops are formed when return current from the A/D flows through
paths that are common with other analog or digital circuitry. If care is not taken,
this current can generate small, unwanted offset voltages that can add to or
subtract from the reference or input voltages of the A/D converter. One way
to avoid ground loops is to use a star connection scheme for AVSS (shown in
Figure 17–26). This way the ground current or reference currents do not flow
through any common input leads, eliminating any error voltages.
In addition to grounding, ripple and noise spikes on the power supply lines due
to digital switching or switching power supplies can corrupt the conversion
result. The ripple can become more dominant by reducing the value of the
conversion voltage range (VR+ – VR–), therefore reducing the value of the LSB
and the noise margin. Thus a clean, noise-free setup becomes even more
important to achieve the desired accuracy. Adding carefully placed bypass
capacitors returned to the respective ground planes can help in reducing ripple
in the supply current and minimizing these effects.
A/D AVCC
ÇÇÇÇÇÇ
10 µF 0.1 µF
+ VeREF+
ÇÇÇÇÇÇ
VREF
–
ÇÇÇÇÇÇ
ÇÇÇÇÇÇ
ÇÇÇÇÇÇ
VREF+
ÇÇÇÇÇÇ
ÉÉÉÉÉÉ DVCC
ÇÇÇÇÇÇ
ÉÉÉÉÉÉ
+ A0. . . 7
VIN 10 µF 0.1 µF
ÇÇÇÇÇÇ
ÉÉÉÉÉÉ
–
AVSS
DVSS
Note: If the internal Vref is used, add 10 µF/100 nF to the reference voltage terminals. External reference voltage source should
meet low dynamic impedance to ensure 12-bit conversion accuracy.
ADC12 17-41
17-42
Appendix A
This appendix summarizes the MSP430x4xx peripheral file (PF) and control-
bit information into a single location for reference.
Topic Page
A.1 Overview
Bit accessibility and/or hardware definitions are indicated following each bit
symbol:
- rw: Read/write
- r: Read only
- r0: Read as 0
- r1: Read as 1
- w: Write only
- w0: Write as 0
- w1: Write as 1
The tables in the following sections describe byte access to each peripheral
file according to the previously-described definitions.
A-2
Special Function Register of MSP430x4xx Family, Byte Access
000Fh
URXE1
Module enable 2, ME2 UTXE1
USPIE1
0005h rw-0
rw-0
URXE0
Module enable 1, ME1 UTXE0
USPIE0
0004h rw-0
rw-0
Interrupt flag 2, IFG2 UTXIFG1 URXIFG1
0003h rw-1 rw-0
Interrupt flag 1, IFG1 UXIFG0 URXIFG0 NMIIFG OFIFG WDTIFG
0002h rw-1 rw-0 rw-0 rw-1 rw-0
Interrupt enable 2, IE2 UTXIE1 URXIE1
0001h rw-0 rw-0
Interrupt enable 1, IE1 UTXIE0 URXIE0 ACCVIE NMIIE OFIE WDTIE
0000h rw-0 rw-0 rw-0 rw-0 rw-0 rw-0
Note: SFR bits are not implemented on devices without the corresponding peripheral.
0010h
A-4
Basic Timer1 Registers, Byte Access
Bit # – 7 6 5 4 3 2 1 0
SVSCTL VLD.3 VLD.2 VLD.1 VLD.0 PORON SVSon SVSOP SVSFG
0053h rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) r r rw–(0)
Bit # – 7 6 5 4 3 2 1 0
Comparator_A Port Disable, CAPD CAPD.7 CAPD.6 CAPD.5 CAPD.4 CAPD.3 CAPD.2 CAPD.1 CAPD.0
005Bh rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
Comparator_A control reg. 2, CACTL2 CACTL2.7 CACTL2.6 CACTL2.5 CACTL2.4 CA1 CA0 CAF CAOUT
005Ah rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) r–(0)
Comparator_A control reg. 1, CACTL1 CAEX CARSEL CAREF1 CAREF0 CAON CAIES CAIE CAIFG
0059h rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
A-6
USART0, USART1, SPI Mode (Sync=1), Byte Access
Bit # – 7 6 5 4 3 2 1 0
ADC12MCTL15† EOS Sref.2 Sref.1 Sref.0 INCH.3 INCH.2 INCH.1 INCH.0
008Fh rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
ADC12MCTL14† EOS Sref.2 Sref.1 Sref.0 INCH.3 INCH.2 INCH.1 INCH.0
008Eh rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
ADC12MCTL13† EOS Sref.2 Sref.1 Sref.0 INCH.3 INCH.2 INCH.1 INCH.0
008Dh rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
ADC12MCTL12† EOS Sref.2 Sref.1 Sref.0 INCH.3 INCH.2 INCH.1 INCH.0
008Ch rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
ADC12MCTL11† EOS Sref.2 Sref.1 Sref.0 INCH.3 INCH.2 INCH.1 INCH.0
008Bh rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
ADC12MCTL10† EOS Sref.2 Sref.1 Sref.0 INCH.3 INCH.2 INCH.1 INCH.0
008Ah rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
ADC12MCTL9† EOS Sref.2 Sref.1 Sref.0 INCH.3 INCH.2 INCH.1 INCH.0
0089h rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
ADC12MCTL8† EOS Sref.2 Sref.1 Sref.0 INCH.3 INCH.2 INCH.1 INCH.0
0088h rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
ADC12MCTL7† EOS Sref.2 Sref.1 Sref.0 INCH.3 INCH.2 INCH.1 INCH.0
0087h rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
ADC12MCTL6† EOS Sref.2 Sref.1 Sref.0 INCH.3 INCH.2 INCH.1 INCH.0
0086h rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
ADC12MCTL5† EOS Sref.2 Sref.1 Sref.0 INCH.3 INCH.2 INCH.1 INCH.0
0085h rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
ADC12MCTL4† EOS Sref.2 Sref.1 Sref.0 INCH.3 INCH.2 INCH.1 INCH.0
0084h rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
ADC12MCTL3† EOS Sref.2 Sref.1 Sref.0 INCH.3 INCH.2 INCH.1 INCH.0
0083h rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
ADC12MCTL2† EOS Sref.2 Sref.1 Sref.0 INCH.3 INCH.2 INCH.1 INCH.0
0082h rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
ADC12MCTL1† EOS Sref.2 Sref.1 Sref.0 INCH.3 INCH.2 INCH.1 INCH.0
0081h rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
ADC12MCTL0† EOS Sref.2 Sref.1 Sref.0 INCH.3 INCH.2 INCH.1 INCH.0
0080h rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
A-8
ADC12 Registers, Byte and Word Access
Bit # – 7 6 5 4 3 2 1 0
ADC12IE ADC12IE.7 ADC12IE.6 ADC12IE.5 ADC12IE.4 ADC12IE.3 ADC12IE.2 ADC12IE.1 ADC12IE.0
01A6h rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0) rw–(0)
A-10
LCD Registers, Byte Access
Note: The LCD memory bits are named with the MSP430 convention. The first part of the bit name indicates the corresponding
segment line and the second indicates the corresponding common line.
Example for a segment using S4 and Com3: S4C3
Bit # – 7 6 5 4 3 2 1 0
Watchdog Timer,
HOLD NMIES NMI TMSEL CNTCL SSEL IS1 IS0
Control register WDTCTL
rw-0 rw-0 rw-0 rw-0 (w),r0 rw-0 rw-0 rw-0
120h
Bit # – 15 14 13 12 11 10 9 8
FCTL3 <–––––––––––––––––––––––––– Read as 096h ––––––––––––––––––––––––––––––––––>
012Ch <–––––––––––––––––––––––––– Written as 0A5h ––––––––––––––––––––––––––––––––––>
FCTL2 <–––––––––––––––––––––––––– Read as 096h ––––––––––––––––––––––––––––––––––>
012Ah <–––––––––––––––––––––––––– Written as 0A5h ––––––––––––––––––––––––––––––––––>
FCTL1 <–––––––––––––––––––––––––– Read as 096h ––––––––––––––––––––––––––––––––––>
0128H <–––––––––––––––––––––––––– Written as 0A5h ––––––––––––––––––––––––––––––––––>
Bit # – 7 6 5 4 3 2 1 0
FCTL3 Reserved Reserved EMEX Lock WAIT ACCVIFG KEYV Busy
012Ch r0 r0 rw–0 rw–1 r–1 rw–0 rw–(0) r(w)–0
FCTL2 SSEL1 SSEL0 FN5 FN4 FN3 FN2 FN1 FN0
012Ah rw–0 rw–1 rw–0 rw–0 rw–0 rw–0 rw–1 rw–0
FCTL1 SEGWRT WRT Reserved Reserved Reserved MEras Erase Reserved
0128H rw–0 rw–0 r0 r0 r0 rw–0 rw–0 r0
A-12
Hardware Multiplier, Word Access
Bit # – 15 14 13 12 11 10 9 8
Sum extend, SumExt † † † † † † † †
013Eh r r r r r r r r
Result-high word ResHI 215 214 213 212 211 210 29 28
013Ch rw rw rw rw rw rw rw rw
Result-low word ResLO 215 214 213 212 211 210 29 28
013Ah rw rw rw rw rw rw rw rw
Second operand OP2 215 214 213 212 211 210 29 28
0138h rw rw rw rw rw rw rw rw
MPYS+ACC MACS 215 214 213 212 211 210 29 28
0136h rw rw rw rw rw rw rw rw
MPY+ACC MAC 215 214 213 212 211 210 29 28
0134h rw rw rw rw rw rw rw rw
Multiply signed MPYS 215 214 213 212 211 210 29 28
0132h rw rw rw rw rw rw rw rw
Multiply unsigned MPY 215 214 213 212 211 210 29 28
0130h rw rw rw rw rw rw rw rw
Bit # – 7 6 5 4 3 2 1 0
Sum extend, SumExt † † † † † † † †
013Eh r r r r r r r r
Result-high word ResHI 27 26 25 24 23 22 21 20
013Ch rw rw rw rw rw rw rw rw
Result-low word ResLO 27 26 25 24 23 22 21 20
013Ah rw rw rw rw rw rw rw rw
Second operand OP2 27 26 25 24 23 22 21 20
0138h rw rw rw rw rw rw rw rw
MPYS+ACC MACS 27 26 25 24 23 22 21 20
0136h rw rw rw rw rw rw rw rw
MPY+ACC MAC 27 26 25 24 23 22 21 20
0134h rw rw rw rw rw rw rw rw
Multiply signed MPYS 27 26 25 24 23 22 21 20
0132h rw rw rw rw rw rw rw rw
Multiply unsigned MPY 27 26 25 24 23 22 21 20
0130h rw rw rw rw rw rw rw rw
† The Sum Extend register SumExt holds a 16×16-bit multiplication (MPYS) sign result, or the overflow of the multiply and accu-
mulate (MAC) operation, or the sign of the signed multiply and accumulate (MACS) operation. Overflow and underflow of the
MACS operation must be handled by software.
Bit # – 7 6 5 4 3 2 1 0
017Eh
017Ch
017Ah
0178h
Cap/com register CCR2 27 26 25 24 23 22 21 20
0176h rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0)
Cap/com register CCR1 27 26 25 24 23 22 21 20
0174h rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0)
Cap/com register CCR0 27 26 25 24 23 22 21 20
0172h rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0)
Timer_A register TAR 27 26 25 24 23 22 21 20
0170h rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0)
016Eh
016Ch
016Ah
0168h
Cap/com control CCTL2, OutMod22 OutMod21 OutMod20 CCIE2 CCI2 OUT2 COV2 CCIFG2
0166h rw-(0) rw-(0) rw-(0) rw-(0) r rw-(0) rw-(0) rw-(0)
Cap/com control CCTL1, OutMod12 OutMod11 OutMod10 CCIE1 CCI1 OUT1 COV1 CCIFG1
0164h rw-(0) rw-(0) rw-(0) rw-(0) r rw-(0) rw-(0) rw-(0)
Cap/com control CCTL0, OutMod02 OutMod01 OutMod00 CCIE0 CCI0 OUT0 COV0 CCIFG0
0162h rw-(0) rw-(0) rw-(0) rw-(0) r rw-(0) rw-(0) rw-(0)
Timer_A control TACTL ID1 ID0 MC1 MC0 Unused CLR TAIE TAIFG
0160h rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0) rw-(0)
A-14
Timer_A Registers, Word Access
Bit # – 7 6 5 4 3 2 1 0
Timer_A interrupt
interru t vector 0 0 0 0 TAIV 0
TAIV 12Eh r0 r0 r0 r0 r-(0) r-(0) r-(0) r0
A-16
Timer_B Registers, Word Access
Bit # – 7 6 5 4 3 2 1 0
Timer_B interru
interruptt vector 0 0 0 0 TBIV 0
TBIV 11Eh r0 r0 r0 r0 r-(0) r-(0) r-(0) r0
A-18
Appendix B
The MSP430 core CPU architecture evolved from a reduced instruction set
with highly-transparent instruction formats. Using these formats, core
instructions are implemented into the hardware. Emulated instructions are
also supported by the assembler. Emulated instructions use the core
instructions with the built-in constant generators CG1 and CG2 and/or the
program counter (PC). The core and emulated instructions are described in
detail in this section. The emulated instruction mnemonics are listed with
examples.
Program memory words used by an instruction vary from one to three words,
depending on the combination of addressing modes.
Topic Page
Status Bits
V N Z C
* ADC[.W];ADC.B dst dst + C –> dst * * * *
ADD[.W];ADD.B src,dst src + dst –> dst * * * *
ADDC[.W];ADDC.B src,dst src + dst + C –> dst * * * *
AND[.W];AND.B src,dst src .and. dst –> dst 0 * * *
BIC[.W];BIC.B src,dst .not.src .and. dst –> dst – – – –
BIS[.W];BIS.B src,dst src .or. dst –> dst – – – –
BIT[.W];BIT.B src,dst src .and. dst 0 * * *
* BR dst Branch to ....... – – – –
CALL dst PC+2 –> stack, dst –> PC – – – –
* CLR[.W];CLR.B dst Clear destination – – – –
* CLRC Clear carry bit – – – 0
* CLRN Clear negative bit – 0 – –
* CLRZ Clear zero bit – – 0 –
CMP[.W];CMP.B src,dst dst – src * * * *
* DADC[.W];DADC.B dst dst + C –> dst (decimal) * * * *
DADD[.W];DADD.B src,dst src + dst + C –> dst (decimal) * * * *
* DEC[.W];DEC.B dst dst – 1 –> dst * * * *
* DECD[.W];DECD.B dst dst – 2 –> dst * * * *
* DINT Disable interrupt – – – –
* EINT Enable interrupt – – – –
* INC[.W];INC.B dst Increment destination,
dst +1 –> dst * * * *
* INCD[.W];INCD.B dst Double-Increment destination,
dst+2–>dst * * * *
* INV[.W];INV.B dst Invert destination * * * *
JC/JHS Label Jump to Label if
Carry-bit is set – – – –
JEQ/JZ Label Jump to Label if
Zero-bit is set – – – –
JGE Label Jump to Label if
(N .XOR. V) = 0 – – – –
JL Label Jump to Label if
(N .XOR. V) = 1 – – – –
JMP Label Jump to Label unconditionally – – – –
JN Label Jump to Label if
Negative-bit is set – – – –
JNC/JLO Label Jump to Label if
Carry-bit is reset – – – –
JNE/JNZ Label Jump to Label if
Zero-bit is reset – – – –
B-2
Instruction Set Overview
Status Bits
V N Z C
MOV[.W];MOV.B src,dst src –> dst – – – –
* NOP No operation – – – –
* POP[.W];POP.B dst Item from stack, SP+2 → SP – – – –
PUSH[.W];PUSH.B src SP – 2 → SP, src → @SP – – – –
RETI Return from interrupt * * * *
TOS → SR, SP + 2 → SP
TOS → PC, SP + 2 → SZP
* RET Return from subroutine – – – –
TOS → PC, SP + 2 → SP
* RLA[.W];RLA.B dst Rotate left arithmetically * * * *
* RLC[.W];RLC.B dst Rotate left through carry * * * *
RRA[.W];RRA.B dst MSB → MSB → ....LSB → C 0 * * *
RRC[.W];RRC.B dst C → MSB → .........LSB → C * * * *
* SBC[.W];SBC.B dst Subtract carry from destination * * * *
* SETC Set carry bit – – – 1
* SETN Set negative bit – 1 – –
* SETZ Set zero bit – – 1 –
SUB[.W];SUB.B src,dst dst + .not.src + 1 → dst * * * *
SUBC[.W];SUBC.B src,dst dst + .not.src + C → dst * * * *
SWPB dst swap bytes – – – –
SXT dst Bit7 → Bit8 ........ Bit15 0 * * *
* TST[.W];TST.B dst Test destination 0 * * 1
XOR[.W];XOR.B src,dst src .xor. dst → dst * * * *
The source field is composed of two addressing bits and a four-bit register
number (0....15). The destination field is composed of one addressing bit and
a four-bit register number (0....15). The byte identifier B/W indicates whether
the instruction is executed as a byte (B/W = 1) or as a word instruction
(B/W = 0).
Operational Code
Field
Status Bits
V N Z C
ADD[.W]; ADD.B src,dst src + dst –> dst * * * *
ADDC[.W]; ADDC.B src,dst src + dst + C –> dst * * * *
AND[.W]; AND.B src,dst src .and. dst –> dst 0 * * *
BIC[.W]; BIC.B src,dst .not.src .and. dst –> dst – – – –
BIS[.W]; BIS.B src,dst src .or. dst –> dst – – – –
BIT[.W]; BIT.B src,dst src .and. dst 0 * * *
CMP[.W]; CMP.B src,dst dst – src * * * *
DADD[.W]; DADD.B src,dst src + dst + C –> dst (dec) * * * *
MOV[.W]; MOV.B src,dst src –> dst – – – –
SUB[.W]; SUB.B src,dst dst + .not.src + 1 –> dst * * * *
SUBC[.W]; SUBC.B src,dst dst + .not.src + C –> dst * * * *
XOR[.W]; XOR.B src,dst src .xor. dst –> dst * * * *
B-4
Instruction Set Overview
The destination field is composed of two addressing bits and the four-bit
register number (0....15). The destination field bit position is the same as that
of the two operand instructions. The byte identifier (B/W) indicates whether the
instruction is executed as a byte (B/W = 1) or as a word (B/W = 0).
Status Bits
V N Z C
RRA[.W]; RRA.B dst MSB → MSB ...LSB → C 0 * * *
RRC[.W]; RRC.B dst C → MSB ........LSB → C * * * *
PUSH[.W]; PUSH.B dst SP – 2 → SP, src → @SP – – – –
SWPB dst swap bytes – – – –
CALL dst PC→2 + @SP, dst → PC – – – –
RETI dst TOS → SR, SP + 2 → SP * * * *
TOS → PC, SP + 2 → SP
SXT dst Bit 7 → Bit 8 ........ Bit 15 0 * * *
The operational-code field is composed of the op-code ( three bits), and three
bits according to the following conditions.
0 0 1 X X X X X X X X X X X X X
A jump that is not taken continues the program with the ascending instruction.
B-6
Instruction Set Overview
Logical instructions
INV[.W] dst Invert destination * * * * XOR #0FFFFh,dst
INV.B dst Invert destination * * * * XOR.B #0FFFFh,dst
RLA[.W] dst Rotate left arithmetically * * * * ADD dst,dst
RLA.B dst Rotate left arithmetically * * * * ADD.B dst,dst
RLC[.W] dst Rotate left through carry * * * * ADDC dst,dst
RLC.B dst Rotate left through carry * * * * ADDC.B dst,dst
B-8
Instruction Set Overview
Description The carry bit (C) is added to the destination operand. The previous contents
of the destination are lost.
Example 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
Example 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
Description The source operand is added to the destination operand. The source operand
is not affected. The previous contents of the destination are lost.
ADD #10,R5
JC TONI ; Carry occurred
...... ; No carry
B-10
Instruction Set Overview
Description 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.
Example 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.
Example The 24-bit counter pointed to by R13 is added to a 24-bit counter, eleven words
above the pointer in R13.
Description The source operand and the destination operand are logically ANDed. The
result is placed into the destination.
Example 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.
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.
B-12
Instruction Set Overview
Description The inverted source operand and the destination operand are logically
ANDed. The result is placed into the destination. The source operand is not
affected.
Example The six MSBs of the RAM word LEO are cleared.
Example The five MSBs of the RAM byte LEO are cleared.
Description The source operand and the destination operand are logically ORed. The
result is placed into the destination. The source operand is not affected.
Example The six LSBs of the RAM word TOM are set.
B-14
Instruction Set Overview
Syntax BR dst
B-16
Instruction Set Overview
CALL Subroutine
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.
CLR R5
B-18
Instruction Set Overview
Syntax CLRC
Operation 0 –> C
Description The carry bit (C) is cleared. The clear carry instruction is a word instruction.
Example The 16-bit decimal counter pointed to by R13 is added to a 32-bit counter
pointed to by R12.
Syntax CLRN
Operation 0→N
or
(.NOT.src .AND. dst –> dst)
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.
Example The Negative bit in the status register is cleared. This avoids special treatment
with negative numbers of the subroutine called.
CLRN
CALL SUBR
......
......
SUBR JN SUBRET ; If input is negative: do nothing and return
......
......
......
SUBRET RET
B-20
Instruction Set Overview
Syntax CLRZ
Operation 0→Z
or
(.NOT.src .AND. dst –> dst)
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.
CLRZ
Description 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.
Status Bits N: Set if result is negative, reset if positive (src >= dst)
Z: Set if result is zero, reset otherwise (src = dst)
C: Set if there is a carry from the MSB of the result, reset otherwise
V: Set if an arithmetic overflow occurs, otherwise reset
Example R5 and R6 are compared. If they are equal, the program continues at the label
EQUAL.
Example Two RAM blocks are compared. If they are not equal, the program branches
to the label ERROR.
Example The RAM bytes addressed by EDE and TONI are compared. If they are equal,
the program continues at the label EQUAL.
B-22
Instruction Set Overview
Description 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.
Example The two-digit decimal counter in the RAM byte CNT is incremented by one.
or
SETC
DADD.B #0,CNT ; ≡ DADC.B CNT
B-24
Instruction Set Overview
Description The destination operand is decremented by one. The original contents are
lost.
; 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+,TONI–EDE–1(R6)
DEC R10
JNZ L$1
; Do not transfer tables using the routine above with the overlap shown in Figure B–4.
TONI
EDE+254
TONI+254
; 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.B #255,LEO
L$1 MOV.B @R6+,TONI–EDE–1(R6)
DEC.B LEO
JNZ L$1
B-26
Instruction Set Overview
Description The destination operand is decremented by two. The original contents are lost.
; 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+,TONI–EDE–2(R6)
DECD R10
JNZ L$1
DECD.B STATUS
Syntax DINT
Operation 0 → GIE
or
(0FFF7h .AND. SR → SR / .NOT.src .AND. dst –> dst)
Mode Bits GIE is reset. OscOff and CPUOff are not affected.
Example 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 ; All interrupt events using the GIE bit are disabled
NOP
MOV COUNTHI,R5 ; Copy counter
MOV COUNTLO,R6
EINT ; All interrupt events using the GIE bit are enabled
B-28
Instruction Set Overview
Syntax EINT
Operation 1 → GIE
or
(0008h .OR. SR –> SR / .NOT.src .OR. dst –> dst)
Mode Bits GIE is set. OscOff and CPUOff are not affected.
Example The general interrupt enable (GIE) bit in the status register is set.
Description The destination operand is incremented by one. The original contents are lost.
Example The status byte of a process STATUS is incremented. When it is equal to 11,
a branch to OVFL is taken.
INC.B STATUS
CMP.B #11,STATUS
JEQ OVFL
B-30
Instruction Set Overview
Example The destination operand is incremented by two. The original contents are lost.
Example The item on the top of the stack (TOS) is removed without using a register.
.......
PUSH R5 ; R5 is the result of a calculation, which is stored
; in the system stack
INCD SP ; Remove TOS by double-increment from stack
; Do not use INCD.B, SP is a word-aligned
; register
RET
Description The destination operand is inverted. The original contents are lost.
B-32
Instruction Set Overview
Syntax JC label
JHS label
Description 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).
Example The P1IN.1 signal is used to define or control the program flow.
Example R5 is compared to 15. If the content is higher or the same, branch to LABEL.
CMP #15,R5
JHS LABEL ; Jump is taken if R5 ≥ 15
...... ; Continue here if R5 < 15
Description 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.
TST R7 ; Test R7
JZ TONI ; if zero: JUMP
TST R5
JZ LABEL
......
B-34
Instruction Set Overview
Description 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.
Example When the content of R6 is greater or equal to the memory pointed to by R7,
the program continues at label EDE.
JL Jump if less
Syntax JL label
Description 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.
Example When the content of R6 is less than the memory pointed to by R7, the program
continues at label EDE.
B-36
Instruction Set Overview
Description The 10-bit signed offset contained in the instruction LSBs is added to the
program counter.
Hint: This one-word instruction replaces the BRANCH instruction in the range of
– 511 to +512 words relative to the current program counter.
JN Jump if negative
Syntax JN label
Description 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.
B-38
Instruction Set Overview
Description 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).
CMP.B #2,STATUS
JLO STL2 ; STATUS < 2
...... ; STATUS ≥ 2, continue here
Description 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.
B-40
Instruction Set Overview
Example The contents of table EDE (word data) are copied to table TOM. The length
of the tables must be 020h locations.
Example The contents of table EDE (byte data) are copied to table TOM. The length of
the tables should be 020h locations
* NOP No operation
Syntax NOP
Operation None
Description No operation is performed. The instruction may be used for the elimination of
instructions during the software check or for defined waiting times.
B-42
Instruction Set Overview
Description The stack location pointed to by the stack pointer (TOS) is moved to the
destination. The stack pointer is incremented by two afterwards.
Example The contents of R7 and the status register are restored from the stack.
POP R7 ; Restore R7
POP SR ; Restore status register
Example The contents of RAM byte LEO is restored from the stack.
Example The contents of the memory pointed to by R7 and the status register are
restored from the stack.
Operation SP – 2 → SP
src → @SP
Description The stack pointer is decremented by two, then the source operand is moved
to the RAM word addressed by the stack pointer (TOS).
Example The contents of the status register and R8 are saved on the stack.
B-44
Instruction Set Overview
Syntax RET
Operation @SP→ PC
SP + 2 → SP
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.
Syntax RETI
Operation TOS → SR
SP + 2 → SP
TOS → PC
SP + 2 → SP
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.
Mode Bits OscOff, CPUOff, and GIE are restored from system stack.
PC –6
PC –4
Interrupt Request
PC –2
PC Interrupt Accepted
PC +6 PCi +4
PC +8
PCi +n–4
PCi +n–2
PCi +n RETI
B-46
Instruction Set Overview
C 0
Byte 7 0
An overflow occurs if dst ≥ 040h and dst < 0C0h before the operation is
performed: the result has changed sign.
Status Bits N: Set if result is negative, reset if positive
Z: Set if result is zero, reset otherwise
C: Loaded from the MSB
V: Set if an arithmetic overflow occurs:
the initial value is 04000h ≤ dst < 0C000h; otherwise it is reset
Set if an arithmetic overflow occurs:
the initial value is 040h ≤ dst < 0C0h; otherwise it is reset
Mode Bits OscOff, CPUOff, and GIE are not affected.
Example R7 is multiplied by 4.
RLA R7 ; Shift left R7 (× 2) – emulated by ADD R7,R7
RLA R7 ; Shift left R7 (× 4) – emulated by ADD R7,R7
Example The low byte of R7 is multiplied by 4.
RLA.B R7 ; Shift left low byte of R7 (× 2) – emulated by
; ADD.B R7,R7
RLA.B R7 ; Shift left low byte of R7 (× 4) – emulated by
; ADD.B R7,R7
Operation C <– MSB <– MSB–1 .... LSB+1 <– LSB <– C
Description The destination operand is shifted left one position as shown in Figure B–7.
The carry bit (C) is shifted into the LSB and the MSB is shifted into the carry
bit (C).
Byte 7 0
Example The input P1IN.1 information is shifted into the LSB of R5.
Example The input P1IN.1 information is to be shifted into the LSB of R5.
B-48
Instruction Set Overview
Operation MSB –> MSB, MSB –> MSB–1, ... LSB+1 –> LSB, LSB –> C
Description The destination operand is shifted right one position as shown in Figure B–8.
The MSB is shifted into the MSB, the MSB is shifted into the MSB–1, and the
LSB+1 is shifted into the LSB.
Byte
15 0
Example R5 is shifted right one position. The MSB retains the old value. It operates
equal to an arithmetic division by 2.
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.
B-50
Instruction Set Overview
Operation C –> MSB –> MSB–1 .... LSB+1 –> LSB –> C
Description The destination operand is shifted right one position as shown in Figure B–6.
The carry bit (C) is shifted into the MSB, the LSB is shifted into the carry bit (C).
Byte 7 0
Description The carry bit (C) is added to the destination operand minus one. The previous
contents of the destination are lost.
Example The 16-bit counter pointed to by R13 is subtracted from a 32-bit counter
pointed to by R12.
Example The 8-bit counter pointed to by R13 is subtracted from a 16-bit counter pointed
to by R12.
B-52
Instruction Set Overview
Syntax SETC
Operation 1 –> C
Syntax SETN
Operation 1 –> N
B-54
Instruction Set Overview
Syntax SETZ
Operation 1 –> Z
Description The source operand is subtracted from the destination operand by adding the
source operand’s 1s complement and the constant 1. The source operand is
not affected. The previous contents of the destination are lost.
B-56
Instruction Set Overview
Description The source operand is subtracted from the destination operand by adding the
source operand’s 1s complement and the carry bit (C). The source operand
is not affected. The previous contents of the destination are lost.
Example The 16-bit counter pointed to by R13 is subtracted from a 16-bit counter in R10
and R11(MSD).
Description The destination operand high and low bytes are exchanged as shown in
Figure B–10.
Example
SWPB R5 ;
MOV R5,R4 ;Copy the swapped value to R4
BIC #0FF00h,R5 ;Correct the result
BIC #00FFh,R4 ;Correct the result
B-58
Instruction Set Overview
Description The sign of the low byte is extended into the high byte as shown in Figure B–11.
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.
Description The destination operand is compared with zero. The status bits are set accord-
ing to the result. The destination is not affected.
TST R7 ; Test R7
JN R7NEG ; R7 is negative
JZ R7ZERO ; R7 is zero
R7POS ...... ; R7 is positive but not zero
R7NEG ...... ; R7 is negative
R7ZERO ...... ; R7 is zero
B-60
Instruction Set Overview
Description The source and destination operands are exclusive ORed. The result is placed
into the destination. The source operand is not affected.
Example The bits set in R6 toggle the bits in the RAM word TONI.
Example The bits set in R6 toggle the bits in the RAM byte TONI.
Example Reset to 0 those bits in low byte of R7 that are different from bits in RAM byte
EDE.
Flash Memory
This chapter describes the MSP430 flash memory module. The flash memory
module is electrically erasable and programmable. Devices with a flash
memory module are multiple-time programmable devices (MTP). They can be
erased and programmed off-board, or in a system via the MSP430’s JTAG pe-
ripheral module, a bootstrap loader, or via the processor’s resources.
Software running on an MSP430 device can erase and program the flash
memory module. This active software may run in RAM, in ROM, or in the flash
memory. The flash memory may be a different memory module or the same
memory module.
Topic Page
ROM RAM
TDI
TDO/TDI
MAB, 16 Bit
MDB, 16 Bit
TMS
TCK
Flash Flash
Test/VPP Memory Memory
Optional Module 1 Module 2
If the active software and the target programming location are in the same flash
memory module, the program execution is halted (flag BUSY=1) until the pro-
gramming cycle is completed (flag BUSY=0). Then it proceeds with the next
instruction. The active software may also erase segments of the flash memory
module. The user should be careful not to erase memory locations that are
necessary to execute the software correctly.
Figure C–2 shows the flash memory Module1 in program or erase operation.
During this operation the module is disconnected from the memory address
C-2
Flash Memory Organization
bus and memory data bus. When a second module (here Module2) is
implemented, program code in this module can be executed while Module1 is
disconnected.
Figure C–2. Flash Memory Module1 Disabled, Module2 Can Execute Code
Simultaneously
ROM RAM
TDI
TDO/TDI
MAB, 16 Bit
MDB, 16 Bit
TMS
TCK
Flash Flash
Test/VPP Memory Memory
Optional Module 1 Module 2
One MSP430 flash memory module will have, in addition to its code segments,
extra flash memory called information memory.
FFFFh
4-kbyte
Flash
Memory
F000h
010FFh 256-Byte
Flash Memory
01000h
A module has several segments. The information memory has two segments
of 128 bytes each. In the example in Figure C–4, the 4-kB module has eight
segments of 512 bytes (Segment0 to Segment7), and two 128-byte segments
(SegmentA and SegmentB). Segment0 to Segment7 can be erased
individually or as a group. SegmentA and SegmentB can be erased
individually or as a group with segments 0 to 7.
The segment structure is described in the device’s data sheet. The information
memory can be located directly below the main memory’s address, or at a
different address but will be in the same module.
Note:
Flash memory modules may have different numbers of segments. Segment
are numbered from 0 up to n, e.g., segment 0 to segment n.
C-4
Flash Memory Data Structure and Operation
F000h Segment2
010FFh 256-Byte
Segment3
Flash
01000h
Segment4
Information
Memory
Segment5
Segment6
F000h Segment7
010FFh
SegmentA
01000h SegmentB
MAB
MDB
FCTL2 Enable
Address
Latch
FCTL3 Flash
Memory
Array
Timing
Generator Enable
Data Latch
Programming
Voltage
Generator
C-6
Flash Memory Data Structure and Operation
operation. Once these registers are set up and write or erase is started, the
timing generator controls the entire operation and applies all signals internally.
If the BUSY control signal is set, it indicates that the timing generator is active
and a write or erase cycle is active. The block write mode also uses a second
control bit WAIT. There are three basic parts to a write or erase cycle:
preparation of program/erase voltage, control timing for the program or erase
operation, and the switch-off sequence of the program/erase voltage. Once a
write or erase function is started, the software should not access the flash
memory until the BUSY signal indicates, with 0, that it can be accessed again.
In critical situations where flash programming or erase should be immediately
stopped, the emergency exit bit EMEX can be set. The current operation may
be incomplete or the result may be incorrect.
Different clock sources (ACLK, MCLK, or SMCLK) can be selected to clock the
timing generator. The connected clock sources applied to the timing generator
may vary with the device, see data sheet for details. The clock source selected
should be active from the beginning of write or erase until the operation is fully
completed.
Figure C–6. Block Diagram of the Timing Generator in the Flash Memory Module
Write ‘1’ to
SSEL1
FN5 ........... FN0 PUC EMEX
SSEL0
ACLK 0
1 fx Reset
MCLK
2 Divider, 1–64
SMCLK Flash Timing Generator
SMCLK 3
Busy Wait
The selected clock source should be divided to meet the frequency require-
ment fx of the flash timing generator.
If the clock signals are not available throughout the duration of the write or
erase operation, or their frequencies change drastically, the result of the write
or erase may be marginal, or the flash memory module may be stressed above
the limits of reliable operation.
Table C–1 shows all useful combinations of control bits for proper write and
erase operation:
Note: A write to flash memory performed with any other combination of bits BLKWRT, WRT, Meras, Eras, BUSY, WAIT, and
Lock will result in an access violation. ACCVIFG is set and an NMI is requested if ACCVIE=1.
C-8
Flash Memory Data Structure and Operation
The dummy write starts the erase cycle. An example of dummy write is
CLR &0F012h.
Note that a dummy write is ignored in a segment where the selected operation
can not be executed successfully.
Figure C–7. Basic Flash EEPROM Module Timing During the Erase Cycle
BUSY
Mass Erase: t(erase) = 5296/fx; Segment Erase: t(erase) = 4817/fx
Control bit BUSY indicates an active erase cycle. It is set immediately after a
dummy write starts the timing generator. It remains set until the entire erase
cycle is completed and the erased segment or block is ready to be accessed
again. The BUSY bit can not be set by software. But it can be reset. In case
of emergency, set the emergency exit (EMEX) bit and the erase operation will
be stopped immediately; BUSY bit is reset. One example of stop erase by soft-
ware is when the supply voltage drops drastically and the operating conditions
of the controller are exceeded. Another example is when the timing of the
erase cycle gets out of control, for example, when the clock-source signal is
lost.
Note:
When the erase cycle is stopped before its normal completion by the hard-
ware, the timing generator is stopped and erasure of the flash memory can
be marginal. An incomplete erasure can be verified. But an erase level of 1
can be inconsistently read as valid when supply voltage, temperature,
access time (instruction execution, data read), and frequency vary.
The flash memory erase bit level is 1. Bits can only be written (programmed)
to a 0-level. Once a bit is programmed, only the erase function can reset it back
to the 1-level. The byte or word 0-level can not be written (programmed) in one
cycle. Any bit can be programmed from 1 to 0 at any time, but not from 0 to 1.
Two slightly different write operations can be performed: write a single byte or
word of data, or write a sequence of bytes or words. A write sequence of bytes
or words can be performed as multiple sequential, or as a block write. The
block write is approximately twice as fast as a multiple-sequential write
algorithm.
- Set the correct input clock frequency of the timing generator by selecting
the clock source and predivider.
- Watch the BUSY bit. Continue with the next steps only if the BUSY bit is
reset.
- Set the write-control bit WRT when a single byte of word data is to be
written.
- Set the write WRT and BLKWRT control bits when block write is chosen
to write multiple bytes or words to the flash memory module.
- Writing the data to the selected address starts the timing generator.
The data is written (programmed) while the timing generator proceeds.
Note:
Whenever the write cycle is stopped before its normal ending by the hard-
ware, the timing generator is stopped and the data written to the flash
memory can be marginal. The data may be incorrect, which can be verified,
or the data are verified to be correct but the programming is marginal.
Reading of the data may be inconsistently valid when varying the supply volt-
age, the temperature, the access time (instruction execution, data read), or
the time.
C-10
Flash Memory Data Structure and Operation
Figure C–8. Basic Flash Memory Module Timing During Write (Single Byte or Word) Cycle
Î ÎÎ
Î Programming Operation Active
ÎÎ
Generate Remove
Programming Voltage Programming Voltage
Entire Programming Cycle Timing
Time of Increased Current Consumption From Supply, VCC
BUSY
t(prog) = 33/fx
Figure C–9. Basic Flash Memory Module Timing During a Block-Write Cycle
BLKWRT bit
The block write can be used on sequential addresses of the memory module.
One block is 64 bytes long, starting at 0xx00h, 0xx40h, 0xx80h, or 0xxC0h, and
ending at 0xx3Fh, 0xx7Fh, 0xxBFh, or 0xxFFh. Examples of sequential block
addresses are:
- Wait until the WAIT bit is set, indicating that the write of the last byte or word
was completed.
- The BUSY bit remains set until the programming voltage is removed from
the flash memory module and overstress is avoided.
- Wait the recovery time t(rcv) before another block write is started.
The conditions to read data from the flash memory with and without access
violation are listed in Table C–2.
No 1 1 3FFF Nothing
Notes: 1) Instruction fetch refers to the fetch part of an instruction, and reads one word. The instruction fetch reads the first
word of instructions with more than one word. The JMP instruction has one word. The data fetched (3FFFh) is used
by the CPU as an instruction.
2) Ensure that the programmed data does not result in unpredictable program execution, such as destruction of
executable code sequences.
3) If the PC points to the memory location being erased, no access violation indicates this situation. After erase, no
executable code is available and an unpredictable situation occurs.
4) Any software located in a flash memory module can not use the BLKWRT mode to program the same flash memory
module. Using the byte or word programming mode allows programming data in the flash memory module holding
the software code currently executing.
5) The access violation sets the LOCK bit to 1. Setting the LOCK bit allows completion of the active block write
operation in the normal manner.
C-12
Flash Memory Control Registers
- The supply voltage should be within the devices’ electrical conditions and
can only vary slightly, as specified in the applicable data sheet
The control bit BUSY indicates that the write or block-write cycle is active. It
is set by the instruction that writes data to the flash memory module and starts
the timing generator. It remains set until the write cycle is completed and the
programming voltage is removed. In the write mode the BUSY bit indicates if
the flash memory is ready for another write operation. In block write mode the
WAIT bit indicates if the flash memory is ready for another write operation and
the BUSY bit indicates the block write operation is completed. In case of
emergency, the emergency exit bit EMEX is set and stops the write cycle
immediately. The programming voltage is switched off. One situation where
the write cycle should be stopped by software is when the supply voltage drops
drastically and the controller’s operating conditions may be exceeded.
Another case is when the flash memory timing gets out of control, as when the
clock-source signal is lost.
Note:
Whenever the write cycle is stopped before its normal ending by the hard-
ware, the timing generator is stopped and the data written in flash memory
may be marginal. Data reading may be inconsistently valid when varying the
supply voltage, the temperature, the access time (instruction execution, data
read), or the time.
All control bits are reset during PUC. PUC is activated after VCC is applied, a
reset condition is applied to the RST/NMI pin or watchdog, or a flash operation
was not performed normally.
C-14
Flash Memory Control Registers
The timing generator generates the timing necessary to write, erase, and
mass-erase from a selected clock source. Two control bits SSEL0 and SSEL1
in control register FCTL2 can select one of three clock sources. The clock
source selected should be divided to meet the frequency requirements for fx,
as specified in the device’s data sheet.
Writing to control register FCTL2 should not be attempted if the BUSY bit is set;
otherwise an access violation will occur (ACCVIFG=1). Read access to FCTL2
is possible at any time without restrictions.
15 8 7 0
FCTL2
SSEL1 SSEL0 FN5 FN4 FN3 FN2 FN1 FN0
012Ah
FCTL2 read: 096h rw–0 rw–1 rw–0 rw–0 rw–0 rw–0 rw–1 rw–0
FCTL2 write: 0A5h
15 8 7 0
FCTL3 ACCV
res. res. EMEX Lock WAIT KEYV BUSY
012Ch IFG
FCTL3 read: 096h r0 r0 rw–0 rw–1 r–1 rw–0 rw–(0) r(w)–0
FCTL3 write: 0A5h
BUSY 0128h, bit0, The bit BUSY shows if an access to the flash memory is possible
(BUSY=0), or if an access violation can occur. The BUSY bit is read
only, but a write operation is allowed. The BUSY bit should be tested
before each write and erase cycle. The flash-timing generator
hardware immediately sets the BUSY bit after the start of a write
operation, a block-write operation, a segment erase, or a mass- erase.
Once the timing generator has completed its function, the BUSY bit is
reset by hardware.
The program and erase timing are shown in Figures C–7, C–8, and
C–9.
0: Flash memory is not busy. Read, write, erase and mass-erase are
possible without any violation of the internal flash timing. The
BUSY bit is reset by POR and by the flash timing generator.
1: Flash memory is busy. Remains in busy state if block write function
is in wait mode.
The conditions for access to the flash memory during BUSY=1 are
described in paragraph C.2.6.
KEYV, 012Ch, bit1, Key Violated.
0: Key 0A5h (high byte) was not violated.
1: Key 0A5h (high byte) was violated. Violation occurs when a write
access to register FCTL1, FCTL2 or FCTL3 is executed and the
high byte is not equal to 0A5h. If the security key is violated, bit
KEYV is set and a PUC is performed. The KEYV bit can be used
to determine the source that forced a start of the program at the
reset vector’s address. The KEYV bit is not automatically reset and
should reset by software.
Note: Any key violation results in a PUC, independent of the state of the
KEYV bit. To avoid endless software loops, the flash memory
control registers should not be written during a key violation
service routine.
Note: The software can set the KEYV bit. A PUC is also performed if
it is set by software.
C-16
Flash Memory Control Registers
EMEX 012Ch, bit5, Emergency exit. The emergency exit should only be used when a flash
memory write or erase operation is out-of-control.
0: No function.
1: Stops the active operation immediately and shuts down all internal
parts of the flash memory controller. Current consumption
immediately drops back to the active mode. All bits in control
register FCTL1 are reset. Since the EMEX bit is automatically reset
by hardware, the software always reads EMEX as 0.
C-18
Flash Memory, Interrupt and Security Key Violation
Figure C–10. Access Violation (Non)Maskable Interrupt Scheme in Flash Memory Module
ACCV
ACCVIFG
S
Flash Module
FCTL1.1
Flash Module
Flash Module
ACCVIE
IE1.5 Clear
VCC POR
KEYV
PO
RST/NMI R PUC
System Reset
Generator POR
NMIIFG
S
TMSEL
NMIES NMI WDTQn EQU PUC POR
PUC
NMIIE
WDTIFG
IE1.4 Clear S IRQ
IFG1.0
OSCFault Clear
Counter WDT
OFIFG POR
S
IRQA
IFG1.4 TIMSEL
WDTIE
OFIE
IE1.0 Clear
IE1.4 Clear
PUC
Watchdog Timer Module
PUC NMI_IRQA
IRQA: Interrupt Request Accepted
no no no
OFIFG=1 ACCVIFG=1 NMIIFG=1
Optional
The NMI handler takes care of all sources requesting a nonmaskable interrupt.
The NMI interrupt is a multiple-source interrupt per MSP430 definition. The
hardware resets the interrupt-enable flags: the external nonmaskable interrupt
enable NMIIE, the oscillator fault interrupt enable OFIE, and the flash memory
access-violation interrupt enable. The individual software handlers reset the
interrupt flags and reenables the interrupt enable bits according to the
application needs. After all software is processed, the interrupt enable bits
have to be set if another NMI event is to be accepted. Setting the interrupt
enable bits should be the last instruction before the return-from-interrupt
instruction RETI. If this rule is violated, the stack can grow out of control while
other NMI requests are already pending. Setting the interrupt enable bits can
be accomplished by using a bit-set-instruction BIS using immediate data or a
mask. The mask data can be modified anywhere via software (for example in
RAM); this constitutes the nonmaskable interrupt processing.
C-20
Flash Memory, Interrupt and Security Key Violation
To protect the software from this error situation, all interrupt sources have to
be disabled since all interrupt requests will fail. The flash memory returns the
vector 03FFFh. Before the interrupt enable bits are modified, they can be
stored in RAM to be restored when the flash memory is ready for access again.
The following interrupt enable bits should be reset to stop all interrupt service
requests:
- GIE = 0
Additionally the watchdog should be halted to prevent its expiration when flash
memory is busy:
- WDTHOLD = 1
When the flash memory is ready, the interrupt sources can be enabled again.
Before they are enabled, critical interrupt flags should be checked and, if
necessary, served or reset by software.
C.5.2 Program Flash Memory Module via Serial Data Link Using JTAG Feature
The hardware interconnection to the JTAG pins is done via four separate pins,
plus the ground or VSS reference level. The JTAG pins are TMS, TCK, TDI
(/VPP), and TDO (/TDI).
TMS TMS
TCK TCK
EN1
TDI TDI
TDO TDO/TDI
VCC 68 kΩ
SN74AHC244 MSP430Fxxx
TCLK XOUT/TCLK
EN2
Test/VPP TEST
VCC/DVCC
AVCC
VSS/DVSS
AVSS
C-22
Flash Memory Access via JTAG and Software
C.5.3.1 Example: Programming One Word Into a Flash Memory Module via Software
Execution Outside This Module
This example assumes that the code to program the flash location is not
executed from the target flash memory module.
yes Test_Busy1
BUSY = 1 BIT #BUSY,&FCTL3
no JNZ Test_Busy1
yes Test_Busy2
BUSY = 1 BIT #BUSY,&FCTL3 ; still busy?
JNZ Test_Busy2 ; yes, repeat busy test
no MOV #FWKEY,&FCTL1 : Reset write bit
LOCK=1 XOR #(FXKEY+LOCK),&FCTL3 : Change lock bit to 1
Restore or Enable Required ; Enable those interrupt sources that should be accepted
Interrupt Sources and Watchdog
The BUSY bit can be tested before the write to the flash memory module is
done, or after a write (program) starts:
- For flash memory locations that hold data, it is a good practice to test the
BUSY bit before the write is executed. This has some time benefits, since
the write process is executed via the flash memory timing generator with-
out further CPU intervention. It is important that the clock source remains
active until BUSY is reset by the flash memory hardware.
The power or clock management, responsible for entering low-power
modes, has to make sure that it does not switch off the clock source used
by the flash controller.
- For flash memory blocks that hold program code, it is a good practice to
test the BUSY bit after the write is executed. The program can only
proceed if the module can be accessed again. No special attention is
needed during execution of software code. Every write to the flash
memory module has to leave the programming cycle with the BUSY bit
reset.
Testing the BUSY bit before writing to a flash memory block that holds
program code ensures that the active program will not access the flash
memory module. Two types of access are visible: execute program code,
or read and write data on this flash memory module.
C.5.3.2 Example: Programming One Word Into the Same Flash Memory Module via Software
C-24
Flash Memory Access via JTAG and Software
C.5.3.3 Example, Programming Byte Sequences Into a Flash Memory Module via Software
Sequences of data, bytes, or words can use the block-write feature. This
reduces the programming time by about one half.
RAM2FLASH
MOV #Start_Ptr,Rx
Set Pointer for Start and End MOV #End_Ptr,Ry
Clear Lock Bit MOV #FWKEY,&FCTL3 ; Clear lock bit
Test_Busy1
yes BIT #BUSY,&FCTL3 ; Flash busy? BLKWRT ended?
Busy ?
JNZ Test_Busy1
no
SEG WRT = WRT =1 MOV #(FWKEY+WRT+BLKWRT), &FCTL3 ; Block write
Test_WAIT1
yes
WAIT = 1 BIT #WAIT,&FCTL3
JNE Test_WAIT1
no
End_Seg_Write
; All data are programmed
SEG WRT = WRT =0
MOV #FWKEY,&FCTL1 ; Stop block write
yes Test_Busy2
Busy ? BIT #BUSY,&FCTL3 ; Block write ended?
JNZ Test_Busy2
no XOR #(FXKEY+LOCK),&FCTL3 ; Change Lock bit to 1
End of Block Write
C.5.3.4 Example, Erase Flash Memory Segment or Module via Software Execution
Outside This Flash Module
Test_Busy1
yes
BUSY = 1 BIT #BUSY,&FCTL3
JNZ Test_Busy1
Segment Erase: Erase = 1
MOV #(FWKEY+Erase),&FCTL1 ; select segment erase
or
Mass Erase: MEras = 1
CLR &0F000h
Dummy Write
Test_Busy2
BIT #BUSY,&FCTL3
yes JNZ Test_Busy2
BUSY = 1
C.5.3.5 Example, Erase Flash Memory Segment Module in the Same Flash Memory Module
via Software
Disable all interrupt sources ; Disable all possible interrupt sources and watchdog
and Watchdog
Restore or Enable Required ; Enable those interrupt sources that should be accepted
Interrupt Sources and Watchdog
Software that controls write, erase, or mass-erase can be located in the flash
memory module and copied during execution into RAM. In this case the code
should be written position-independent, and should be loaded (for instance,
to RAM) before it is used. The algorithm runs in RAM during the programming
sequence to avoid conflict when the flash memory is written or erased.
C-26
Flash Memory Access via JTAG and Software
Start-of-Subroutine: Load_Flash_Routine
End-of-Source Code ?
End-of-Subroutine: RET
;------------------------------------------------------------
; Definitions used in Subroutine:
; Move programming code sequence into RAM (load_flash_routine)
;------------------------------------------------------------
Flash_ram .set 0222h ; Start address of flash
; program in the RAM
; program in the RAM
Prg_source_start .set 0xxxxh ; Start address of code
; in the flash to be prg’ed
Prg_source_end .set 0yyyyh ; End address of code
; in the flash to be prg’ed
Prg_dest_start .set Flash_ram
load_flash_routine ; The code of the program which moves
; Flash access code (write, erase,..)
; starts at label load_flash_routine
push r9
push r10
mov #Prg_source_start,R9 ; load pointer source
mov #Prg_dest_start,R10 ; load pointer destination
load_flash_prg
mov @R9,0(R10) ; move a word
incd R10 ; destination pointer + 2
incd R9 ; source pointer + 2
cmp # Prg_source_end,R9 ; compare to end_of_code
jne load_ flash_prg
pop r9
pop r10
ret