MSP430 Microcontroller Basics John H. Davies AMSTERDAM BOSTON HEIDELBERG LONDON NEW YORK OXFORD PARIS SAN DIEGO SAN FRANCISCO SINGAPORE SYDNEY TOKYO Newnes is an imprint of Elsevier N WPIGS
Contents Preface xi Chapter 1: Embedded Electronic Systems and Microcontrollers 7 1.1 What (and Where) Are Embedded Systems? 1 1.2 Approaches to Embedded Systems 2 1.3 Small Microcontrollers 5 1.4 Anatomy of a Typical Small Microcontroller 8 1.5 Memory 11 1.6 Software 15 1.7 Where Does the MSP430 Fit? 16 Chapter 2: The Texas Instruments MSP430 21 2.1 The Outside View Pin-Out 21 2.2 The Inside View Functional Block Diagram 24 2.3 Memory 25 2.4 Central Processing Unit 30 2.5 Memory-Mapped Input and Output 32 2.6 Clock Generator 33 2.7 Exceptions: Interrupts and Resets 36 2.8 Where to Find Further Information 37 Chapter 3: Development 43 3.1 Development Environment 44 3.2 The С Programming Language 46 3.3 Assembly Language 55 3.4 Access to the Microcontroller for Programming and Debugging 57 3.5 Demonstration Boards 59 3.6 Hardware 64 3.7 Equipment 65
viii Contents Chapter 4: A Simple Tour of the MSP430 67 4.1 First Program on a Conventional Desktop Computer 68 4.2 Light LEDs in С 70 4.3 Light LEDs in Assembly Language 72 4.4 Read Input from a Switch 80 4.5 Automatic Control: Flashing Light by Software Delay 91 4.6 Automatic Control: Use of Subroutines 99 4.7 Automatic Control: Flashing Light by Polling Timer_A 105 4.8 Header Files and Issues Brushed under the Carpet 114 Chapter 5: Architecture of the MSP430 Processor 119 5.1 Central Processing Unit 119 5.2 Addressing Modes 125 5.3 Constant Generator and Emulated Instructions 131 5.4 Instruction Set 132 5.5 Examples 146 5.6 Reflections on the CPU and Instruction Set 153 5.7 Resets 157 5.8 Clock System 163 Chapter 6: Functions, Interrupts, and Low-Power Modes 7 77 6.1 Functions and Subroutines 178 6.2 What Happens when a Subroutine Is Called? 178 6.3 Storage for Local Variables 179 6.4 Passing Parameters to a Subroutine and Returning a Result 183 6.5 Mixing С and Assembly Language 185 6.6 Interrupts 186 6.7 What Happens when an Interrupt Is Requested? 188 6.8 Interrupt Service Routines 190 6.9 Issues Associated with Interrupts 196 6.10 Low-Power Modes of Operation 198 Chapter 7: Digital Input, Output, and Displays 207 7.1 Digital Input and Output: Parallel Ports 208 7.2 Digital Inputs 216 7.3 Switch Debounce 225 7.4 Digital Outputs 238 7.5 Interface between 3V and 5V Systems 243 7.6 Driving Heavier Loads 247 7.7 Liquid Crystal Displays 252 7.8 Driving an LCD from an MSP430x4xx 256 7.9 Simple Applications of the LCD 264
Contents ix Chapter 8: Timers 275 8.1 Watchdog Timer 276 8.2 Basic Timerl 281 8.3 Timer_A 287 8.4 Measurement in the Capture Mode 300 8.5 Output in the Continuous Mode 318 8.6 Output in the Up Mode: Edge-Aligned Pulse-Width Modulation 330 8.7 Output in the Up/Down Mode: Centered Pulse-Width Modulation 349 8.8 Operation of Timer_A in the Sampling Mode 352 8.9 Timer_B 353 8.10 What Timer Where? 356 8.11 Setting the Real-Time Clock: State Machines 357 Chapter 9: Mixed-Signal Systems: Analog Input and Output 369 9.1 Comparator_A 371 9.2 Analog-to-Digital Conversion: General Issues 393 9.3 Analog-to-Digital Conversion: Successive Approximation 402 9.4 The ADC10 Successive-Approximation ADC 407 9.5 Basic Operation of the ADC 10 412 9.6 More Advanced Operation of the ADC10 424 9.7 The ADC12 Successive-Approximation ADC 432 9.8 Analog-to-Digital Conversion: Sigma-Delta 438 9.9 The SD16_A Sigma-Delta ADC 446 9.10 Operation of SD16_A 459 9.11 Signal Conditioning and Operational Amplifiers 475 9.12 Digital-to-Analog Conversion 485 Chapter 10: Communication 493 10.1 Communication Peripherals in the MSP430 495 10.2 Serial Peripheral Interface 497 10.3 SPI with the USI 504 10.4 SPI with the USCI 513 10.5 A Thermometer Using SPI in Mode 3 with the F2013 as Master 520 10.6 A Thermometer Using SPI in Mode 0 with the FG4618 as Master 526 10.7 Inter-integrated Circuit Bus 534 10.8 ASimplePCMasterwiththeUSCI_B0onaFG4618 542 10.9 A Simple PC Slave with the USI on a F2013 549 10.10 State Machines for PC Communication 559 10.11 A Thermometer Using PC with the F2013 as Master 567 10.12 Asynchronous Serial Communication 574 10.13 Asynchronous Communication with the USCI_A 581
x Contents 10.14 A Software UART Using Timer_A 590 10.15 Other Types of Communication 599 Chapter 11: The Future: MSP430X 601 11.1 Architecture of the MSP430X 601 11.2 Instruction Set of the MSP430X 607 11.3 Where Next? 614 11.4 Conclusion 617 Appendix A: Kickstarting the MSP430 679 A. 1 Introduction to EW430 619 A.2 Developing a Project in С 621 A.3 Debugging with the Simulator 627 A.4 Debugging with the Emulator 630 A.5 Developing a Project in Assembly Language 633 A.6 Tips for Using EW430 636 A.7 Tips for Specific Development Kits 640 Appendix B: Further Reading 645 Books and Articles 645 Newsletters, Magazines, and Journals 651 Index 655