Pic32frm 12io
Pic32frm 12io
I/O Ports
HIGHLIGHTS
This section of the manual contains the following topics:
12
12.1 Introduction.............................................................................................................. 12-2
I/O Ports
12.2 Control Registers ..................................................................................................... 12-3
12.3 Modes of Operation ................................................................................................. 12-8
12.4 Operation in Power-Saving Modes ........................................................................ 12-17
12.5 Effects of Various Resets....................................................................................... 12-17
12.6 Related Application Notes ..................................................................................... 12-18
12.7 Revision History..................................................................................................... 12-19
Note: This family reference manual section is meant to serve as a complement to device
data sheets. Depending on the device variant, this manual section may not apply to
all PIC32 devices.
Please consult the note at the beginning of the “I/O Ports” chapter in the current
device data sheet to check whether this document supports the device you are
using.
Device data sheets and family reference manual sections are available for
download from the Microchip Worldwide Web site at: http://www.microchip.com
12.1 INTRODUCTION
The general purpose I/O pins can be considered the simplest of peripherals. These I/O pins allow
the PIC32 microcontroller to monitor and control other devices. To add flexibility and functionality
to a device, some pins are multiplexed with alternate function(s). These functions depend on
which peripheral features are on the device. In general, when a peripheral is functioning, that pin
may not be used as a general purpose I/O pin.
Following are some of the key features of the I/O Ports module:
• Individual output pin open-drain enable/disable
• Individual input pin pull-up enable/disable
• Monitor select inputs and generate interrupt on a mismatch condition
• Operate during Sleep and Idle modes
• Fast bit manipulation using CLR, SET, and INV registers (not available on all devices)
• Slew Rate Control (not available on all devices)
A block diagram of a typical I/O port structure is shown in Figure 12-1. The diagram depicts the
many peripheral functions that can be multiplexed onto the I/O pin.
Data Bus D Q
ODCx
SYSCLK CK
EN Q
WR ODCx
RD TRISx
0
I/O Cell
1
D Q
TRISx
CK
Q
EN
WR TRISx
D Q
LATx
CK I/O pin
EN Q
WR LATx
WR PORTx
RD LATx
1
Synchronization
RD PORTx 0
Q D Q D
SLEEP Q CK Q CK
SYSCLK
SRCON0x
SRCON1x
Note: Not all registers and associated bits are available on all devices. Refer to the “I/O
Ports” chapter in the specific device data sheet to determine availability.
Before reading and writing any I/O port, the desired pin or pins should be properly configured for
the application. Each I/O port has nine registers directly associated with the operation of the port
and one control register. Each I/O port pin has a corresponding bit in these registers. Throughout
this section, the letter ‘x’, denotes any or all Port module instances. For example, TRISx would
represent TRISA, TRISB, TRISC, and so on. Any bit and its associated data and control registers
that is not valid for a particular device will be disabled and will read as zeros. 12
For additional information on the registers in this section, refer to the “I/O Ports” chapter in the
specific device data sheet.
I/O Ports
12.2.1 Registers for Configuring Tri-state Functions (TRISx)
The TRISx registers configure the data direction flow through port I/O pins. The TRISx register
bits determine whether a PORTx I/O pin is an input or an output:
• If a data direction bit is ‘1’, the corresponding I/O port pin is an input
• If a data direction bit is ‘0’, the corresponding I/O port pin is an output
• A read from a TRISx register reads the last value written to that register
• All I/O port pins are defined as inputs after a Power-on Reset (POR)
7:0
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0 12
— — — — — — — —
Legend:
I/O Ports
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Note: Values in this register can only be changed if the IOLOCK Configuration bit (CFGCON<13>) = 0.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Note: Values in this register can only be changed if the IOLOCK Configuration bit (CFGCON<13>) = 1.
Every I/O module register has a corresponding SET, CLR, and INV register, which provide atomic
bit manipulations. As the name of the register implies, a value written to a SET, CLR, or INV
register effectively performs the implied operation, but only on the corresponding base register
and only bits specified as ‘1’ are modified. Bits specified as ‘0’ are not modified.
• Writing 0x0001 to TRISASET register sets only bit 0 in the base register TRISA
• Writing 0x0020 to PORTDCLR register clears only bit 5 in the base register PORTD
12
• Writing 0x9000 to LATCINV register inverts only bits 15 and 12 in the base register LATC
Reading SET, CLR, and INV registers returns an undefined value. To see the affects of a write
I/O Ports
operation to a SET, CLR, or INV register, the base register must be read instead.
A typical method to toggle an I/O pin requires a read-modify-write operation performed on a
PORTx register in software. For example, a read from a PORTx register, mask and modify the
desired output bit or bits, and write the resulting value back to the PORTx register. This method
is vulnerable to a read-modify-write issue where the port value may change after it is read and
before the modified data can be written back, thus changing the previous state. This method also
requires more instructions.
PORTA ^ = 0x0001;
A more efficient and atomic method uses the PORTxINV register. A write to the PORTxINV
register effectively performs a read-modify-write operation on the target base register, equivalent
to the software operation described previously; however, it is done in hardware. To toggle an I/O
pin using this method, a ‘1’ is written to the corresponding bit in the PORTxINV register. This
operation will read the PORTx register, invert only those bits specified as ‘1’, and write the
resulting value to the LATx register, thus toggling the corresponding I/O pins all in a single atomic
instruction cycle.
PORTAINV = 0x0001;
Each I/O pin can be configured for various types of slew rate control on its associated port. This
is controlled by the Slew Rate Control bits in the SRCON1x and SRCON0x registers that are
associated with each I/O port. The slew rate control is configured using the corresponding bit in
each register, as shown in Table 12-1.
As an example, writing 0x0001, 0x0000 to SRCON1A and SRCON0A, respectively, will enable
slew rate control on the RA0 pin and sets the slew rate to the slow edge rate.
For example, Figure 12-2 illustrates the remappable pin selection for the U1RX input.
12
Figure 12-2: Remappable Input Example for U1RX
I/O Ports
U1RXR<3:0>
0
RPA2
1
RPB6
2 U1RX input
RPA4 to peripheral
n
RPn
Note: For input only, PPS functionality does not have priority over TRISx settings. Therefore,
when configuring RPn pin for input, the corresponding bit in the TRISx register must also
be configured for input (set to ‘1’).
•
SDI2 SDI2R SDI2R<3:0>
•
I/O Ports
Default
0
U1TX Output
1
U1RTS Output 2
RPA0
Output Data
14
15
I/O Ports
Peripheral Module Enable
Peripheral Output Enable
Peripheral Output Data
PI/O Module
RD ODCx
Data Bus D Q
SYSCLK ODCx
CK
Q
EN
WR ODCx
1 I/O Cell
RD TRISx 0
0
1
D Q
TRISx 1
CK
Q 0
EN
WR TRISx
Output Multiplexers
D Q
LATx I/O pin
CK
Q
EN
WR LATx
WR PORTx
RD LATx
RD PORTx 0
Q D Q D
SLEEP Q CK Q CK
SYSCLK
Synchronization
Peripheral Input R(2)
Note 1: This block diagram is a general representation of a shared port/peripheral structure and is provided for illustration
purposes only. The actual structure for any specific port/peripheral combination may be different than what is
depicted in this diagram.
2: R = Peripheral input buffer types may vary. Refer to the specific device data sheet for peripheral details.
In general, the following peripherals allow their input pins to be controlled manually through the
LATx registers:
• External Interrupts pins
• Input Capture pins
• Timer Clock input pins
• PWM Fault pins
Most serial communication peripherals, when enabled, take full control of the I/O pin so that the
input pins associated with the peripheral cannot be affected through the corresponding PORTx
registers. These peripherals include the following modules:
• SPI 12
• I2 C
• UART
I/O Ports
12.3.3 Change Notice (CN) Pins
The CN pins provide PIC32 devices the ability to generate interrupt requests to the processor in
response to a change of state on selected input pins (corresponding TRISx bits must be = 1).
The total number of available CN inputs is dependent on the selected PIC32 device. Refer to the
“I/O Ports” chapter in the specific device data sheet for further details.
The enabled pin values are compared with the values sampled during the last read operation of
the designated PORTx register. If the pin value is different from the last value read, a mismatch
condition is generated. The mismatch condition can occur on any of the enabled input pins. The
mismatches are “ORed” together to provide a single interrupt-on-change signal. The enabled
pins are sampled on every internal system clock cycle, SYSCLK.
Output Multiplexers
Open-Drain Selection
Peripheral Module Enable I/O
Peripheral Output Enable 0 Output BSC Output
1
Output LATx Data 1 Enable Boundary Enable
0
Scan Cell
Peripheral Output Enable (BSC)
1 Output Data BSC Output
0 TRISx Data
BSC Input
Data
I/O pin
BSC Enable
Input Data
I/O Ports
(CNCONx<13>) selects whether the module will stop or continue functioning in Idle mode.
• If SIDL = 1, the module will continue to sample Input CN I/O pins in Idle mode; however,
synchronization is disabled
• If SIDL = 0, the module will continue to synchronize and sample Input CN I/O pins in Idle
mode
Note: Please visit the Microchip web site (http://www.microchip.com) for additional
application notes and code examples for the PIC32 family of devices.
I/O Ports
bit (CNCONx Register).
Revision E (July 2011)
This revision includes the following changes:
• Added a note at the beginning of the section, which provides information on
complementary documentation
• Changed all occurrences of PIC32MX to PIC32
• Removed the paragraph about the I/O related SFRs in 12.1 “Introduction”
• Added 12.2.7 “Registers for Peripheral Pin Select”
• Removed all Interrupt registers
• Removed TRISx, PORTx, LATx, ODCx, CNEN, CNPUE registers and their associated
SET, INV, and CLR registers
• Removed the FRZ bit from the Change Notice Control register (see Register 12-1)
• Removed related Interrupts section and sub-sections
• Removed the operation of the I/O port in Debug mode from 12.4 “Operation in
Power-Saving Modes”
• Removed I/O Port Application, I/O Pin Control and Design Tips sections
• Removed 12.2.6 CN Control Registers section
• Renamed the section 12.2.5 ODCx Registers as 12.2.4 “Registers for Open-Drain Con-
figuration (ODCx)”
• Added section 12.2.5 “Registers for Configuring Analog and Digital Port Pins
(ANSELx)”
• Added section 12.2.6 “Registers for Input Change Notification”
• Added section 12.3.1 “Peripheral Pin Select (PPS)”
• In 12.3 “Modes of Operation”, removed sections on Digital Inputs, Analog Inputs, Digital
Outputs, Analog Outputs, Open-Drain Configuration and Port Descriptions
• Updated the note in the second point of 12.3.3.1 “CN Configuration and Operation”
• Modifications to register formatting and minor updates have been made throughout the
document
Revision F (January 2015)
This revision includes the following updates:
• Added 12.2.9 “Registers for Slew Rate Control”
• 12.3.3.1 “CN Configuration and Operation” was updated
• Minor updates to text and formatting were incorporated throughout the document
NOTES:
• 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.
QUALITY MANAGEMENT SYSTEM Microchip received ISO/TS-16949:2009 certification for its worldwide
headquarters, design and wafer fabrication facilities in Chandler and
CERTIFIED BY DNV Tempe, Arizona; Gresham, Oregon and design centers in California
and India. The Company’s quality system processes and procedures
are for its PIC® MCUs and dsPIC® DSCs, KEELOQ® code hopping
== ISO/TS 16949 == 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.
01/27/15