Published by John Wiley & Sons, Inc., Hoboken, New Jersey. All rights reserved
Published simultaneously in Canada
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 750-4470, or on the web at www.copyright.com. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permission.
Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this book, they make no representations or warranties with respect to the accuracy or completeness of the contents of this book and specifically disclaim any implied warranties of merchantability or fitness for a particular purpose. No warranty may be created or extended by sales representatives or written sales materials. The advice and strategies contained herein may not be suitable for your situation. You should consult with a professional where appropriate. Neither the publisher nor author shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages.
For general information on our other products and services or for technical support, please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic formats. For more information about Wiley products, visit our web site at www.wiley.com.
Library of Congress Cataloging-in-Publication Data is available.
ISBN: 978-1-119-05237-1
Dedication
This book is dedicated to my wife, Yan Wang, and to my daughter, Susan (Xue) Bai.
Preface
The ARM® Cortex®-M4 MCU is one of the most popular and updated microcontrollers widely implemented in education, industrial, and manufacturing fields in recent years. Because of their relatively simple structure and powerful functions, the ARM® Cortex®-M4 MCU systems have been applied in more and more applications in our real world, including automatic controls, intelligent controls, industrial controls, and academic implementations.
The advantages of using an ARM® Cortex®-M4 microcontroller include but are not limited to the following:
The ARM® Cortex®-M4 MCU is a 32-bit microcontroller, and it can work independently as a single controller to provide real-time and multifunction controls to effectively and easily control most real objectives in our world.
The internal bus system used in Cortex®-M4 MCU is 32-bit, and it is based on the so-called Advanced Microcontroller Bus Architecture (AMBA) standard. The AMBA standard provides efficient operations and low power cost on the hardware.
The main bus interface between the MCU and external components is the Advanced High-performance Bus (AHB), which provide interfaces for memory and system bus, as well as peripheral devices.
A Nested Vectored Interrupt Controller (NVIC) is used to provide all supports and managements to the interrupt responses and processing to all components in the system.
The Cortex®-M4 MCU also provides standard and extensive debug features and helps to enable users to easily check and trace their program with breakpoints and steps.
The TM4C123GXL EVB provides fundamental and basic peripherals and interfaces to enable users to conveniently communicate to other parallel or serial peripherals via GPIO Ports to perform specific control tasks and functions.
The EduBASE ARM® Trainer provides the most popular I/O devices, such as 4-LED, a 4-bit DIP switch, four 7-segment LEDs, a 4×4 keypad working as an input keyboard, a 16×2 LCD connected to the LCD Controller HD44780 to work as an output displaying device, two H-Bridge motor drivers, three analog input sensors, a CAN protocol and other peripheral interfaces. All of these I/O devices and interfaces provide great flexibility to enable users to design and build advanced and professional control units applied in our real world.
The integrated development environment Keil® ARM-MDK μVersion®5 provides an integrated development environment to enable users to easily create, compile, build, and run professional application projects to control and coordinate the entire control system to perform a desired task in short period of time.
The author of this book tries to provide a complete package to cover all components and materials related to ARM® Cortex®-M4 microcontroller systems, including hardware and software as well as practical application notes with real examples. All example projects in the book have been compiled, built, and tested. To help students to master the main techniques and ideas, five appendices are provided to facilitate the students to overcome some possible learning curves.
Any questions or comments regarding this book are welcome.
Charlotte, North Carolina
Ying Bai
Acknowledgments
The first and most special thanks go to my wife, Yan Wang; I could not finish this book without her sincere encouragements and supports.
Many thanks should be given to the editor Mary Hatcher, who made this book available to the public. You could not find this book on the market without her deep perspective and hard work. The same thanks are extended to the editing team for this book. Without their contributions, it would have been impossible for this book to have been published.
Acknowledgments should also be extended to the following book reviewers for their valuable opinions to the book:
Dr. Jiang (Linda) Xie, Professor, Department of Electrical and Computer Engineering, University of North Carolina at Charlotte
Dr. Xiaohong Yuan, Associate Professor, Department of Computer Science, North Carolina A&T State University
Dr. Daoxi Xiu, Application Analyst Programmer, North Carolina Administrative Office of the Courts
Dr. Dali Wang, Associate Professor, Department of Physics and Computer Science, Christopher Newport University
Last but not least, thanks should be given to all the people who have supported me while writing this book.
Ying Bai
Trademarks and Copyrights
ARM®, Cortex®, Keil® and μVision® are registered trademarks of ARM Limited (or its subsidiaries) in the EU and/or elsewhere.
ARM7™, ARM9™ and ULINK™ are trademarks of ARM Limited (or its subsidiaries) in the EU and/or elsewhere. All rights reserved.
MATLAB® is a trademark and product of The MathWorks, Inc.
MATLAB Simulink® is a trademark and product of The MathWorks, Inc.
MATLAB System Identification Toolbox™ is a trademark and product of The MathWorks, Inc.
MATLAB System Control Toolbox™ is a trademark and product of The MathWorks, Inc.
MATLAB Fuzzy Logic Toolbox™ is a trademark and product of The MathWorks, Inc.
Texas Instruments™ is a trade mark of the Texas Instruments Incorporated.
Tiva™ is a trademark and product of the Texas Instruments Incorporated.
TivaWare™ is a trademark and product of the Texas Instruments Incorporated.
LaunchPad™ is a trademark and product of the Texas Instruments Incorporated.
Code Composer Studio™ is a trademark and product of the Texas Instruments Incorporated.
Stellaris® is a trademark and product of the Texas Instruments Incorporated.
Copyright Permissions
All copyright permitted Figures and Tables used in this book are listed below based on the different venders and companies.
Table I lists the copyright permitted Figures and Tables originated by the Texas Instruments Incorporated and used in this book. All those Figures and Tables have been permitted to be re-printed in this book under the copyright permissions of the Texas Instruments Incorporated.
Table I Copyright Permitted Figures and Tables by Texas Instruments Incorporated.
Chapter
Figures and Tables
Page
Chapter 2
Figure 2.14: Block diagram of TM4C123GH6PM MCU. Figure 2.17: Function block diagram of Analog/Digital GPIO control. Figure 2.20: The TM4C123GXL evaluation board. Figure 2.21: The functional block diagram of the LaunchPad board. Table 2.3: Exception and interrupt types and priority numbers. Table 2.8: GPIO Pins with special considerations.
39 48 73 76 36 58
Chapter 4
Figure 4.34: An example of using mask byte to do data reading and writing.
230
Chapter 5
Figure 5.6: An example of the NVIC Priority Level Register PRI0.
276
Chapter 6
Figure 6.3: Bit field and function on BOOTCFG Register. Figure 6.4: Bit field and function on FMA Register. Figure 6.5: Bit field and function on the FMC Register. Figure 6.6: Bit field and function on the FMC2 Register. Figure 6.7: Bit field and function on FCRIS Register. Figure 6.8: Bit field and function on FCIM Register. Figure 6.9: Bit field and function on FCMISC Register. Figure 6.11: The functional block diagram of the EEPROM. Figure 6.12: The bit field values and related functions in the EEDONE register. Figure 6.13: The bit field values and related functions in the EEPROT register.
339 341 342 343 344 346 347 355 358 360
Chapter 7
Figure 7.12: The bit fields for the ADCSSMUX0 register. Figure 7.13: The bit fields for the ADCSSMUX1, 2 registers. Figure 7.14: The bit fields for the ADCSSMUX3 register. Figure 7.15: The bit fields for the ADCSSCTL0 register. Figure 7.16: The bit fields for the ADCSSCTL1, 2 registers. Figure 7.17: The bit fields for the ADCSSCTL3 register. Figure 7.32: PWM Count-Down and Count Up/Down modes. Figure 7.33: An example of using the count-up/down mode to generate PWM outputs. Figure 7.34: The output PWM signals generated by Dead-Band generator. Figure 7.35: The detailed block diagram for the PWM Generator block. Figure 7.36: Bit fields in the PWM generator control register. Figure 7.37: Bit fields in the PWM generator A register. Figure 7.41: Architecture and functional block diagram of PWM module. Figure 7.42: Bit fields in the Run-Mode Clock Configuration (RCC) register.
Figure 8.4: Functional block diagram of the SSI module. Figure 8.5: Operational timing sequence of the TI synchronous serial frame. Figure 8.6: The operational sequence for Freescale SPI frame (SPO = SPH = 0). Figure 8.7: The operational sequence for Freescale SPI frame (SPO = 0, SPH = 1). Figure 8.8: The operational sequence for MACROWIRE frame. Figure 8.11: The bit field and functions of the SSICR0 Register. Figure 8.42: The I2C bus configuration and status. Figure 8.43: The definition of START and STOP conditions. Figure 8.44: The functional block diagram of each I2C module. Figure 8.45: The I2C data transfer format and frame. Figure 8.46: The operational sequence of the master working in the transmit mode. Figure 8.47: The operational sequence of the master working in the receive mode. Figure 8.48: The operational sequence of the I2C module working in the slave mode. Figure 8.62: The functional block diagram for one UART module. Figure 8.65: Bit configurations of the UARTCTL register.
Figure 9.1: The architecture and block diagram of one GPTM block. Figure 9.3: An example of using a count-down timer to detect input edge events. Figure 9.4: An example of using the count-down mode timer to detect the edge time. Figure 9.5: An example of using Timer A to generate a PWM signal. Figure 9.20: The functional block diagram of the watchdog modules. Figure 9.27: Functional block diagram of the USB module.
693 700 701 703 734 760
Chapter 10
Figure 10.2: A typical standard CAN frame format. Figure 10.3: Functional block diagram of the CAN modules. Figure 10.5: A normal CAN bit time configuration. Figure 10.25: Functional block diagram of the QEI Modules. Figure 10.26: The inversion and swapping logic circuit. Figure 10.63: Architecture and functional block diagram of the Analog Comparator modules.
Table II Copyright Permitted Figures and Tables by ARM Limited.
Chapter
Figures and Tables
Page
Chapter 3
Figure 3.4: The components included in the MDK Core. Figure 3.5: Components in the Software Packs. Figure 3.9: The opened Keil® MDK-ARM μVersion® 5.1 suite. Figure 3.11: The opened Hello World project. Figure 3.12: The opened source file hello.c. Figure 3.13: Rebuild the hello project. Figure 3.14: The building result of the hello project. Figure 3.15: The debugging result of the hello world project. Figure 3.16: The opened MDK-ARM IDE. Figure 3.17: The opened Device Database wizard. Figure 3.18: The detailed information for the device TM4C123GH6PM. Figure 3.19: The License Management wizard. Figure 3.20: An example of the Configuration submenu. Figure 3.22: The Select Device for Target wizard. Figure 3.23: The Manage Run-Time Environment wizard. Figure 3.24: The selected components in the Manage Run-Time Environment wizard. Figure 3.25: The new project wizard. Figure 3.26: The Add New Item to Group wizard. Figure 3.28: The finished codes for the source file MyProject.c. Figure 3.29: Add a header file MyProject.h into the project. Figure 3.31: The finished header file MyProject.h. Figure 3.32: The project building process. Figure 3.33: The finished debugger checking wizard. Figure 3.34: The download process for our project. Figure 3.35: The debug process for our project. Figure 3.36: The Components, Environment, Books wizard. Figure 3.37: The Manage Run-Time Environment wizard for our sample project. Figure 3.38: Functions provided by the Options for Target Project wizard. Figure 3.39: The Target option for the sample project MyProject. Figure 3.40: The Output option for the sample project MyProject. Figure 3.41: The Listing option for the sample project MyProject. Figure 3.42: The Debug option for the sample project MyProject. Figure 3.43: The Utilities option for the sample project MyProject. Figure 3.44: The opened Settings wizard. Figure 3.45: An example of using System Viewer for TIMER0 device. Figure 3.46: The Nested Vectored Interrupt Controller configuration dialog. Figure 3.50: A debug example for our sample project MyProject. Figure 3.51: The optimization wizard for our sample project. Figure 3.52: An example of using the code optimization under the Target tab.
Figure 6.26: The running result of the project DRAFlash. Figure 6.27: The 1-KB erased flash memory block (0x1000~0x13FF). Figure 6.32: The running result of the DRAFlashInt project. Figure 6.34: The running result of the project DRAFlashBuffer. Figure 6.38: The 18 read-out data stored in the data array prData[]. Figure 6.42: The read back data stored in the prData[] array.
387 388 397 400 414 420
Chapter 8
Figure 8.74: Running result of the project DRAUART. Figure 8.75: Running result of the project Lab8_5. Figure 8.76: Running result of the project Lab8_6.
664 685 689
Chapter 11
Figure 11.6: The FPU is automatically used in MDK-ARM μVersion 5 IDE. Figure 11.11: The running result of the project DRAFPU.
939 945
Table III list the copyright permitted Figures and Tables originated by the MathWorks, Inc. and used in this book. All those Figures and Tables have been permitted to be re-printed in this book under the copyright permissions of the MathWorks, Inc.
Chapter
Figures and Tables
Page
Chapter 10
Figure 10.38: The MATLAB Script file getMData.m. Figure 10.39: Load the data array mdata.dat into the MATLAB Workspace. Figure 10.40: The opened Identification Toolbox and Import data wizard. Figure 10.41: The modified data array mdatad in the identification Toolbox. Figure 10.42: The opened Process Models wizard. Figure 10.43: The identified model responses and analysis. Figure 10.44: Commands used to set transfer function of the DC motor and start PID tuner. Figure 10.45: The opened PID Tuner and the tuning result. Figure 10.46: The opened SIMULINK window. Figure 10.47: The finished SIMULINK bock connections. Figure 10.48: The simulated step response result. Figure 10.51: The step response of the actual closed-loop motor control system. Figure 10.55: Graphic representation of the control rules. Figure 10.56: The fuzzy output surface or envelope. Figure 10.62: The step response of the fuzzy logic control system.
Figure 11.12: The plotting result for the data array gSData[].
945
About the Companion Website
This book is accompanied by a companion website: http://www.wiley.com/go/armbai
The website includes:
Class Projects
Appendix A
Appendix B
Appendix C
Appendix D
Appendix E
If you are an instructor and adopted this book for your course, please email ieeeproposals@wiley.com to get access to the instructor files for this book.