Microcontroller Engineering with MSP432 : Fundamentals and Applications book cover
1st Edition

Microcontroller Engineering with MSP432
Fundamentals and Applications





ISBN 9781498772983
Published October 20, 2016 by CRC Press
844 Pages 327 B/W Illustrations

FREE Standard Shipping
USD $140.00

Prices & shipping based on shipping country


Preview

Book Description

This book aims to develop professional and practical microcontroller applications in the ARM-MDK environment with Texas Instruments MSP432P401R LaunchPad kits. It introduces ARM Cortex-M4 MCU by highlighting the most important elements, including: registers, pipelines, memory, and I/O ports. With the updated MSP432P401R Evaluation Board (EVB), MSP-EXP432P401R, this MCU provides various control functions with multiple peripherals to enable users to develop and build various modern control projects with rich control strategies. Micro-controller programming is approached with basic and straightforward programming codes to reduce learning curves, and furthermore to enable students to build embedded applications in more efficient and interesting ways. For authentic examples, 37 Class programming projects are built into the book that use MSP432P401R MCU. Additionally, approximately 40 Lab programming projects with MSP432P401R MCU are included to be assigned as homework.

Table of Contents

Contents

Preface............................................................................................................................................ xix

Acknowledgments....................................................................................................................... xxi

Author..........................................................................................................................................xxiii

Trademarks and references........................................................................................................ xxv

Chapter 1 Introduction to microcontrollers and this book.................................................1

1.1 Microcontroller configuration and structure....................................................................1

1.2 ARM® Cortex®-M4 microcontroller system.......................................................................3

1.3 MSP432P401R microcontroller and its development tools and kits...............................4

1.4 Outstanding features about this book................................................................................4

1.5 Who this book is for..............................................................................................................5

1.6 What this book covers...........................................................................................................5

1.7 How this book is organized and how to use this book...................................................7

1.8 How to use the source code and sample projects.............................................................7

1.9 Instructors and customers supports................................................................................. 10

Chapter 2 MSP432 microcontroller architectures................................................................11

2.1 Overview.............................................................................................................................. 11

2.2 Introduction to ARM• Cortex•-M4 MCU........................................................................ 12

2.2.1 Architecture of ARM• Cortex•-M4 MCU.......................................................... 15

2.2.1.1 ARM• MCU architecture block diagram.......................................... 15

2.2.1.2 Architecture of the ARM• Cortex•-M4 core (CPU)......................... 17

2.2.1.3 Architecture of the floating-point registers......................................22

2.3 Introduction to MSP-432™ MCU family member—MSP432P401R..............................25

2.3.1 MSP432P401R microcontroller overview............................................................25

2.3.2 MSP432P401R microcontroller on-chip memory map......................................26

2.3.3 System peripherals................................................................................................29

2.3.3.1 On-chip peripherals.............................................................................29

2.3.3.2 Interfaces to external parallel and serial peripherals...................... 31

2.3.4 MSP432P401R microcontroller GPIO modules.................................................. 32

2.3.4.1 MSP432P401R GPIO ports architecture............................................. 32

2.3.4.2 General digital I/O function control..................................................33

2.3.4.3 PM control..............................................................................................40

2.3.4.4 Comparison between the digital I/O function control

and PM control......................................................................................42

2.3.4.5 Initialization and configuration of GPIO ports................................43

2.3.5 MSP432P401R microcontroller system controls.................................................44

2.3.5.1 MCU system reset control...................................................................45

2.3.5.2 Power supply system (PSS)..................................................................48

2.3.5.3 Power control manager (PCM)...........................................................50

2.3.5.4 System clock control.............................................................................53

2.3.5.5 System controller (SYSCTL).................................................................65

2.4 Introduction to MSP432P401R LaunchPad™ MSP-EXP432P401R evaluation board......65

2.4.1 Onboard hardware configurations..................................................................... 70

2.4.2 GPIO pins configurations on booster pack interface connectors (J1~J4)........ 70

2.5 Introduction to EduBASE ARM• trainer..........................................................................72

2.6 Chapter summary...............................................................................................................73

Chapter 3 MSP432 microcontroller development kits........................................................79

3.1 Overview..............................................................................................................................79

3.2 Entire MSP432P401R-based development system...........................................................80

3.3 Download and install development suite and specified firmware..............................82

3.4 Introduction to the IDE: Keil• MDK µVersion5...............................................................82

3.4.1 Keil• MDK-ARM• for the MDK-Cortex-M family............................................84

3.4.2 General development flow with MDK-ARM•................................................... 85

3.4.3 Functions of the Keil• MDK-ARM• µVersion•5 GUI....................................... 87

3.4.3.1 File menu................................................................................................89

3.4.3.2 Edit and view menus............................................................................90

3.4.3.3 Project menu..........................................................................................92

3.4.3.4 Flash menu........................................................................................... 111

3.4.3.5 Debug menu........................................................................................ 112

3.4.3.6 Peripherals menu................................................................................ 113

3.4.3.7 Tools menu........................................................................................... 113

3.4.3.8 Software version control system (SVCS) menu.............................. 115

3.4.3.9 Window menu..................................................................................... 116

3.4.3.10 Help menu............................................................................................ 116

3.5 Embedded software development procedure............................................................... 117

3.6 ARM•-MDK µVision5 debugger and debug process................................................... 117

3.6.1 ARM• µVision5 debug architecture.................................................................. 119

3.6.2 ARM• debug adaptor and debug adaptor driver........................................... 120

3.6.3 MSP432™ Family Launchpad™ debug adaptor and debug

adaptor driver.......................................................................................................122

3.6.4 ARM• µVersion5 debug process........................................................................122

3.7 MSP432™ family software suite...................................................................................... 123

3.7.1 MSPWare for MSP432™ series software package........................................... 125

3.7.1.1 Peripheral driver library (driverlib).................................................. 126

3.7.1.2 Boot loader........................................................................................... 126

3.7.1.3 Code examples.................................................................................... 127

3.8 MSP432™ series CMSIS support..................................................................................... 127

3.9 Chapter summary............................................................................................................. 128

Chapter 4 ARM® microcontroller software and instruction set.....................................131

4.1 Overview............................................................................................................................ 131

4.2 Introduction to ARM• Cortex•-M4 software development structure....................... 132

4.3 ARM• Cortex•-M4 assembly instruction set................................................................. 133

4.3.1 ARM• Cortex•-M4 assembly language syntax............................................... 134

4.3.2 ARM• Cortex•-M4 pseudo instructions.......................................................... 136

4.3.3 ARM• Cortex•-M4 addressing modes............................................................. 137

4.3.3.1 Immediate offset addressing mode.................................................. 137

4.3.3.2 Register offset addressing mode...................................................... 139

4.3.3.3 PC-relative addressing mode............................................................ 141

4.3.3.4 Load and store multiple registers addressing mode..................... 142

4.3.3.5 PUSH and POP register addressing mode...................................... 145

4.3.3.6 Load and store register exclusive addressing mode...................... 145

4.3.3.7 Inherent addressing mode................................................................. 146

4.3.3.8 Addressing mode summary............................................................. 147

4.3.4 ARM• Cortex•-M4 instruction set categories................................................. 147

4.3.4.1 Data moving instructions.................................................................. 147

4.3.4.2 Arithmetic instructions..................................................................... 149

4.3.4.3 Logic instructions............................................................................... 152

4.3.4.4 Shift and rotate instructions............................................................. 153

4.3.4.5 Data conversion instructions............................................................ 155

4.3.4.6 Bit field processing instructions....................................................... 157

4.3.4.7 Compare and test instructions.......................................................... 161

4.3.4.8 Program flow control instructions................................................... 162

4.3.4.9 Saturation instructions....................................................................... 166

4.3.4.10 Exception-related instructions.......................................................... 168

4.3.4.11 Sleep mode instructions.................................................................... 169

4.3.4.12 Memory barrier instructions............................................................. 169

4.3.4.13 Miscellaneous instructions............................................................... 170

4.4 ARM• Cortex•-M4 software development procedures............................................... 170

4.5 Using C language to develop MSP432P401R microcontroller applications.............. 172

4.5.1 Standard data types used in intrinsic functions............................................ 172

4.5.2 CMSIS core-specific intrinsic functions........................................................... 174

4.5.3 Keil• ARM• compiler-specific intrinsic functions.......................................... 177

4.5.4 Inline assembler................................................................................................... 177

4.5.5 Naming convention and definition in C programming developments........... 181

4.5.6 MSPWare peripheral driver library.................................................................. 182

4.5.6.1 Programming models........................................................................ 182

4.5.6.2 DRA model.......................................................................................... 182

4.5.6.3 Peripheral driver library and API functions................................... 190

4.5.6.4 Comparison between two programming models......................... 199

4.5.6.5 Combined programming model example.......................................200

4.6 Chapter summary.............................................................................................................204

Chapter 5 MSP432 microcontroller interrupts and exceptions......................................221

5.1 Overview............................................................................................................................ 221

5.2 Exceptions and interrupts in the ARMR CortexR-M4 MCU system...........................222

5.2.1 Exception and interrupt types...........................................................................223

5.2.2 Exceptions and interrupts management.......................................................... 224

5.2.3 Exception and interrupt processing..................................................................228

5.2.3.1 Exception and interrupt inputs and pending status.....................229

5.2.3.2 Exception and interrupt vector table...............................................230

5.2.3.3 Definitions of the priority levels....................................................... 231

5.3 Exceptions and interrupts in the MSP432P401R microcontroller system..................233

5.3.1 Local interrupts configurations and controls for GPIO pins........................236

5.3.2 Local interrupts configurations and controls for GPIO ports....................... 237

5.3.2.1 NVIC interrupt priority level registers............................................238

5.3.2.2 NVIC Interrupt set enable registers (ISERs)................................... 242

5.3.3 Global interrupts configurations and controls................................................ 243

5.3.4 GPIO interrupt handling and processing procedure..................................... 244

5.4 Developing GPIO port interrupt projects to handle GPIO interrupts....................... 245

5.4.1 Using DRA programing model to handle GPIO interrupts.......................... 245

5.4.1.1 Create a new project DRAInt and the header file.......................... 246

5.4.1.2 Create a new C code file DRAInt and add it into the project....... 247

5.4.1.3 Set up environment to compile and run the project...................... 249

5.4.2 Using CMSIS-core macros for NVIC registers to handle

GPIO interrupts................................................................................................. 249

5.4.2.1 Popular data structures defined in the MSP432P401R

header file.............................................................................................250

5.4.2.2 IRQ numbers defined in the MSPWare system header file.......... 252

5.4.2.3 NVIC macros defined in the MSPWare system header files........255

5.4.2.4 NVIC structure defined in the CMSIS-core header file................256

5.4.2.5 Building sample project to use CMSIS-core macros for

NVIC to handle interrupts................................................................258

5.4.2.6 Create a new project NVICInt and add the C code file................. 259

5.4.3 Using MSPPDL API functions to handle GPIO interrupts............................ 261

5.4.3.1 NVIC API functions defined in the MSPPDL................................. 261

5.4.3.2 GPIO interrupt-related API functions in the MSPPDL................. 262

5.4.3.3 Building sample project to use API functions to handle

interrupts.............................................................................................264

5.4.3.4 Create a new project SDInt and add the C code file......................265

5.4.3.5 Configure environments and run the project................................. 266

5.4.4 Using CMSIS-core access functions to handle GPIO interrupts................... 268

5.4.4.1 Building a sample project to use CMSIS-core functions

to handle interrupts............................................................................ 269

5.4.4.2 Create a new project CMSISInt and add the C code file............... 270

5.4.4.3 Configure environments and run the project................................. 272

5.5 Comparison among four interrupt programing methods.......................................... 272

5.6 Chapter summary............................................................................................................. 273

Chapter 6 ARM® and MSP432™ MCU memory system...................................................289

6.1 Overview............................................................................................................................ 289

6.2 Memory architecture in the MSP432P401R MCU system............................................290

6.3 Static random-access memory (SRAM).......................................................................... 291

6.3.1 SRAM memory map in the MSP432P401R MCU system............................... 292

6.3.2 SRAM control and status registers................................................................... 293

6.3.2.1 SRAM size (SYS_SRAM_SIZE) register.......................................... 293

6.3.2.2 SRAM bank enable (SYS_SRAM_BANKEN) register................... 293

6.3.2.3 SRAM bank retention control register

(SYS_SRAM_BANKRET)................................................................... 294

6.3.3 Bit-band operations............................................................................................. 297

6.3.3.1 Mapping relationship between the bit-band region

and bit-band alias region................................................................... 298

6.3.3.2 Advantages of using the bit-band operations................................. 298

6.3.3.3 Illustration example of using bit-band alias addresses.................300

6.3.3.4 Bit-band operations for different data sizes....................................302

6.3.3.5 Bit-band operations built in C programs.........................................302

6.4 Internal ROM......................................................................................................................303

6.4.1 Bootstrap loader (BSL).........................................................................................304

6.4.2 MSPWare peripheral driver library..................................................................306

6.5 Flash memory.....................................................................................................................308

6.5.1 Basic operational components of the flash memory....................................... 310

6.5.1.1 Flash controller clocking.................................................................... 310

6.5.1.2 Flash controller address mapping.................................................... 310

6.5.1.3 Flash controller access privileges..................................................... 311

6.5.2 Operational modes of the flash memory.......................................................... 312

6.5.2.1 Flash memory read mode and features........................................... 312

6.5.2.2 Flash memory program (write) mode.............................................. 320

6.5.2.3 Flash memory erase mode.................................................................330

6.5.2.4 Flash memory Write-Erase protection.............................................333

6.5.3 Flash memory interrupt handling....................................................................335

6.5.4 Low-frequency active and low-frequency LPM0 modes support................336

6.5.5 Flash controller benchmarking features.......................................................... 337

6.5.6 Recommended settings and flow for program and erase operations.......... 339

6.6 Memory system programing methods...........................................................................340

6.6.1 Flash memory projects with DRA model.........................................................340

6.6.1.1 Flash memory reading projects with DRA model.........................340

6.6.1.2 Flash memory immediate writing projects with DRA model.........343

6.6.1.3 Flash memory burst programing projects with DRA model.......347

6.6.1.4 Flash memory erasing projects with DRA model.......................... 351

6.6.2 Use API functions in the MSPWare library to perform flash

memory programing...........................................................................................354

6.6.2.1 Flash reading-related API functions................................................355

6.6.2.2 Flash programing-related API functions........................................ 357

6.6.2.3 Flash erasing-related API functions.................................................358

6.6.2.4 Flash program-erase protection-related functions........................358

6.6.2.5 Flash interrupt processing-related API functions..........................360

6.6.3 Use API functions to build flash memory example projects

with SD model......................................................................................................360

6.6.3.1 Configuring the environments and run the project......................364

6.7 Complete memory map in the MSP432P401R MCU system........................................365

6.8 Memory requirements and memory properties...........................................................368

6.8.1 Memory requirements........................................................................................ 369

6.8.2 Memory access attributes................................................................................... 369

6.8.3 Memory endianness............................................................................................ 371

6.8.3.1 Little-endian format........................................................................... 371

6.8.3.2 Big-endian format............................................................................... 372

6.9 Chapter summary............................................................................................................. 372

Chapter 7 MSP432™ parallel I/O ports programing..........................................................391

7.1 Overview............................................................................................................................ 391

7.2 GPIO module architecture and GPIO port configuration........................................... 392

7.3 GPIO ports controlled by using the general digital I/O control................................. 394

7.4 GPIO ports controlled by using the PMC......................................................................402

7.4.1 PM control for GPIO P2......................................................................................404

7.4.2 PM control for GPIO P3......................................................................................404

7.4.3 PM control for GPIO P7......................................................................................406

7.5 On-board keypads interface programing project.........................................................408

7.5.1 Keypad interfacing programing structure...................................................... 410

7.5.2 Create the keypad interfacing programing project........................................ 413

7.5.2.1 Create the C source file DRAKeyPad.c............................................ 413

7.5.3 Set up the environment to build and run the project.................................... 417

7.6 ADC programing project................................................................................................. 417

7.6.1 ADC module in the MSP432P401R MCU system............................................ 418

7.6.2 ADC module architecture and functional block diagram............................ 418

7.6.2.1 External and internal analog input selection................................. 418

7.6.2.2 Internal and external reference voltage selection.......................... 419

7.6.2.3 ADC clock selection and clock predivision....................................420

7.6.2.4 ADC triggering source and sample-hold mode selection............420

7.6.2.5 ADC conversion mode selection.......................................................422

7.6.2.6 ADC conversion result memory-register selection........................ 424

7.6.2.7 ADC power management..................................................................425

7.6.2.8 ADC conversion interrupt-source selection and processing........425

7.6.3 ADC14 core and conversion result format.......................................................427

7.6.4 ADC14 registers...................................................................................................428

7.6.4.1 ADC14 control register 0 (ADC14CTL0)..........................................429

7.6.4.2 ADC14 control register 1 (ADC14CTL1)..........................................429

7.6.4.3 ADC14 conversion memory control registers

(ADC14MCTL0~ ADC14MCTL31).....................................................429

7.6.4.4 ADC14 conversion memory registers

(ADC14MEM0~ADC14MEM31)........................................................429

7.6.4.5 ADC14 interrupt enable registers (ADC14IER0~ADC14IER1)..........433

7.6.4.6 ADC14 interrupt flag registers (ADC14IFGR0~ADC14IFGR1).........435

7.6.4.7 ADC14 clear interrupt flag registers

(ADC14CLRIFGR0~ADC14CLRIFGR1)............................................435

7.6.4.8 ADC14 interrupt vector register (ADC14IV)...................................436

7.6.5 Analog input signal channels and GPIO pins................................................. 437

7.6.6 ADC14 module initialization............................................................................. 437

7.6.7 Build the ADC programing project..................................................................438

7.6.7.1 ADC module in EduBASE ARM® trainer........................................438

7.6.7.2 Create the ADC programing project (polling-driven)................... 439

7.6.7.3 Create the source file DRAADC14.c.................................................440

7.6.7.4 Set up the environment to build and run the project....................442

7.6.8 ADC module API functions provided in the TivaWare peripheral

driver library........................................................................................................442

7.6.8.1 Configure and set up the ADC14 module API functions.............443

7.6.8.2 Enable and disable the ADC14 module API functions.................447

7.6.8.3 Get the running status and receive the ADC14 conversion

results API functions..........................................................................448

7.6.8.4 Configure and process the ADC14 interrupts API functions...........448

7.6.8.5 Build an example ADC14 project using API functions.................450

7.7 Analog comparator project............................................................................................... 452

7.7.1 Architecture and organization of the COMP_E Module...............................453

7.7.2 Compared analog inputs selection...................................................................453

7.7.3 Reference voltages selection...............................................................................455

7.7.4 Comparator output controls............................................................................... 457

7.7.5 Comparator interrupt controls........................................................................... 459

7.7.6 Analog comparator interfacing signals and GPIO pins................................. 462

7.7.7 Initialization and configuration process for the analog comparator...........463

7.7.8 Develop an example analog comparator project.............................................464

7.7.9 Analog comparator API functions in the MSPPDL........................................466

7.7.9.1 API functions used to initialize COMP_E modules...................... 467

7.7.9.2 API functions used to set up reference voltages............................ 467

7.7.9.3 API functions used to control and manage the

COMP_E modules............................................................................... 469

7.7.9.4 API functions used to manage interrupts related

to the COMP_E modules.................................................................... 469

7.7.10 Use API functions to build a comparator project with the SD model......... 470

7.8 Chapter summary............................................................................................................. 475

Chapter 8 MSP432™ serial I/O ports programing.............................................................487

8.1 Overview............................................................................................................................ 487

8.2 Introduction to SPI mode and SPI operations...............................................................488

8.2.1 Architecture and organization of the SPI mode.............................................488

8.2.2 CKPL and CKPH (transmit–receive frame).....................................................489

8.3 Enhanced universal serial communication interfaces eUSCI_A and eUSCI_B............490

8.4 eUSCI interface used for SPI mode................................................................................. 491

8.4.1 Architecture and functional block diagram of the eUSCI used

for SPI mode......................................................................................................... 492

8.4.2 General controls and bit clock generation registers....................................... 492

8.4.3 SPI data transmit control registers.................................................................... 495

8.4.4 SPI dat

...
View More

Author(s)

Biography

Dr. Ying Bai is a professor in the Department of Computer Science and Engineering at Johnson C. Smith University in Charlotte, North Carolina. His special research interests include intelligent controls, soft computing, mixed-language programming, fuzzy logic controls, robotic controls, robots calibrations, and fuzzy multicriteria decision-making. He has had industry experience in software and senior software engineer positions at companies such as Motorola MMS, Schlumberger ATE Technology, Immix Telecom, and Lam Research.

Dr. Bai has published approximately 50 academic research papers in IEEE Trans. Journals and international conferences. He has also published 13 books with publishers such as Prentice Hall, CRC Press LLC, Springer, Cambridge University Press, and Wiley IEEE Press in recent years. The Russian translation of his first book titled Applications Interface Programming Using Multiple Languages was published by Prentice Hall in 2005. The Chinese translation of his eighth book titled Practical Database Programming with Visual C#.NET was published by Tsinghua University Press in China at the end of 2011. His books cover interfacing software programming, serial port programming, database programming, and fuzzy logic controls in industrial applications, as well as microcontroller programming and applications.

Reviews

"This textbook provides a systemic, complete introduction and discussion about MSP432 MCU components and implementations, including most popular peripherals, with over 70 projects. It supplies plenty of learning and teaching materials in each chapter with homework assignments, exercises, class projects, lab projects, and MS PPT slides, which are convenient for college students and instructors.

This is the first textbook that provides such complete and up-to-date materials on MSP432 MCU for college students and professional programmers, which provides a shortcut between what to learn in school and what fundamentals are needed in the market in the related technical fields.

In short, this is a textbook that provides the up-to-date and complete learning materials that can help students learn this kind of technical knowledge in a practical way and be better prepared for the application market fields in engineering or information technology, in which micro-computers and micro-controllers are widely used."
—Daoxi Xiu, NC Administrative Office of the Courts, USA

"Clear and concise with detailed, well thought out topics, applications, and graphics. Dr. Bai provides a very detailed explanation of the hardware and its application, which aids to a rapid understanding of the MPS432 microcontroller. The use of the MPS432P401R MCU-based EVB as a common core for the development of software and hardware applications provides a stable platform with consistent results in the classroom."
— Thomas Stout, Tidewater Community College, Virginia, USA