Microchip Technology PIC32 User’s Guide

Getting Started with PIC32
User’s Guide
© 2008 Microchip Technology Inc. DS61146B
Note the following details of the code protection feature on Microchip devices:
Microchip products meet the specification contained in their particular Microchip Data Sheet.
Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the intended manner and under normal conditions.
There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
Microchip is willing to work with the customer who is concerned about the integrity of their code.
Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer’s risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron, dsPIC, K
EELOQ, KEELOQ logo, MPLAB, PIC, PICmicro,
PICSTART, PRO MATE, rfPIC and SmartShunt are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.
FilterLab, Linear Active Thermistor, MXDEV, MXLAB, SEEVAL, SmartSensor and The Embedded Control Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, CodeGuard, dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN, ECONOMONITOR, FanSense, In-Circuit Serial Programming, ICSP, ICEPIC, Mindi, MiWi, MPASM, MPLAB Certified logo, MPLIB, MPLINK, mTouch, PICkit, PICDEM, PICDEM.net, PICtail, PIC
32
logo, PowerCal, PowerInfo, PowerMate, PowerTool, REAL ICE, rfLAB, Select Mode, Total Endurance, UNI/O, WiperLock and ZENA are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated in the U.S.A.
All other trademarks mentioned herein are property of their respective companies.
© 2008, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved.
Printed on recycled paper.
Microchip received ISO/TS-16949:2002 certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona; Gresham, Oregon and design centers in California and India. The Company’s quality system processes and procedures are for its PIC devices, Serial EEPROMs, microperipherals, nonvolatile memory and analog products. In addition, Microchip’s quality system for the design and manufacture of development systems is ISO 9001:2000 certified.
®
MCUs and dsPIC® DSCs, KEELOQ
®
code hopping
DS61146B-page ii © 2008 Microchip Technology Inc.
GETTING STARTED WITH PIC32
Table of Contents
Preface ........................................................................................................................... 1
Chapter 1. PIC32 Features
1.1 Introduction ..................................................................................................... 7
1.2 Highlights ........................................................................................................ 7
Chapter 2. PIC32 Product Family
2.1 Introduction ..................................................................................................... 9
Chapter 3. PIC32 Architecture
3.1 Introduction ................................................................................................... 11
Chapter 4. PIC32 Tools
4.1 Introduction ................................................................................................... 15
4.2 Highlights ...................................................................................................... 15
4.3 MPLAB
4.4 MPLAB
4.5 Peripheral Libraries ...................................................................................... 17
4.6 Software Solutions ....................................................................................... 19
4.7 Demonstration, Development and Evaluation Boards .................................. 20
4.8 Technical Documentation ............................................................................. 20
®
IDE ................................................................................................ 15
®
C32 C Compiler ............................................................................. 16
Chapter 5. Step-by-Step Procedures to Setup, Build, and Run a Demo Project
5.1 Introduction ................................................................................................... 21
5.2 Highlights ...................................................................................................... 21
5.3 MPLAB IDE Setup ........................................................................................ 21
5.4 Step-by-step Guide Overview ...................................................................... 22
5.5 Selecting the Device ..................................................................................... 23
5.6 Creating the Project ...................................................................................... 24
5.7 Setting Up Language Tools .......................................................................... 25
5.8 Naming the Project ....................................................................................... 26
5.9 Adding Files to the Project ........................................................................... 27
5.10 Attaching the Debugger .............................................................................. 31
5.11 Building the Project .................................................................................... 32
5.12 Testing the Code ........................................................................................ 32
Chapter 6. Technical Support Resources
6.1 Introduction ................................................................................................... 37
Index ............................................................................................................................. 39
Worldwide Sales and Service .................................................................................... 40
© 2008 Microchip Technology Inc. DS61146B-page iii
Getting Started with PIC32
NOTES:
DS61146B-page iv © 2008 Microchip Technology Inc.
GETTING STARTED WITH PIC32
Preface
NOTICE TO CUSTOMERS
All documentation becomes dated, and this manual is no exception. Microchip tools and documentation are constantly evolving to meet customer needs, so some actual dialogs and/or tool descriptions may differ from those in this document. Please refer to our web site (www.microchip.com) to obtain the latest documentation available.
Documents are identified with a “DS” number. This number is located on the bottom of each page, in front of the page number. The numbering convention for the DS number is “DSXXXXXA”, where “XXXXX” is the document number and “A” is the revision level of the document.
For the most up-to-date information on development tools, see the MPLAB Select the Help menu, and then Topics to open a list of available online help files.
INTRODUCTION
This document is intended to enable new PIC32 users to get a basic hardware and soft­ware understanding of the PIC32 architecture and quickly get started with software development for PIC32 products.
This document is primarily written for anyone wanting to get overview knowledge of PIC32 microcontrollers and associated technical collateral provided by Microchip and its third party tools partners. A basic understanding of embedded systems development and 'C' programming knowledge is required, if you are planning to follow step-by-step instructions provided later in this document.
This chapter contains general information that will be useful to know before using the PIC32. Items discussed in this chapter include:
• Document Layout
• Conventions Used in this Guide
• Recommended Reading
• The Microchip Web Site
• Development Systems Customer Change Notification Service
• Customer Support
• Document Revision History
®
IDE online help.
© 2008 Microchip Technology Inc. DS61146B-page 1
Getting Started with PIC32
DOCUMENT LAYOUT
This document is divided into 6 sections. Sections 1 through 4 provide an overview of PIC32 products. Section 5 provides an overview of PIC32 development tools. Section 6 describes the procedure to setup a development environment and debug a sample application. The manual layout is as follows:
Chapter 1. PIC32 Features
Chapter 2. PIC32 Product Family
Chapter 3. PIC32 Architecture
Chapter 4. PIC32 Tools
Chapter 5. Step-by-Step Procedures to Setup, Build, and Run a Demo Project
Chapter 6. Technical Support Resources
DS61146B-page 2 © 2008 Microchip Technology Inc.
CONVENTIONS USED IN THIS GUIDE
This manual uses the following documentation conventions:
DOCUMENTATION CONVENTIONS
Description Represents Examples
Arial font:
Italic characters Referenced books MPLAB
Initial caps A window the Output window
Quotes A field name in a window or
Underlined, italic text with right angle bracket
Bold characters A dialog button Click OK
N‘Rnnnn A number in verilog format,
Text in angle brackets < > A key on the keyboard Press <Enter>, <F1>
Courier New font:
Plain Courier New Sample source code #define START
Italic Courier New A variable argument file.o, where file can be
Square brackets [ ] Optional arguments mcc18 [options] file
Curly brackets and pipe character: { | }
Ellipses... Replaces repeated text var_name [,
Preface
®
IDE User’s Guide
Emphasized text ...is the only compiler...
A dialog the Settings dialog A menu selection select Enable Programmer
“Save project before build”
dialog A menu path File>Save
A tab Click the Power tab
4‘b0010, 2‘hF1 where N is the total number of digits, R is the radix and n is a digit.
Filenames autoexec.bat File paths c:\mcc18\h Keywords _asm, _endasm, static Command-line options -Opa+, -Opa- Bit values 0, 1 Constants 0xFF, ‘A’
any valid filename
[options]
Choice of mutually exclusive arguments; an OR selection
Represents code supplied by user
errorlevel {0|1}
var_name...]
void main (void)
{ ...
}
© 2008 Microchip Technology Inc. DS61146B-page 3
Getting Started with PIC32
RECOMMENDED READING
This user's guide describes how to use PIC32. Other useful documents are listed below. The following Microchip documents are available and recommended as supple­mental reference resources.
Readme for the PIC32MX
For the latest information on using PIC32 microcontrollers, read the file (an ASCII text file) at the root level of the CD included in the PIC32 Starter Kit. The file generally con­tains the most current update information, as well as any issues that may not have been available when this document was published.
Readme Files
For the latest information on using other tools, read the tool-specific readme files in the Readmes subdirectory of the PIC32MX Starter Kit installation directory. The files con­tain update information, as well as any issues that may not have been available when this document was published.
THE MICROCHIP WEB SITE
Microchip provides online support via our web site at www.microchip.com. This web site is used as a means to make files and information easily available to customers. Accessible by using your favorite Internet browser, the web site contains the following information:
Product Support – Data sheets and errata, application notes and sample
programs, design resources, user’s guides and hardware support documents, latest software releases and archived software
General Technical Support – Frequently Asked Questions (FAQs), technical
support requests, online discussion groups, Microchip consultant program member listing
Business of Microchip – Product selector and ordering guides, latest Microchip
press releases, listing of seminars and events, listings of Microchip sales offices, distributors and factory representatives
DS61146B-page 4 © 2008 Microchip Technology Inc.
Preface
DEVELOPMENT SYSTEMS CUSTOMER CHANGE NOTIFICATION SERVICE
Microchip’s customer notification service helps keep customers current on Microchip products. Subscribers will receive e-mail notification whenever there are changes, updates, revisions or errata related to a specified product family or development tool of interest.
To register, access the Microchip web site at www.microchip.com, click on Customer Change Notification and follow the registration instructions.
The Development Systems product group categories are:
Compilers – The latest information on Microchip C compilers and other language
tools. These include the MPLAB C18 and MPLAB C32 C compilers; and MPLAB LIB30 object librarians.
Emulators – The latest information on Microchip in-circuit emulators.This
includes the MPLAB ICE 2000 and MPLAB ICE 4000.
In-Circuit Debuggers – The latest information on the Microchip in-circuit
debugger, MPLAB ICD 2.
MPLAB
Integrated Development Environment for development systems tools. This list is focused on the MPLAB IDE, MPLAB SIM simulator, MPLAB IDE Project Manager and general editing and debugging features.
Programmers – The latest information on Microchip programmers. These include
the MPLAB PM3 and PRO MATE Plus, PICkit
®
IDE – The latest information on Microchip MPLAB IDE, the Windows®
®
®
1 and PICkit® 2 development programmers.
II device programmers and the PICSTART®
CUSTOMER SUPPORT
Users of Microchip products can receive assistance through several channels:
• Distributor or Representative
• Local Sales Office
• Field Application Engineer (FAE)
• Technical Support
• Development Systems Information Line
Customers should contact their distributor, representative or field application engineer (FAE) for support. Local sales offices are also available to help customers. A listing of sales offices and locations is included in the back of this document.
Technical support is available through the web site at: http://support.microchip.com
DOCUMENT REVISION HISTORY
Revision A (October 2007)
• Initial Release of this Document.
Revision B (March 2008)
• Updates
© 2008 Microchip Technology Inc. DS61146B-page 5
Getting Started with PIC32
NOTES:
DS61146B-page 6 © 2008 Microchip Technology Inc.

1.1 INTRODUCTION

The PIC32 is a 32-bit family of general purpose microcontrollers from Microchip Technology. It offers 80+ DMIPS performance with a wide variety of on-chip periph­erals. It employs industry leading M4K MIPS32 core from MIPS Technologies, Inc. All members in the PIC32 family use programming interface similar to other Micro­chip PIC patible with the PIC24FJ128GA family of 16-bit microcontrollers.

1.2 HIGHLIGHTS

The PIC32 family offers a number of features to enable a wide variety of applications. The following subsections list all the key features grouped in major categories.
Performance:
• Up to 80 MHz, MIPS M4K 32-bit core with 5 stage pipeline
• High-performance hardware multiply/divide unit – 1 multiply per clock
• Programmable user and kernel memory partition for enhanced application stability
• Multiple register sets for reduced interrupt latency
• Hardware assisted single-cycle register bits manipulations
• 128-bit wide Flash memory to shorten individual instruction fetch time
• 256 bytes of high-speed cache memory with instruction and ROM data prefetch buffer
• Available DMA controller with integrated CRC calculation and pattern-based transfer termination
• Includes USB On-The-Go controller for USB device, host, or dual-role applications
• USB controller has own dedicated DMA interface
GETTING STARTED WITH PIC32

Chapter 1. PIC32 Features

®
microcontrollers. In addition, PIC32 microcontrollers are pin-to-pin com-
Power Management:
• 2.3 to 3.6V operation
• Full-speed operation over entire voltage range
• Various low-power modes including RUN, IDLE and SLEEP
• I/O transfers via DMA in IDLE mode
• Programmable peripheral clock
• Individual peripheral ON/OFF control and operation during IDLE mode
• Multiple clock sources
Scalability:
• Industry known MIPS32-compatible M4K CPU core with 5 stage pipeline
• Large family of devices with Flash memory options from 32 KB to 512 KB
• Pin compatible with 64/100 pin PIC24FJXXXGA family of 16-bit microcontrollers
© 2008 Microchip Technology Inc. DS61146B-page 7
Getting Started with PIC32
Ease of Use:
•PIC® microcontroller “look and feel” peripherals
• Standard MPLAB REAL ICE™, and MPLAB ICD 2.
• Software Peripheral Libraries compatible with those for Microchip 16-bit microcontrollers
• Microchip developed middleware modules such as TCP/IP and 16-bit file system
®
tool-suite – MPLAB IDE, MPLAB C32 C Compiler, MPLAB
DS61146B-page 8 © 2008 Microchip Technology Inc.

Chapter 2. PIC32 Product Family

2.1 INTRODUCTION

The PIC32 family includes scalable devices ranging from 32KB to 512KB of Flash memory. Also a rich set of peripherals – Five timers, 16 channels of 10-bit A/D Converters and communication interfaces: SPI, I
Please consult the “PIC32MX Family Data Sheet” (DS61143) for a complete list of family variants, core and peripheral characteristics.

FIGURE 2-1: PIC32 MCU MODULES

GETTING STARTED WITH PIC32
2
C™ and UART.
VREG
VREG
RTCC
RTCC
USB
USB
OTG
OTG
SPI
SPI
(2)
(2)
W
44--W
JTAG
JTAG
Debug
Debug
I2C
I2C
(2)
(2)
Boundary
Boundary
Scan
Scan
Vectored
Vectored
Interrupts
Interrupts
CPU
CPU
Bus
Bus
Matrix
Matrix
EUART
EUART
(2)
(2)
W
22--W
(5)
(5)
IC
IC
WDT,
WDT,
BOR.
BOR.
CVRef
CVRef
DMAC
DMAC
+
+
CRC
CRC
Ext
Ext
OCOMP
OCOMP
/PWM
/PWM
(5)
(5)
W
55--W
Trace
Trace
C
C
a
a
c
c
h
h
e
e
TMR
TMR
(5)
(5)
RAM
RAM
128--
128
Flash
Flash
bit
bit
MCHP
MCHP
Debug
Debug
INTs
INTs
(5)
(5)
Change
Change
Notice
Notice
(21)
(21)
OD
OD
/GPIO
/GPIO
(85)
(85)
ADC
ADC
(16ch,
(16ch,
10b)
10b)
Enh..
Enh
PMP
PMP
Analog
Analog
Comp.
Comp.
(2)
(2)
© 2008 Microchip Technology Inc. DS61146B-page 9
Getting Started with PIC32
NOTES:
DS61146B-page 10 © 2008 Microchip Technology Inc.
Loading...
+ 30 hidden pages