Cover Page

IEEE Press

445 Hoes Lane

Piscataway, NJ 08854

IEEE Press Editorial Board

Tariq Samad, Editor in Chief

George W. Arnold Vladimir Lumelsky Linda Shafer
Dmitry Goldgof Pui-In Mak Zidong Wang
Ekram Hossain Jeffrey Nanzer MengChu Zhou
Mary Lanzerotti Ray Perez George Zobrist

Kenneth Moore, Director of IEEE Book and Information Services (BIS)

Practical Microcontroller Engineering with ARM® Technology

Ying Bai

Department of Computer Science and Engineering
Johnson C. Smith University
Charlotte, North Carolina

Wiley Logo

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 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:

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

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.
452
453
454
455
456
458
488
489
490
491
492
494
503
504
Chapter 8

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.
556
558
559
559
560
563
612
612
613
614
615
617
618
644
652
Chapter 9 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.
807
809
820
851
852
900

Table II lists the copyright permitted Figures and Tables originated by the ARM Limited and used in this book. All those Figures and Tables have been reproduced with permission from ARM Limited. Copyright © ARM Limited.

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.
87
88
92
93
94
95
95
96
97
98
99
99
100
103
103
104
105
106
108
108
109
110
111
111
112
114
114
116
116
117
117
119
119
120
123
125
134
139
141
Chapter 4 Figure 4.38: The finished Options wizard. 236
Chapter 6 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.
875
876
876
877
878
879
880
880
881
882
883
886
890
890
898
Chapter 11 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:

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.