Microchip PIC24HJ32GP204 Bedienungsanleitung


Lesen Sie kostenlos die 📖 deutsche Bedienungsanleitung für Microchip PIC24HJ32GP204 (74 Seiten) in der Kategorie Nicht kategorisiert. Dieser Bedienungsanleitung war für 17 Personen hilfreich und wurde von 2 Benutzern mit durchschnittlich 4.5 Sternen bewertet

Seite 1/74
 2007-2015 Microchip Technology Inc. DS70000195G-page 1
HIGHLIGHTS
This section of the manual contains the following major topics:
1.0 Introduction ....................................................................................................................... 2
2.0 I
2
C Bus Characteristics..................................................................................................... 4
3.0 Control and Status Registers ............................................................................................ 8
4.0 Enabling I
2
C Operation ................................................................................................... 18
5.0 Communicating as a Master in a Single Master Environment ........................................ 20
6.0 Communicating as a Master in a Multi-Master Environment .......................................... 34
7.0 Communicating as a Slave ............................................................................................. 37
8.0 Connection Considerations for I
2
C Bus .......................................................................... 61
9.0 Operation in Power-Saving Modes ................................................................................. 63
10.0 Peripheral Module Disable (PMDx) Registers ................................................................ 63
11.0 Effects of a Reset............................................................................................................ 63
12.0 Constant-Current Source ................................................................................................ 64
13.0 Register Maps................................................................................................................. 66
14.0 Design Tips ..................................................................................................................... 67
15.0 Related Application Notes............................................................................................... 68
16.0 Revision History .............................................................................................................. 69
Inter-Integrated Circuit (I2C)
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 2  2007-2015 Microchip Technology Inc.
This document supersedes the following PIC24 and dsPIC
ÂŽ
DSC Family Reference Manual sections:
1.0 INTRODUCTION
The Inter-Integrated Circuit (I
2
C) module is a serial interface useful for communicating with other
peripheral or microcontroller (MCU) devices. The external peripheral devices may be serial
EEPROMs, display drivers, Analog-to-Digital Converters (ADC) and so on.
The I
2
C module can operate as any one of the following in the I
2
C system:
• Slave device
• Master device in a single master system (slave may be active)
• Master or slave device in a multi-master system (bus collision detection and arbitration are
available)
The I
2
C module contains an independent I
2
C master logic and a I
2
C slave logic, which generates
interrupts based on their events. In the multi-master systems, the user software is simply
partitioned into the master controller and the slave controller.
When the I
2
C master logic is active, the slave logic also remains active, detecting the state of the
bus and potentially receiving messages from itself in a single master system or from the other
masters in a multi-master system. No messages are lost during the multi-master bus arbitration.
In a multi-master system, the bus collision conflicts with the other masters in the system when
detected, and the module provides a method to terminate and then restart the message.
The I
2
C module contains a Baud Rate Generator (BRG). The I
2
C BRG does not consume other
timer resources in the device. Figure 1-1 illustrates the I
2
C module block diagram.
Key features of the I
2
C module include the following:
• Independent master and slave logic
• Multi-master support which prevents message losses in arbitration
• Detects 7-bit and 10-bit device addresses with configurable address masking in Slave mode
• Detects general call addresses as defined in the I
2
C protocol
• Bus Repeater mode, allowing the module to accept all messages as a slave, irrespective of
the address
• Automatic SCLx clock stretching provides delays for the processor to respond to a slave
data request
• Supports 100 kHz and 400 kHz bus specifications
• Supports the Intelligent Platform Management Interface (IPMI) standard
• Supports SDAx hold time for SMBus (300 nS or 150 nS) in Slave mode
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 PIC24 and dsPIC33 devices.
Please consult the note at the beginning of the “Inter-Integrated Circuit (I
2
C)”
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
DS Number Section Number Title
DS70195 19 dsPIC33F/PIC24H Family Reference Manual
DS70330 19 dsPIC33E/PIC24E Family Reference Manual
DS39702 24 PIC24F Family Reference Manual
DS70235 19 PIC24H Family Reference Manual
DS70068 21 dsPIC30F Family Reference Manual
Note:
For more information, refer to the SDAHT bit description in the specific device data sheet.
 2007-2015 Microchip Technology Inc. DS70000195G-page 3
Inter-Integrated Circuit (I
2
C)
Figure 1-1: I
2
C Block Diagram
I2CxRCV
Internal
Data Bus
SCLx
SDAx
Shift
Match Detect
Clock
Address Match
Clock
Stretching
I2CxTRN
LSB
Shift Clock
BRG
Reload
Control
T
CY
or T
CY
/2
(1)
Acknowledge
Generation
I2CxCONH
I2CxSTAT
Control Logic
Read
LSB
Write
Read
I2CxBRG
I2CxRSR
Write
Read
Write
Read
Write
Read
Write
Read
Write
Read
Down Counter
I2CxCONL
Write
Read
Note 1: Refer to the specific device data sheet for the clock rate.
I2CxADD
Start and Stop
Bit Detect
Start and Stop
Bit Generation
Collision
Detect
I2CxMSK
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 4  2007-2015 Microchip Technology Inc.
2.0 I2C BUS CHARACTERISTICS
The I
2
C bus is a 2-wire serial interface. Figure 2-1 illustrates the schematic of an I
2
C connection
between a dsPIC33/PIC24 device and a 24LC256 I
2
C serial EEPROM, which is a typical
example for any I
2
C interface.
The I
2
C interface uses a comprehensive protocol to ensure reliable transmission and reception
of the data. When communicating, one device acts as the “master” and it initiates transfer on the
bus, and generates the clock signals to permit that transfer, while the other devices act as the
“slave” responding to the transfer. The clock line, SCLx, is output from the master and input to
the slave, although occasionally the slave drives the SCLx line. The data line, SDAx, may be
output and input from both the master and slave.
Because the SDAx and SCLx lines are bidirectional, the output stages of the devices driving the
SDAx and SCLx lines must have an open-drain in order to perform the wired-AND function of the bus.
External pull-up resistors are used to ensure a high level when no device is pulling the line down.
In the I
2
C interface protocol, each device has an address. When a master needs to initiate a data
transfer, it first transmits the address of the device that it wants to “communicate”. All of the
devices “listen” to see if this is their address. Within this address, bit 0 specifies whether the
master wants to read from or write to the slave device. The master and slave are always in
opposite modes (Transmitter or Receiver) of operation during a data transfer. That is, they
operate in either of the following two relationships:
• Master-Transmitter and Slave-Receiver
• Slave-Transmitter and Master-Receiver
In both cases, the master originates the SCLx clock signal.
Figure 2-1: Typical I
2
C Interconnection Block Diagram
Note:
SCLx and SDAx must be configured as digital.
SCLx
SDAx
dsPIC33/PIC24
SDA
SCL
V
DD
V
DD
2.2 k24LC256
(typical)
 2007-2015 Microchip Technology Inc. DS70000195G-page 5
Inter-Integrated Circuit (I
2
C)
2.1 Bus Protocol
The following I
2
C bus protocol has been defined:
• The data transfer may be initiated only when the bus is not busy.
• During the data transfer, the data line must remain stable whenever the SCLx clock line is
high. Any changes in the data line, while the SCLx clock line is high, will be interpreted as a
Start or Stop condition.
Accordingly, the bus conditions are defined as illustrated in Figure 2-2.
Figure 2-2: I
2
C Bus Protocol States
2.1.1 START DATA TRANSFER (S)
After a bus Idle state, a high-to-low transition of the SDAx line while the clock (SCLx) is high
determines a Start condition. All data transfers must be preceded by a Start condition.
2.1.2 STOP DATA TRANSFER (P)
A low-to-high transition of the SDAx line while the clock (SCLx) is high determines a Stop
condition. All data transfers must end with a Stop condition.
2.1.3 REPEATED START (R)
After a Wait state, a high-to-low transition of the SDAx line while the clock (SCLx) is high
determines a Repeated Start condition. Repeated Starts allow a master to change bus direction
or address a slave device without relinquishing control of the bus.
2.1.4 DATA VALID (D)
After a Start condition, the state of the SDAx line represents valid data when the SDAx line is
stable for the duration of the high period of the clock signal. There is one bit of data per SCLx
clock.
2.1.5 ACKNOWLEDGE (A) OR NOT ACKNOWLEDGE (N)
All data byte transmissions must be Acknowledged (ACK) or Not Acknowledged (NACK) by the
receiver. The receiver will pull the SDAx line low for an ACK or release the SDAx line for a NACK.
The Acknowledge is a 1-bit period using one SCLx clock.
2.1.6 WAIT/DATA INVALID (Q)
The data on the line must be changed during the low period of the clock signal. The devices may
also stretch the clock low time by asserting a low on the SCLx line, causing a Wait on the bus.
2.1.7 BUS IDLE (I)
Both data and clock lines remain high after a Stop condition and before a Start condition.
Address
Valid
Data
Allowed
to Change
Stop
Condition
Start
Condition
SCLx
SDAx
(I) (S) (D) (A) or (N) (P) (I)
Data or
(Q)
ACK/NACK
Valid
NACK
ACK
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 6  2007-2015 Microchip Technology Inc.
2.2 Message Protocol
A typical I
2
C message is illustrated in Figure 2-3. In this example, the message will read a
specified byte from a 24LC256 I
2
C serial EEPROM. The dsPIC33/PIC24 device will act as the
master and the 24LC256 device will act as the slave.
Figure 2-3 illustrates the data as driven by the master device and the slave device, taking into
account that the combined SDAx line is a wired-AND of the master and slave data. The master
device controls and sequences the protocol. The slave device will only drive the bus at
specifically determined times.
Figure 2-3: A Typical I
2
C Message: Read of Serial EEPROM (Random Address Mode)
2.2.1 START MESSAGE
Each message is initiated with a Start condition and terminated with a Stop condition. The
number of data bytes transferred between the Start and Stop conditions is determined by the
master device. As defined by the system protocol, the bytes of the message may have special
meaning, such as the device address byte or the data byte.
2.2.2 ADDRESS SLAVE
In Figure 2-3, the first byte is the device address byte, which must be the first part of any I
2
C
message. It contains a device address and a R/W status bit. Note that R/W = 0 for this first
address byte, indicating that the master will be a transmitter and the slave will be a receiver.
2.2.3 SLAVE ACKNOWLEDGE
The receiving device is obliged to generate an Acknowledge signal, ACK, after the reception of
each byte. The master device must generate an extra SCLx clock, which is associated with this
Acknowledge bit.
2.2.4 MASTER TRANSMIT
The next two bytes, sent by the master to the slave, are data bytes that contain the location of
the requested EEPROM data byte. The slave must Acknowledge each of the data bytes.
2.2.5 REPEATED START
The slave EEPROM has the required address information that is required to return the requested
data byte to the master. However, the R/W status bit from the first device address byte specifies
the master transmission and the slave reception. The direction of the bus must be reversed for
the slave to send data to the master.
To perform this function without ending the message, the master sends a Repeated Start. The
Repeated Start is followed with a device address byte containing the same device address as
before, and with R/W = 1, to indicate the slave transmission and the master reception.
X
Bus
Master
SDAx
Start
Address
Byte
EEPROM Address
High Byte
EEPROM Address
Low Byte Address
Byte Data
Byte
S1 0 1 0 AAA0
210 R1 0 1 0 AAA1
210 P
Slave
SDAx
Activity
N
AAAA
Output
Output
Idle
R/W
ACK
ACK
ACK
Restart
ACK
NACK
Stop
Idle
R/W
 2007-2015 Microchip Technology Inc. DS70000195G-page 7
Inter-Integrated Circuit (I
2
C)
2.2.6 SLAVE REPLY
The slave transmits the data byte by driving the SDAx line, while the master continues to
originate clocks but releases its SDAx drive.
2.2.7 MASTER ACKNOWLEDGE
During reads, a master must terminate data requests to the slave by generating a NACK on the
last byte of the message.
2.2.8 STOP MESSAGE
The master sends a Stop signal to terminate the message and returns the bus to an Idle state.
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 8  2007-2015 Microchip Technology Inc.
3.0 CONTROL AND STATUS REGISTERS
The I
2
C module has registers for operation that are accessible by the user application. All
registers are accessible in either Byte or Word mode. The registers are as follows:
•
I2CxCON: I2Cx Control Register
or
I2CxCONL: I2Cx Control Register Low
and
I2CxCONH: I2Cx Control Register High
These registers allow control of the module’s operation.
•
I2CxSTAT: I2Cx Status Register
This register contains status flags indicating the module’s state during operation.
•
I2CxMSK: I2Cx Slave Mode Address Mask Register
This register designates which bit positions in the I2CxADD register can be ignored, which
allows for multiple address support.
•
ISRCCON: I2Cx Current Source Control Register
(1)
This register allows control of the current source module.
•
I2CxRCV: I2Cx Receive Buffer Register
This is the buffer register from which data bytes can be read. The I2CxRCV register is a
read-only register.
•
I2CxTRN: I2Cx Transmit Register
This is the transmit register. The bytes are written to this register during a transmit operation.
The I2CxTRN register is a read/write register.
• I2CxADD: I2Cx Address Register
This register holds the slave device address.
• I2CxBRG: I2Cx Baud Rate Generator Reload Register
This register holds the BRG reload value for the I
2
C module BRG.
The transmit data is written to the I2CxTRN register. This register is used when the module
operates as a master transmitting data to the slave or when it operates as a slave sending reply
data to the master. As the message progresses, the I2CxTRN register shifts out the individual
bits. Therefore, the I2CxTRN register cannot be written to unless the bus is Idle.
The data being received by either the master or the slave is shifted into a non-accessible shift
register, I2CxRSR. When a complete byte is received, the byte transfers to the I2CxRCV register.
In receive operations, the I2CxRSR and I2CxRCV registers create a double-buffered receiver.
This allows reception of the next byte to begin before reading the current byte of the received
data.
If the module receives another complete byte before the user software reads the previous byte
from the I2CxRCV register, a receiver overflow occurs and sets the I2COV bit (I2CxSTAT<6>).
The byte in the I2CxRSR register is lost if BOEN = 0. Further reception and clock stretching are
disabled until the I
2
C module sees a Start/Repeated, Start/Stop condition on the bus. If the
I2COV flag has been cleared, the reception can proceed normally. If the I2COV flag is not
cleared, the module will receive the next byte correctly, but will send a NACK. It will then be
unable to receive further bytes or stretch the clock until it detects a Start/Repeated and Start/Stop
condition.
The I2CxADD register holds the slave device address. In 10-Bit Addressing mode, all bits are
relevant. In 7-Bit Addressing mode, only the I2CxADD<6:0> bits are relevant. The
I2CxADD<6:0> bits correspond to the upper 7 bits in the address byte. The Read/Write bit (R/W)
is not included in the value in this register. The A10M bit (I2CxCON<10> or I2CxCONL<10>)
specifies the expected mode of the slave address. By using the I2CxMSK register with the
I2CxADD register in Slave Addressing mode, one or more bit positions can be removed from the
exact address matching, allowing the module, in Slave mode, to respond to multiple addresses.
Note 1:
The I2CxCONL, I2CxCONH and ISRCCON registers are not available on all
devices. Refer to the specific device data sheet for availability.
 2007-2015 Microchip Technology Inc. DS70000195G-page 9
Inter-Integrated Circuit (I
2
C)
Register 3-1: I2CxCON: I2Cx Control Register
R/W-0 U-0 R/W-0 R/W-1, HC R/W-0 R/W-0 R/W-0 R/W-0
I2CEN — I2CSIDL SCLREL IPMIEN
( )1
A10M DISSLW SMEN
bit 15 bit 8
R/W-0 R/W-0 R/W-0 R/W-0, HC R/W-0, HC R/W-0, HC R/W-0, HC R/W-0, HC
GCEN STREN ACKDT ACKEN RCEN PEN RSEN SEN
bit 7 bit 0
Legend:
HC = Hardware Clearable bit
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at Reset ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15
I2CEN:
I2Cx Enable bit
1 = Enables the I2Cx module and configures the SDAx and SCLx pins as serial port pins
0 = Disables the I2Cx module; all the I
2
C pins are controlled by port functions
bit 14
Unimplemented:
Read as ‘0’
bit 13
I2CSIDL:
I2Cx Stop in Idle Mode bit
1 = Discontinues the module operation when a device enters the Idle mode
0 = Continues the module operation in the Idle mode
bit 12
SCLREL:
SCLx Release Control bit (when operating as I
2
C slave)
1 = Releases the SCLx clock
0 = Holds the SCLx clock low (clock stretch)
If STREN = 1:
User software may write ‘0’ to initiate a clock stretch and write ‘1’ to release the clock. Hardware clears
at the beginning of every slave data byte transmission. Hardware clears at the end of every slave
address byte reception. Hardware clears at the end of every slave data byte reception.
If STREN = 0:
User software may only write ‘1’ to release the clock. Hardware clears at the beginning of every slave
data byte transmission. Hardware clears at the end of every slave address byte reception.
bit 11
IPMIEN:
IPMI Enable bit
( )1
1 = IPMI Support mode is enabled, all addresses are Acknowledged
0 = IPMI Support mode is disabled
bit 10
A10M:
10-Bit Slave Address bit
1 = I2CxADD register is a 10-bit slave address
0 = I2CxADD register is a 7-bit slave address
bit 9
DISSLW:
Disable Slew Rate Control bit
1 = Slew rate control is disabled
0 = Slew rate control is enabled
bit 8
SMEN:
SMBus Input Levels bit
1 = Enables the I/O pin thresholds compliant with the SMBus specification
0 = Disables the SMBus input thresholds
bit 7
GCEN:
General Call Enable bit (when operating as I
2
C slave)
1 = Enables the interrupt when a general call address is received in the I2CxRSR register (module is
enabled for reception)
0 = Disables the general call address
bit 6
STREN:
SCLx Clock Stretch Enable bit (I
2
C Slave mode only; used in conjunction with the SCLREL bit)
1 = Enables the user software or the receive clock stretching
0 = Disables the user software or the receive clock stretching
Note 1:
The IPMIEN bit should not be set when the I
2
C module is operating as a master.
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 10  2007-2015 Microchip Technology Inc.
bit 5
ACKDT:
Acknowledge Data bit (I
2
C Master mode; receive operation only)
Value that will be transmitted when the user software initiates an Acknowledge sequence.
1 = Sends a NACK during an Acknowledge
0 = Sends an ACK during an Acknowledge
bit 4
ACKEN:
Acknowledge Sequence Enable bit (I
2
C Master mode receive operation)
1 = Initiates the Acknowledge sequence on the SDAx and SCLx pins and transmits the ACKDT data bit
(hardware clears at the end of the master Acknowledge sequence)
0 = Acknowledge sequence is not in progress
bit 3
RCEN:
Receive Enable bit (I
2
C Master mode)
1 = Enables Receive mode for I
2
C (hardware clears at the end of eighth bit of master receive data byte)
0 = Receive sequence is not in progress
bit 2
PEN:
Stop Condition Enable bit (I
2
C Master mode)
1 = Initiates the Stop condition on the SDAx and SCLx pins (hardware clears at the end of master Stop
sequence)
0 = Stop condition is not in progress
bit 1
RSEN:
Repeated Start Condition Enable bit (I
2
C Master mode)
1 = Initiates the Repeated Start condition on the SDAx and SCLx pins (hardware clears at the end of
master Repeated Start sequence)
0 = Repeated Start condition is not in progress
bit 0
SEN:
Start Condition Enable bit (I
2
C Master mode)
1 = Initiates the Start condition on the SDAx and SCLx pins (hardware clears at the end of master Start
sequence)
0 = Start condition is not in progress
Register 3-1: I2CxCON: I2Cx Control Register (Continued)
Note 1:
The IPMIEN bit should not be set when the I
2
C module is operating as a master.
 2007-2015 Microchip Technology Inc. DS70000195G-page 11
Inter-Integrated Circuit (I
2
C)
Register 3-2: I2CxCONL: I2Cx Control Register Low
R/W-0 U-0 R/W-0, HC R/W-1 R/W-0 R/W-0 R/W-0 R/W-0
I2CEN — I2CSIDL SCLREL
( )1
STRICT A10M DISSLW SMEN
bit 15 bit 8
R/W-0 R/W-0 R/W-0 R/W-0, HC R/W-0, HC R/W-0, HC R/W-0, HC R/W-0, HC
GCEN STREN ACKDT ACKEN RCEN PEN RSEN SEN
bit 7 bit 0
Legend:
HC = Hardware Clearable bit
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
bit 15
I2CEN:
I2Cx Enable bit
1 = Enables the I
2
C module and configures the SDAx and SCLx pins as serial port pins
0 = Disables the I
2
C module; all the I
2
C pins are controlled by port functions
bit 14
Unimplemented:
Read as ‘0’
bit 13
I2CSIDL:
I2Cx Stop in Idle Mode bit
1 = Discontinues the module operation when a device enters Idle mode
0 = Continues the module operation in the Idle mode
bit 12
SCLREL:
SCLx Release Control bit (I
2
C Slave mode only)
( )1
Module resets and (I2CEN = 0) sets SCLREL = 1.
If STREN = 0:
( )2
1 = Releases the clock
0 = Forces clock low (clock stretch)
If STREN = 1:
1 = Releases the clock
0 = Holds clock low (clock stretch); the user may program this bit to ‘0’, clock stretch at next SCLx low
bit 11
STRICT:
Strict I
2
C Reserved Address Rule Enable bit
1 = Strict reserved addressing is enforced; for reserved addresses
In a Slave mode, the device does not respond to reserved address space and the addresses falling
in that category are NACKed.
In a Master mode, the device is allowed to generate addresses with the reserved address space.
0 = Reserved addressing would be Acknowledged
In a Slave mode, the device will respond to an address falling in the reserved address space. When
there is a match with any of the reserved addresses, the device will generate an ACK .
In a Master mode, it is reserved.
bit 10
A10M:
10-Bit Slave Address Flag bit
1 = I2CxADD is a 10-bit slave address
0 = I2CxADD is a 7-bit slave address
bit 9
DISSLW:
Slew Rate Control Disable bit
1 = Slew rate control is disabled for Standard Speed mode (100 kHz, disabled for 1 MHz mode)
0 = Slew rate control is enabled for High-Speed mode (400 kHz)
bit 8
SMEN:
SMBus Input Levels Enable bit
1 = Enables the input logic; therefore, thresholds are compliant with the SMBus specification
0 = Disables the SMBus protocol-specific inputs
Note 1:
Automatically cleared to ‘0’ at the beginning of the slave transmission; automatically cleared to ‘0’ at the
end of the slave reception.
2:
Automatically cleared to ‘0’ at the beginning of the slave transmission.
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 12  2007-2015 Microchip Technology Inc.
bit 7
GCEN:
General Call Enable bit (I
2
C Slave mode only)
1 = Enables the interrupt when a general call address is received in I2CxRSR; the module is enabled for
reception
0 = General call address is disabled
bit 6
STREN:
SCLx Clock Stretch Enable bit
In I
2
C Slave mode only; used in conjunction with the SCLREL bit.
1 = Enables clock stretching
0 = Disables clock stretching
bit 5
ACKDT:
Acknowledge Data bit
In I
2
C Master mode during Master Receive mode. The value that will be transmitted when the user
initiates an Acknowledge sequence at the end of a receive.
In I
2
C Slave mode when AHEN = 1 or DHEN = 1. The value that the slave will transmit when it initiates
an Acknowledge sequence at the end of an address or data reception.
1 = NACK is sent
0 = ACK is sent
bit 4
ACKEN:
Acknowledge Sequence Enable bit
In I
2
C Master mode only; applicable during Master Receive mode.
1 = Initiates the Acknowledge sequence on the SDAx and SCLx pins, and transmits the ACKDT data bit
0 = Acknowledge sequence is in Idle mode
bit 3
RCEN:
Receive Enable bit (I
2
C Master mode only)
1 = Enables Receive mode for I
2
C; automatically cleared by hardware at the end of an 8-bit receive
data byte
0 = Receive sequence is not in progress
bit 2
PEN:
Stop Condition Enable bit (I
2
C Master mode only)
1 = Initiates the Stop condition on the SDAx and SCLx pins
0 = Stop condition is in Idle mode
bit 1
RSEN:
Restart Condition Enable bit (I
2
C Master mode only)
1 = Initiates the Restart condition on the SDAx and SCLx pins
0 = Restart condition is in Idle mode
bit 0
SEN:
Start Condition Enable bit (I
2
C Master mode only)
1 = Initiates the Start condition on the SDAx and SCLx pins
0 = Start condition is in Idle mode
Register 3-2: I2CxCONL: I2Cx Control Register Low (Continued)
Note 1:
Automatically cleared to ‘0’ at the beginning of the slave transmission; automatically cleared to ‘0’ at the
end of the slave reception.
2:
Automatically cleared to ‘0’ at the beginning of the slave transmission.
 2007-2015 Microchip Technology Inc. DS70000195G-page 13
Inter-Integrated Circuit (I
2
C)
Register 3-3: I2CxCONH: I2Cx Control Register High
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
— — — — — — — —
bit 15 bit 8
U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
— PCIE SCIE BOEN SDAHT SBCDE AHEN DHEN
bit 7 bit 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
bit 15-7
Unimplemented:
Read as ‘0’
bit 6
PCIE:
Stop Condition Interrupt Enable bit (I
2
C Slave mode only)
1 = Enables the interrupt on detection of a Stop condition
0 = Stop detection interrupts are disabled
bit 5
SCIE:
Start Condition Interrupt Enable bit (I
2
C Slave mode only)
1 = Enables the interrupt on detection of a Start or Restart condition
0 = Start detection interrupts are disabled
bit 4
BOEN:
Buffer Overwrite Enable bit (I
2
C Slave mode only)
1 = The I2CxRCV register is updated and an ACK is generated for a received address or data byte,
ignoring the state of the I2COV bit only if the RBF bit = 0
0 = The I2CxRCV register is only updated when the I2COV bit is clear
bit 3
SDAHT:
SDAx Hold Time Selection bit
( )1
1 = Minimum of 300 ns hold time on SDAx after the falling edge of the SCLx clock
0 = Minimum of 100 ns hold time on SDAx after the falling edge the of SCLx clock
bit 2
SBCDE:
Slave Mode Bus Collision Detect Enable bit (I
2
C Slave mode only)
If, on the rising edge of the SCLx, SDAx is sampled low when the module is outputting a high state, the
BCL bit is set and the bus goes into Idle mode. This Detection mode is valid only during the data and
ACK transmit sequences.
1 = Enables the slave bus collision interrupts
0 = Disables the slave bus collision interrupts
bit 1
AHEN:
Address Hold Enable bit (I
2
C Slave mode only)
1 = Following the falling edge of the eighth SCLx clock for a matching received address byte; the
SCLREL bit (I2CxCONL<12>) will be cleared and the SCLx will be held low
0 = Address holding is disabled
bit 0
DHEN:
Data Hold Enable bit (I
2
C Slave mode only)
1 = Following the eighth falling edge of the SCLx clock for a received data byte; slave hardware clears
the SCLREL bit (I2CxCONL<12>) and SCLx is held low
0 = Data holding is disabled
Note 1:
This bit must be set to ‘0’ for 1 MHz operation.
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 14  2007-2015 Microchip Technology Inc.
Register 3-4: I2CxSTAT: I2Cx Status Register
R-0, HSC R-0, HSC R-0, HSC U-0 U-0 R/C-0, HS R-0, HSC R-0, HSC
ACKSTAT TRSTAT ACKTIM
( )1
— — BCL GCSTAT ADD10
bit 15 bit 8
R/C-0, HS R/C-0, HS R-0, HSC R-0, HSC R-0, HSC R-0, HSC R-0, HSC R-0, HSC
IWCOL I2COV D/A P S R/W RBF TBF
bit 7 bit 0
Legend:
C = Clearable bit HSC = Hardware Settable/Clearable bit
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared HS = Hardware Settable bit
bit 15
ACKSTAT:
Acknowledge Status bit
1 = NACK received from slave
0 = ACK received from slave
Hardware sets or clears at the end of slave or master Acknowledge.
bit 14
TRSTAT:
Transmit Status bit (I
2
C Master mode transmit operation)
1 = Master transmit is in progress (8 bits + ACK)
0 = Master transmit is not in progress
Hardware sets at the beginning of master transmission; hardware clears at the end of slave Acknowledge.
bit 13
ACKTIM:
Acknowledge Time Status bit (valid in I
2
C Slave mode only)
( )1
1 = Indicates that the I
2
C bus is in an Acknowledge sequence; set on the falling edge of the eighth SCLx
clock
0 = Not an Acknowledge sequence, cleared on ninth rising edge of the SCLx clock
bit 12-11
Unimplemented:
Read as ‘0’
bit 10
BCL:
Bus Collision Detect bit (Master and Slave
modes)
1 = A bus collision has been detected during a master or slave operation
0 = No collision
Hardware sets at detection of a bus collision; clears when I
2
C module is disabled, I2CEN = 0.
bit 9
GCSTAT:
General Call Status bit
1 = General call address was received
0 = General call address was not received
Hardware sets when address matches general call address; hardware clears at Stop detection.
bit 8
ADD10:
10-Bit Address Status bit
1 = 10-bit address was matched
0 = 10-bit address was not matched
Hardware sets at match of second byte of matched 10-bit address; hardware clears at Stop detection.
bit 7
IWCOL:
I2Cx
Write Collision Detect bit
1 = An attempt to write to the I2CxTRN register failed because the I
2
C module is busy
0 = No collision
Hardware sets at occurrence of a write to the I2CxTRN register while busy (cleared by software).
bit 6
I2COV:
I2Cx
Receive Overflow Flag bit
1 = A byte is received while the I2CxRCV register is still holding the previous byte
0 = No overflow
Hardware sets at attempt to transfer the I2CxRSR register to the I2CxRCV register (cleared by software).
Note 1:
Refer to the specific device data sheet for availability of the ACKTIM bit.
 2007-2015 Microchip Technology Inc. DS70000195G-page 15
Inter-Integrated Circuit (I
2
C)
bit 5
D/A:
Data/Address bit (I
2
C Slave mode)
1 = Indicates that the last byte received was data
0 = Indicates that the last byte received was a device address
Hardware clears at device address match; hardware sets by reception of a slave byte or sets after the
transmission is complete and the TBF flag is cleared.
bit 4
P:
Stop bit
1 = Indicates that a Stop bit has been detected last
0 = Stop bit was not detected last
Hardware sets or clears when Start, Repeated Start or Stop is detected.
bit 3
S:
Start bit
1 = Indicates that a Start (or Repeated Start) bit has been detected last
0 = Start bit was not detected last
Hardware sets or clears when Start, Repeated Start or Stop is detected.
bit 2
R/W:
Read/Write Information bit (when operating as I
2
C slave)
1 = Read, data transfer is an output from the slave
0 = Write, data transfer is an input to the slave
Hardware sets or clears after reception of an I
2
C device address byte.
bit 1
RBF:
Receive Buffer Full Status bit
1 = Receive completes; the I2CxRCV register is full
0 = Receive is not complete; the I2CxRCV register is empty
Hardware sets when the I2CxRCV register is written with a received byte; hardware clears when user
software reads the I2CxRCV register.
bit 0
TBF:
Transmit Buffer Full Status bit
1 = Transmit is in progress; the I2CxTRN register is full
0 = Transmit completes; the I2CxTRN register is empty
Hardware sets when user software writes to the I2CxTRN register; hardware clears at completion of the
data transmission.
Register 3-4: I2CxSTAT: I2Cx Status Register (Continued)
Note 1:
Refer to the specific device data sheet for availability of the ACKTIM bit.
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 16  2007-2015 Microchip Technology Inc.
Register 3-5: I2CxMSK: I2Cx Slave Mode Address Mask Register
U-0 U-0 U-0 U-0 U-0 U-0 R/W-0 R/W-0
— — — — — — AMSK<9:8>
bit 15 bit 8
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
AMSK<7:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at Reset ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15-10
Unimplemented:
Read as ‘0’
bit 9-0
AMSK<9:0>:
Mask for Address Bit x Select bits
For 10-Bit Address:
1 = Enables masking for bit Ax of the incoming message address; bit match is not required in this position
0 = Disables masking for bit Ax; bit match is required in this position
For 7-Bit Address (I2CxMSK<6:0> only):
1 = Enables masking for bit Ax + 1 of the incoming message address; bit match is not required in this position
0 = Disables masking for bit Ax + 1; bit match is required in this position
 2007-2015 Microchip Technology Inc. DS70000195G-page 17
Inter-Integrated Circuit (I
2
C)
Register 3-6: ISRCCON: I2Cx Current Source Control Register
( )1
R/W-0 U-0 U-0 U-0 U-0 R/W-0 R/W-0 R/W-0
ISRCEN — — — — OUTSEL2 OUTSEL1 OUTSEL0
bit 15 bit 8
U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
— — ISRCCAL5
( )2
ISRCCAL4
( )2
ISRCCAL3
( )2
ISRCCAL2
( )2
ISRCCAL1
( )2
ISRCCAL0
( )2
bit 7 bit 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
bit 15
ISRCEN:
I2Cx Current Source Enable bit
1 = Current source is enabled
0 = Current source is disabled
bit 14-11
Unimplemented:
Read as ‘0’
bit 10-8
OUTSEL<2:0>:
Output Select for Current bits
111 = Reserved
110 = Reserved
101 = Reserved
100 = Selected input pin is ISRC4 (AN4)
011 = Selected input pin is ISRC3 (AN5)
010 = Selected input pin is ISRC2 (AN6)
001 = Selected input pin is ISRC1 (AN7)
000 = No output is selected
bit 7-6
Unimplemented:
Read as ‘0’
bit 5-0
ISRCCAL<5:0>:
I2Cx
Current Source Calibration bits
( )2
Note 1:
This register is not available on all devices. Refer to the specific device data sheet for availability.
2:
The calibration value must be retrieved from the Flash memory and stored in this location at start-up time.
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 18  2007-2015 Microchip Technology Inc.
4.0 ENABLING I 2C OPERATION
The I
2
C module is enabled by setting the I2CEN bit (I2CxCON<15> or I2CxCONL<15>). The I
2
C
module fully implements all master and slave functions. When the module is enabled, the master
and slave functions are active simultaneously and will respond according to the user software or
bus events.
When initially enabled, the module will release the SDAx and SCLx pins, putting the bus into an
Idle state. The master functions will remain in an Idle state unless the user software sets the SEN
control bit and the data is loaded into the I2CxTRN register. These two actions initiate a master
event.
When the master logic is active, the slave logic also remains active. Therefore, the slave
functions will begin to monitor the bus. If the slave logic detects a Start event and a valid address
on the bus, the slave logic will begin a slave transaction.
4.1 I2C I/O Pins
Two pins are used for the bus operation. These are the SCLx pin, which is the clock, and the
SDAx pin, which is the data. When the module is enabled, assuming no other module with higher
priority has control, the module will assume control of the SDAx and SCLx pins. The user
software need not be concerned with the state of the port I/O of the pins as the module overrides
the port state and direction. At initialization, the pins are tri-stated (released).
4.2 I2C Interrupts
The I
2
C module generates three interrupts: MI2CxIF, SI2CxIF and I2CxBCIF. The MI2CxIF
interrupt is assigned to the master events, the SI2CxIF interrupt is assigned to the slave events
and the I2CxBCIF is assigned for the bus collision interrupt. These interrupts set a corresponding
interrupt flag bit and interrupt the user software process if the corresponding interrupt enable bit
is set, and the corresponding interrupt priority is higher than the CPU interrupt priority.
The MI2CxIF interrupt is generated on completion of the following master message events:
• Start condition
• Stop condition
• Data transfer byte transmitted or received
• Acknowledge transmit
• Repeated Start
• Detection of a bus collision event.
The SI2CxIF interrupt is generated on detection of a message directed to the slave, including the
following events:
• Detection of a Start condition (see
Note 1
)
• Detection of a Stop condition (see
Note 1
)
• Detection of a Repeated Start condition (see
Note 1
)
• Detection of a valid device address (including general call) during data reception
• Request to transmit the data (ACK ) or to stop the data transmission (NACK)
• Reception of data
The I2CxBCIF interrupt is generated on a bus collision event in master/slave transmit operation:
• Start condition (master)
• Stop condition (master)
• Repeated Start (master)
• Data (master and slave)
• Acknowledge transmit (master and slave)
Note:
In some devices, the bus collision interrupt is not tied with the MI2CxIF interrupt.
Note 1:
These interrupts may not be present on all devices. Refer to the specific device
data sheet for availability.
 2007-2015 Microchip Technology Inc. DS70000195G-page 19
Inter-Integrated Circuit (I
2
C)
4.3 Setting Baud Rate When Operating as a Bus Master
When operating as an I
2
C master, the module must generate the system SCLx clock. Generally,
the I
2
C system clocks are specified to be either 100 kHz, 400 kHz or 1 MHz. The system clock
rate is specified as the minimum SCLx low time, plus the minimum SCLx high time. In most
cases, that is defined by two BRG periods (T
BRG
).
The reload value for the BRG is the I2CxBRG register, as illustrated in Figure 4-1. When the BRG
is loaded with this value, the generator counts down to zero and stops until another reload has
taken place. The BRG is reloaded automatically on baud rate restart. For example, if clock
synchronization is taking place, the BRG will be reloaded when the SCLx pin is sampled high.
Equation 4-1 shows the formula for computing the BRG reload value.
Equation 4-1: BRG Reload Value Calculation
Figure 4-1: Baud Rate Generator Block Diagram
Note:
The I2CxBRG register values that are less than two are not supported.
Note:
Equation 4-1 is only for a design guideline. Due to system-dependent parameters,
the actual baud rate may differ slightly. Testing is required to confirm that the actual
baud rate meets the system requirements; otherwise, the value of the I2CxBRG
register has to be adjusted.
(See
Note 1
)
Default (See
Note 1
and
Note 2
)
Where:
Typical value of delay varies from 110 ns to 130 ns.
Note 1:
Refer to the specific device data sheet for BRG reload value calculation.
2:
If there is no calculation mentioned in the data sheet, then the default BRG
reload value calculation should be considered.
or
I2CxBRG = 1
F
SCL
F
CY
2
– Delay  – 2
( )( )
I2CxBRG = 1
F
SCL
F
CY
– Delay – 2
( )( )
Down Counter T
BRG
=
T
CY
or T
CY
/2
(1)
I2CxBRG<8:0>
SCLx Reload
Control
Reload
Note 1:
Refer to the specific device data sheet for the clock rate.
2
T
SCL
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 20  2007-2015 Microchip Technology Inc.
5.0 COMMUNICATING AS A MASTER IN A SINGLE MASTER ENVIRONMENT
The I
2
C module’s typical operation in a system is using the I
2
C to communicate with an I
2
C
peripheral, such as an I
2
C serial memory. In an I
2
C system, the master controls the sequence of
all data communication on the bus. In this example, the dsPIC33/PIC24 device and its I
2
C
module have the role of the single master in the system. As the single master, it is responsible
for generating the SCLx clock and controlling the message protocol.
The I
2
C module controls individual portions of the I
2
C message protocol; however, sequencing
of the components of the protocol to construct a complete message is performed by the user
software.
For example, a typical operation in a single master environment is to read a byte from an I
2
C
serial EEPROM. Figure 5-1 illustrates the example message.
To accomplish this message, the user software will sequence through the following steps:
1. Assert a Start condition on SDAx and SCLx.
2. Send the I
2
C device address byte to the slave with a write indication.
3. Wait for and verify an Acknowledge from the slave.
4. Send the serial memory address high byte to the slave.
5. Wait for and verify an Acknowledge from the slave.
6. Send the serial memory address low byte to the slave.
7. Wait for and verify an Acknowledge from the slave.
8. Assert a Repeated Start condition on SDAx and SCLx.
9. Send the device address byte to the slave with a read indication.
10. Wait for and verify an Acknowledge from the slave.
11. Enable the master reception to receive serial memory data.
12. Generate an ACK or NACK condition at the end of a received byte of data.
13. Generate a Stop condition on SDAx and SCLx.
Figure 5-1: A Typical I
2
C Message: Read of Serial EEPROM (Random Address Mode)
The I
2
C module supports Master mode communication with the inclusion of the Start and Stop
generators, data byte transmission, data byte reception, Acknowledge generator and a BRG.
Generally, the user software will write to a control register to start a particular step, then wait for
an interrupt or poll status to wait for completion. These operations are discussed in the
subsequent sections.
Note:
The IPMIEN bit (I2CxCON<11>) should not be set when operating as a master.
Bus
Master
SDAx
Start
Address
Byte
EEPROM Address
High Byte
EEPROM Address
Low Byte
Address
Byte
Data
Byte
S
1010
AAA
0
210 R
1 0 1 0
AAA
1
210 P
Slave
SDAx
Activity
N
AAAA
Output
Output
Idle
R/W
ACK
ACK
ACK
Restart
R/W
ACK
NACK
Stop
Idle
Note:
The I
2
C module does not allow queuing of events. For example, the user software
is not allowed to initiate a Start condition and immediately write the I2CxTRN
register to initiate transmission before the Start condition is complete. In this case,
the I2CxTRN register will not be written to and the IWCOL status bit (I2CxSTAT<7>)
will be set, indicating that this write to the I2CxTRN register did not occur.
 2007-2015 Microchip Technology Inc. DS70000195G-page 21
Inter-Integrated Circuit (I
2
C)
5.1 Generating Start Bus Event
To initiate a Start event, the user software sets the SEN bit (I2CxCON<0> or I2CxCONL<0>).
Prior to setting the Start bit, the user software can check the P status bit (I2CxSTAT<4>) to ensure
that the bus is in an Idle state.
Figure 5-2 illustrates the timing of the Start condition.
• Slave logic detects the Start condition, sets the S status bit (I2CxSTAT<3>) and clears the
P status bit (I2CxSTAT<4>)
• The SEN bit is automatically cleared at completion of the Start condition
• The MI2CxIF interrupt is generated at completion of the Start condition
• After the Start condition, the SDAx line and SCLx lines are left low (Q state)
5.1.1 IWCOL STATUS FLAG
If the user software writes to the I2CxTRN register when a Start sequence is in progress, the
IWCOL status bit (I2CxSTAT<7>) is set and the contents of the transmit buffer are unchanged
(the write does not occur).
Figure 5-2: Master Start Timing Diagram
Note:
A delay (typically 150 nS) should be given between the enabling of the I
2
C module
and the Start bus event.
Note:
As the queuing of events is not allowed, writing to the lower 5 bits of the I2CxCON
or I2CxCONL register is disabled until the Start condition is complete.
SCLx (Master)
SDAx (Master)
S
SEN
MI2CxIF Interrupt
T
BRG
1 2 3 4
1
T
BRG
2
3
4
I
2
C Bus State (I) (Q)
P
(S) Writing SEN = initiates a master Start 1
event. BRG starts.
The BRG times out. Master module
drives SDAx low. The BRG restarts.
The slave detects the Start and sets
S = 1 and P = 0.
The BRG times out. The master
module drives SCLx low, generates an
interrupt and clears the SEN bit.
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 22  2007-2015 Microchip Technology Inc.
5.2 Sending Data to a Slave Device
The transmission of a data byte, a 7-bit device address byte or the second byte of a 10-bit
address is accomplished by writing the appropriate value to the I2CxTRN register. Loading this
register will start the following process:
1. The user software loads the I2CxTRN register with the data byte to transmit.
2. Writing to the I2CxTRN register sets the TBF bit (I2CxSTAT<0>).
3. The data byte is shifted out through the SDAx pin until all 8 bits are transmitted. Each bit
of address or data will be shifted out onto the SDAx pin after the falling edge of SCLx.
4. On the ninth SCLx clock, the module shifts in the ACK bit from the slave device and writes
its value into the ACKSTAT status bit (I2CxSTAT<15>).
5. The module generates the MI2CxIF interrupt at the end of the ninth SCLx clock cycle.
The module does not generate or validate the data bytes. The contents and usage of the bytes
are dependent on the state of the message protocol maintained by the user software.
The sequence of events that occur during master transmission and master reception are
provided in Figure 5-3.
Figure 5-3: Master Transmission Timing Diagram
D7 D6 D5 D4 D3 D2 D1 D0
SCLx (Master)
SCLx (Slave)
SDAx (Master)
SDAx (Slave)
TBF
I2CxTRN
MI2CxIF Interrupt
T
BRG
T
BRG
5 6 7 81 2 3 4
Writing to the I2CxTRN register will start a master transmission event. The TBF status bit is set.1
The BRG starts. The Most Significant Byte (MSB) of the I2CxTRN register drives SDAx. SCLx remains low. 2
The BRG times out. SCLx is released and the BRG restarts.3
The BRG times out. SCLx is driven low. After SCLx is detected low, the next bit of the I2CxTRN register drives SDAx.4
While SCLx is low, the slave can also pull SCLx low to initiate a Wait (clock stretch).5
Master has already released SCLx and slave can release to end the Wait. The BRG restarts.6
At the falling edge of the eighth SCLx clock, the master releases SDAx. The TBF status bit is cleared.
7
At the falling edge of the ninth SCLx clock, the master generates the interrupt. SCLx remains low until the next event.8
The slave releases SDAx and the TRSTAT status bit is clear.
I
2
C Bus State (Q) (D) (Q) (A) (Q)(D) (Q)
TRSTAT
ACKSTAT
The TRSTAT status bit is set.
The slave drives an ACK/NACK.
 2007-2015 Microchip Technology Inc. DS70000195G-page 23
Inter-Integrated Circuit (I
2
C)
5.2.1 SENDING A 7-BIT ADDRESS TO THE SLAVE
Sending a 7-bit device address involves sending one byte to the slave. A 7-bit address byte must
contain the 7 bits of the I
2
C device address and a R/W status bit that defines whether the
message will be a write to the slave (master transmission and slave reception) or a read from the
slave (slave transmission and master reception).
5.2.2 STRICT SUPPORT IN MASTER MODE
The master device is allowed to generate an address that falls in the reserved address space if the
STRICT bit (I2CxCONL<11>) is set. For more information on the reserved address, refer to Table 7-2.
5.2.3 SENDING A 10-BIT ADDRESS TO THE SLAVE
Sending a 10-bit device address involves sending two bytes to the slave. The first byte contains 5 bits
of the I
2
C device address reserved for 10-Bit Addressing modes and 2 bits of the 10-bit address. As
the next byte, which contains the remaining 8 bits of the 10-bit address, must be received by the slave,
the R/W status bit in the first byte must be ‘0’, indicating master transmission and slave reception. If
the message data is also directed toward the slave, the master can continue sending data. However,
if the master expects a reply from the slave, a Repeated Start sequence with the R/W status bit at ‘1’
will change the R/W state of the message to a read of the slave.
5.2.4 RECEIVING ACKNOWLEDGE FROM THE SLAVE
On the falling edge of the eighth SCLx clock, the TBF status bit is cleared and the master will
deassert the SDAx pin, allowing the slave to respond with an Acknowledge. The master will then
generate a ninth SCLx clock.
This allows the slave device being addressed to respond with an ACK bit during the ninth bit time
if an address match occurs or data was received properly. A slave sends an Acknowledge when
it has recognized its device address (including a general call) or when the slave has properly
received its data.
The status of ACK is written into the ACKSTAT bit (I2CxSTAT<15>) on the falling edge of the
ninth SCLx clock. After the ninth SCLx clock, the module generates the MI2CxIF interrupt and
enters into the Idle state until the next data byte is loaded into the I2CxTRN register.
5.2.5 ACKSTAT STATUS FLAG
The ACKSTAT bit (I2CxSTAT<15>) is cleared when the slave has sent an Acknowledge
(ACK = 0) and is set when the slave does not Acknowledge (ACK = 1).
5.2.6 TBF STATUS FLAG
When transmitting, the TBF status bit (I2CxSTAT<0>) is set when the CPU writes to the I2CxTRN
register and is cleared when all 8 bits are shifted out.
5.2.7 IWCOL STATUS FLAG
If the user software attempts to write to the I2CxTRN register when a transmit is already in
progress (that is, the module is still shifting a data byte), the IWCOL status bit (I2CxSTAT<7>) is
set and the contents of the buffer are unchanged (the write does not occur). The IWCOL status
bit must be cleared in the user software.
Note:
In a 7-Bit Addressing mode, each node using the I
2
C protocol should be configured
with a unique address that is stored in the I2CxADD register.
While transmitting the address byte, the master must shift the address bits<7:0>,
left by 1 bit, and configure bit 0 as the R/W bit.
Note:
In a 10-Bit Addressing mode, each node using the I
2
C protocol should be configured
with a unique address that is stored in the I2CxADD register.
While transmitting the first address byte, the master must shift the address
bits<9:8>, left by one bit, and configure bit 0 as the R/W bit.
Note:
Because queuing of events is not allowed, writing to the lower 5 bits of the I2CxCON
or I2CxCONL register is disabled until the transmit condition is complete.
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 24  2007-2015 Microchip Technology Inc.
5.3 Receiving Data from a Slave Device
The master can receive data from the slave device after the master has transmitted the slave
address with an R/W status bit value of ‘1’. This is enabled by setting the RCEN bit (I2CxCON<3>
or I2CxCONL<3>). The master logic begins to generate clocks, and before each falling edge of
the SCLx, the SDAx line is sampled and data is shifted into the I2CxRSR register.
After the falling edge of the eighth SCLx clock, the following events occur:
• The RCEN bit is automatically cleared
• The contents of the I2CxRSR register transfer into the I2CxRCV register
• The RBF status bit (I2CxSTAT<1>) is set
• The I
2
C module generates the MI2CxIF interrupt
When the CPU reads the receive buffer (I2CxRCV), the RBF status bit is automatically cleared.
The user software can process the data and then execute an Acknowledge sequence.
The sequence of events that occurs during master transmission and master reception is
illustrated in Figure 5-4.
Figure 5-4: Master Reception Timing Diagram
Note:
The lower 5 bits of the I2CxCON or I2CxCONL register must be ‘0’ before
attempting to set the RCEN bit. This ensures that the master logic is inactive.
D7 D6 D5 D4 D3 D2 D1 D0
SCLx (Master)
SCLx (Slave)
SDAx (Slave)
SDAx (Master)
RBF
I
2
C Bus State
MI2CxIF Interrupt
5 62 3 4
Writing the RCEN bit will start a master reception event. The BRG starts. SCLx remains low.2
The BRG times out. The master attempts to release SCLx. 3
When the slave releases SCLx, the BRG restarts.4
The BRG times out. The MSB of the response is shifted to the I2CxRSR register. SCLx is driven low for the next baud5
At the falling edge of the eighth SCLx clock, the I2CxRSR register is transferred to the I2CxRCV register. 6
RCEN
(D) (Q) (Q)(D)(Q)
I2CxRCV
(Q)
1
Typically, the slave can pull SCLx low (clock stretch) to request a Wait to prepare the data response. 1
The slave will drive the MSB of the data response on SDAx when ready.
(Q)
interval.
The module clears the RCEN bit. The RBF status bit is set. The master generates the interrupt.
T
BRG
T
BRG
 2007-2015 Microchip Technology Inc. DS70000195G-page 25
Inter-Integrated Circuit (I
2
C)
5.3.1 RBF STATUS FLAG
When receiving data, the RBF status bit (I2CxSTAT<1>) is set when a device address or data
byte is loaded into the I2CxRCV register from the I2CxRSR register. It is cleared when the user
software reads the I2CxRCV register.
5.3.2 I2COV STATUS FLAG
If another byte is received in the I2CxRSR register while the RBF status bit remains set, and the
previous byte remains in the I2CxRCV register, the I2COV status bit (I2CxSTAT<6>) is set and
the data in the I2CxRSR register is lost.
Leaving the I2COV status bit set does not inhibit further reception. If the RBF status bit is cleared
by reading the I2CxRCV register, and the I2CxRSR register receives another byte, that byte will
be transferred to the I2CxRCV register.
5.3.3 IWCOL STATUS FLAG
If the user software writes to the I2CxTRN register when a receive is already in progress (that is,
the I2CxRSR register is still shifting in a data byte), the IWCOL status bit (I2CxSTAT<7>) is set
and the contents of the buffer are unchanged (the write does not occur).
Note:
Because queuing of events is not allowed, writing to the lower 5 bits of the I2CxCON
register is disabled until the data reception condition is complete.
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 26  2007-2015 Microchip Technology Inc.
5.4 Acknowledge Generation
Setting the ACKEN bit (I2CxCON<4> or I2CxCONL<4>) enables the generation of a master
Acknowledge sequence.
Figure 5-5 illustrates an ACK sequence and Figure 5-6 illustrates a NACK sequence. The ACKDT
bit (I2CxCON<5> or I2CxCONL<5>) specifies an ACK or NACK sequence.
After two baud periods, the ACKEN bit is automatically cleared and the module generates the
MI2CxIF interrupt.
5.4.1 IWCOL STATUS FLAG
If the user software writes the I2CxTRN register when an Acknowledge sequence is in progress,
the IWCOL status bit (I2CxSTAT<7>) is set and the contents of the buffer are unchanged (the
write does not occur).
Figure 5-5: Master Acknowledge (ACK) Timing Diagram
Figure 5-6: Master Not Acknowledge (NACK) Timing Diagram
Note:
The lower 5 bits of the I2CxCON or I2CxCONL register must be ‘0’ (master logic
inactive) before attempting to set the ACKEN bit.
Note:
Because queuing of events is not allowed, writing to the lower 5 bits of the I2CxCON
or I2CxCONL register is disabled until the Acknowledge condition is complete.
SCLx (Master)
SDAx (Master)
ACKEN
MI2CxIF Interrupt
T
BRG
1 2 3
Writing ACKEN = 1 initiates a master Acknowledge event.
1
T
BRG
Writing ACKDT = 0 specifies sending an ACK.
When SCLx is detected low, the module drives SDAx low. 2
The BRG times out. Module releases SCLx. BRG restarts.
3
BRG times out. 4
I
2
C Bus State (A) (Q)(Q)
4
BRG starts. SCLx remains low.
Module drives SCLx low, then releases SDAx.
Module clears ACKEN. Master generates the interrupt.
(Q)
ACKDT = 0
SCLx (Master)
SDAx (Master)
ACKEN
MI2CxIF Interrupt
T
BRG
1 2 3
Writing ACKEN = 1 initiates a master Acknowledge event.
1
T
BRG
Writing ACKDT = 1 specifies sending a NACK.
When SCLx is detected low, the module releases SDAx.2
The BRG times out. Module releases SCLx. BRG restarts.3
The BRG times out. 4
I
2
C Bus State (A) (I)(Q)
4
BRG starts.
Module drives SCLx low, then releases SDAx.
Module clears ACKEN. Master generates the interrupt.
ACKDT = 1
(Q)
 2007-2015 Microchip Technology Inc. DS70000195G-page 27
Inter-Integrated Circuit (I
2
C)
5.5 Generating a Stop Bus Event
Setting the PEN bit (I2CxCON<2> or I2CxCONL<2>) enables the generation of a master Stop
sequence.
When the PEN bit is set, the master generates the Stop sequence, as illustrated in Figure 5-7.
• The slave detects the Stop condition, sets the P status bit (I2CxSTAT<4>) and clears the
S status bit (I2CxSTAT<3>)
• The PEN bit is automatically cleared
• The module generates the MI2CxIF interrupt
5.5.1 IWCOL STATUS FLAG
If the user software writes the I2CxTRN register when a Stop sequence is in progress, the
IWCOL status bit (I2CxSTAT<7>) is set and the contents of the buffer are unchanged (the write
does not occur).
Figure 5-7: Master Stop Timing Diagram
Note:
The lower 5 bits of the I2CxCON or I2CxCONL register must be ‘0’ (master logic
inactive) before attempting to set the PEN bit.
Note:
Because queuing of events is not allowed, writing to the lower 5 bits of the I2CxCON
or I2CxCONL register is disabled until the Stop condition is complete.
SCLx (Master)
SDAx (Master)
S
PEN
MI2CxIF Interrupt
T
BRG
1 2 3 5
Writing PEN = 1 initiates a master Stop event. 1
T
BRG
BRG starts. Module drives SDAx low.
The BRG times out. Module releases SCLx.
2
BRG restarts.
The BRG times out. Module releases SDAx.3
Slave logic detects a Stop. Module sets P = 1 and S = 0.4
I
2
C Bus State (I)
P
T
BRG
(Q)
4
BRG restarts.
The BRG times out. Module clears PEN. 5
Master generates the interrupt.
(Q) (P)
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 28  2007-2015 Microchip Technology Inc.
5.6 Generating a Repeated Start Bus Event
Setting the RSEN bit (I2CxCON<1> or I2CxCONL<1>) enables the generation of a master
Repeated Start sequence, as illustrated in Figure 5-8.
To generate a Repeated Start condition, the user software sets the RSEN bit. The master module
asserts the SCLx pin low. When the module samples the SCLx pin low, the module releases the
SDAx pin for 1 T
BRG
. When the BRG times out and the module samples SDAx high, the module
deasserts the SCLx pin. When the module samples the SCLx pin high, the BRG reloads and
begins counting. SDAx and SCLx must be sampled high for 1 T
BRG
. This action is then followed
by assertion of the SDAx pin low for 1 T
BRG
while SCLx is high.
The following is the Repeated Start sequence:
1. The slave detects the Start condition, sets the S status bit (I2CxSTAT<3>) and clears the
P status bit (I2CxSTAT<4>).
2. The RSEN bit is automatically cleared.
3. The I
2
C module generates the MI2CxIF interrupt.
5.6.1 IWCOL STATUS FLAG
If the user software writes the I2CxTRN register when a Repeated Start sequence is in progress,
the IWCOL status bit (I2CxSTAT<7>) is set and the contents of the buffer are not changed (the
write does not occur).
Figure 5-8: Master Repeated Start Timing Diagram
Note:
The lower 5 bits of the I2CxCON or I2CxCONL register must be ‘0’ (master logic
inactive) before attempting to set the RSEN bit.
Note:
Because queuing of events is not allowed, writing of the lower 5 bits of the I2CxCON
or I2CxCONL register is disabled until the Repeated Start condition is complete.
SCLx (Master)
SDAx (Master)
S
RSEN
MI2CxIF Interrupt
T
BRG
1 2 3 5
Writing RSEN = 1 initiates a master Repeated Start event.
1
T
BRG
BRG starts. Module drives SCLx low and
The BRG times out. Module releases SCLx. 2
BRG restarts.
The BRG times out. Module drives SDAx low.3
Slave logic detects Start. Module sets S = 1 and P = 0.4
I
2
C Bus State (Q)
P
T
BRG
(Q)
4
BRG restarts.
The BRG times out. Module drives SCLx low.5
Module clears RSEN. Master generates the interrupt.
(Q)
releases SDAx.
(S)
 2007-2015 Microchip Technology Inc. DS70000195G-page 29
Inter-Integrated Circuit (I
2
C)
5.7 Building Complete Master Messages
As described in
Section 5.0 “Communicating as a Master in a Single Master Environment”
,
the user software is responsible for constructing messages with the correct message protocol.
The module controls individual portions of the I
2
C message protocol; however, sequencing of the
components of the protocol to construct a complete message is performed by the user software.
The user software can use polling or interrupt methods while using the module. The timing
diagrams shown in this document use interrupts for detecting various events.
The user software can use the SEN, RSEN, PEN, RCEN and ACKEN bits (Least Significant 5 bits
of the I2CxCON or I2CxCONL register), and the TRSTAT status bit as a ‘state’ flag when progressing
through a message. For example, Table 5-1 shows some example state numbers associated with
bus states.
Table 5-1: Master Message Protocol States
The user software will begin a message by issuing a Start condition. The user software will record
the state number corresponding to the Start.
As each event completes and generates an interrupt, the interrupt handler may check the state
number. Therefore, for a Start state, the interrupt handler will confirm execution of the Start
sequence and then start a master transmission event to send the I
2
C device address, changing
the state number to correspond to the master transmission.
On the next interrupt, the interrupt handler will again check the state, determining that a master
transmission just completed. The interrupt handler will confirm successful transmission of the
data, then move on to the next event, depending on the contents of the message. In this manner,
on each interrupt, the interrupt handler will progress through the message protocol until the
complete message is sent.
Figure 5-9 provides a detailed examination of the same message sequence as shown in
Figure 5-1. Figure 5-10 provides a few simple examples of the messages using a 7-bit address-
ing format. Figure 5-11 provides an example of a 10-bit addressing format message sending data
to a slave. Figure 5-12 provides an example of a 10-bit addressing format message receiving
data from a slave.
Example
State Number
( )1
I2CxCON<4:0> or
I2CxCONL<4:0>
TRSTAT
(I2CxSTAT<14>) State
000000 0 Bus Idle or Wait
100001 N/A Sending Start Event
200000 1 Master Transmitting
300010 N/A Sending Repeated Start Event
400100 N/A Sending Stop Event
501000 N/A Master Reception
610000 N/A Master Acknowledgment
Note 1:
The example state numbers are for reference only. The user software can assign
the state numbers as desired.
DS70000195G-page 30  2007-2015 Microchip Technology Inc.
Figure 5-9: Master Message (Typical I
2
C Message: Read of Serial EEPROM)
1 Setting the SEN bit begins a Start event.
AKDT
ACKEN
SEN
SCLx
SDAx
SCLx
SDAx
I2CxTRN
TBF
I2CxRCV
RBF
MI2CxIF
ACKSTAT
1 2 3 4 5 6 7 8
A1 A0
9
A
PEN
RCEN
1 2 3 4 5 6 7 8
A11
A10
A9
A8
1 2 3 4 5 6 7 8 9
W
1 1
RSEN
1 2 3 4 5 6 7 8 9
1 32
9
A
1 2 3 4 5 6 7
D3 D2 DD7 D6 D5 D4AA
4 5 7
2Writing the I2CxTRN register starts a master transmission. The data is the serial
3 Writing the I2CxTRN register starts a master transmission. The data is the first
4
5
Writing the I2CxTRN register starts a master transmission6
Setting the RCEN bit starts a master reception. On interrupt,
7
9
Setting the ACKEN bit starts an Acknowledge event. ACK
Setting the PEN bit starts a master Stop event.
EEPROM device address byte, with the R/W status bit clear, indicating a write.
byte of the EEPROM data address.
the serial EEPROM device address byte, but with R/W statu
the I2CxRCV register, which clears the RBF status bit.
0 0 A2 A7 A6 A5 A4 A2 A1 A0 A1 A0 R
1 10 0 A2
0 0 0 0
6
Writing the I2CxTRN register starts a master transmission. The data is the second
byte of the EEPROM data address.
8
Setting the RSEN bit starts a Repeated Start event.
(Master)
(Master)
(Slave)
(Slave)
A3
MI2CxIF Interrupt Flag Cleared by User Software
 2007-2015 Microchip Technology Inc. DS70000195G-page 31
Figure 5-10: Master Message (7-Bit Address: Transmission and Reception)
1Setting the SEN bit begins a Start event.
AKDT
ACKEN
SEN
SCLx
SDAx
SCLx
SDAx
I2CxTRN
TBF
I2CxRCV
RBF
MI2CxIF
ACKSTAT
1 2 3 4 5 6 7 8
A2 A1
9
A
PEN
RCEN
1 2 3 4 5 6 7 8
D7 D6 D5 D4 D3 D2 D1 D0
1 2 3 4 5 6 7 8 9
W
RSEN
1 32
9 1 2 3 4 5 6 7
D3 D2 DD7 D6 D5 D4A
4 5 6 7
2 Writing the I2CxTRN register starts a master transmission. The data is the
3 Writing the I2CxTRN register starts a master transmission. The data is the
4 Setting the PEN bit starts a master Stop event.
5Setting the SEN bit begins a Start event. An interrupt is generated on completion
6Writing the I2CxTRN register starts a master transmis
7Setting the RCEN bit starts a master reception.
8Setting the ACKEN bit starts an Acknowledge event. AC
Setting the PEN bit starts a master Stop event.
address byte with the R/W status bit clear.
message byte.
A7 A6 A5 A4 A3
A
A2 A1 RA7 A6 A5 A4 A3
address byte with the R/W status bit set.
9
(Master)
(Master)
(Slave)
(Slave)
MI2CxIF Interrupt Flag Cleared by User Software
of the Start event.
 2007-2015 Microchip Technology Inc. DS70000195G-page 33
Figure 5-12: Master Message (10-Bit Reception)
1 Setting the SEN bit begins a Start event.
AKDT
ACKEN
SEN
SCLx
SDAx
SCLx
SDAx
I2CxTRN
TBF
I2CxRCV
RBF
MI2CxIF
ACKSTAT
1 2 3 4 5 6 7 8
A9 A8
9
A
PEN
RCEN
1 2 3 4 5 6 7 8
D3 D2 D1 D0D7 D6 D5 D4
A7 A6 A5 A4 A3 A2 A1 A0
1 2 3 4 5 6 7 8 9
W01 1 1 1
RSEN
A9 A801 1 1 1 R
1 2 3 4 5 6 7 8 9
1 32
9
A
1 2 3 4 5 6 7
D3 D2 D1D7 D6 D5 D4AA
4 5 6 7 8
2Writing the I2CxTRN register starts a master transmission. The data is the first
3 Writing the I2CxTRN register starts a master transmission. The data is the second
4 Setting the RSEN bit starts a master Restart event.
5 Writing the I2CxTRN register starts a master transmission. The data is a resend
6Setting the RCEN bit starts a master reception. On interru
7Setting the ACKEN bit starts an Acknowledge event. AC
8 Setting the RCEN bit starts a master reception.
9 Setting the ACKEN bit starts an Acknowledge event. AC
Setting the PEN bit starts a master Stop event.
byte of the address with the R/W status bit cleared.
byte of the address.
of the first byte with the R/W status bit set.
the I2CxRCV register, which clears the RBF status bit.
(Slave)
(Slave)
(Master)
(Master)
MI2CxIF Interrupt Flag Cleared in User Software
10
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 34  2007-2015 Microchip Technology Inc.
6.0 COMMUNICATING AS A MASTER IN A MULTI-MASTER ENVIRONMENT
The I
2
C protocol allows more than one master to be attached to a system bus. Taking into
account that a master can initiate message transactions and generate clocks for the bus, the
protocol has methods to account for situations where more than one master is attempting to
control the bus. The clock synchronization ensures that multiple nodes can synchronize their
SCLx clocks to result in one common clock on the SCLx line. The bus arbitration ensures that if
more than one node attempts a message transaction, only one node will be successful in
completing the message. The other nodes lose bus arbitration and are left with a bus collision.
6.1 Multi-Master Operation
The master module has no special settings to enable the multi-master operation. The module
performs the clock synchronization and bus arbitration at all times. If the module is used in a
single master environment, clock synchronization only occurs between the master and slaves,
and bus arbitration does not occur.
6.2 Master Clock Synchronization
In a multi-master system, different masters can have different baud rates. The clock
synchronization ensures that when these masters are attempting to arbitrate the bus, their clocks
will be coordinated.
The clock synchronization occurs when the master deasserts the SCLx pin (SCLx intended to
float high). When the SCLx pin is released, the BRG is suspended from counting until the SCLx
pin is actually sampled high. When the SCLx pin is sampled high, the BRG is reloaded with the
contents of I2CxBRG<8:0> and begins counting. This ensures that the SCLx high time will
always be at least one BRG rollover count in the event that the clock is held low by an external
device, as illustrated in Figure 6-1.
Figure 6-1: Baud Rate Generator Timing with Clock Synchronization
Note:
The IPMIEN bit (I2CxCON<11>) should not be set when operating as a master.
SCLx (Slave)
The baud counter decrements twice per T
CY
. On rollover, the master SCLx will transition.1
1
000 003001002003
SCLx (Master)
001002003000Baud Counter
SDAx (Master)
3 4 6
The slave has pulled SCLx low to initiate a Wait.2
At what would be the master baud counter rollover, detecting SCLx low holds the counter.
3
Logic samples SCLx once per T
CY
. Logic detects SCLx high.4
2
The baud counter rollover occurs on the next cycle.5
5
On the next rollover, the master SCLx will transition.6
T
BRG
T
BRG
T
CY
000
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 36  2007-2015 Microchip Technology Inc.
6.6 Bus Collision During a Repeated Start Condition
When the two masters do not collide throughout an address byte, a bus collision can occur when
one master attempts to assert a Repeated Start while another transmits data. In this case, the
master generating the Repeated Start loses arbitration and generates a bus collision interrupt.
6.7 Bus Collision During Message Bit Transmission
The most typical case of data collision occurs while the master is attempting to transmit the
device address byte, a data byte or an Acknowledge bit.
If the user software is properly checking the bus state, it is unlikely that a bus collision will occur
on a Start condition. However, because another master can, at the same time, check the bus and
initiate its own Start condition, it is likely that SDAx arbitration will occur and synchronize the Start
of two masters. In this condition, both masters begin and continue to transmit their messages
until one master loses arbitration on a message bit. The SCLx clock synchronization keeps the
two masters synchronized until one loses arbitration. Figure 6-2 illustrates an example of the
message bit arbitration.
Figure 6-2: Bus Collision During Message Bit Transmission
6.8 Bus Collision During a Stop Condition
If the master software loses track of the state of the I
2
C bus, many existing conditions can
cause a bus collision during a Stop condition. In this case, the master generating the Stop
condition will lose arbitration and generate a bus collision interrupt.
Note:
The bus collision interrupt is not available on all devices. Refer to the specific device
data sheet for availability.
SCLx (Master)
SDAx (Master)
TBF
T
BRG
1 2 3
Master transmits bit value of ‘1’ in the next SCLx clock.1
T
BRG
Module releases SDAx.
Another master on bus transmits the bit value of ‘0’
2
in the next SCLx clock. Another master pulls SDAx low.
BRG times out. Module attempts to verify SDAx high.3
I
2
C Bus State
BCL
(D)
SCLx (Bus)
SDAx (Bus)
Bus collision detected.
Module releases SDAx and SCLx. Module sets BCL status bit
and clears the TBF status bit. Master generates the interrupt.
(D)(Q)
(Q) (Q)
MI2CxIF Interrupt
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 38  2007-2015 Microchip Technology Inc.
7.3 Detecting the Address
Once the module has been enabled, the slave waits for a Start condition to occur. After a Start,
depending on the A10M bit (I2CxCON<10> or I2CxCONL<10>), the slave attempts to detect a
7-bit or 10-bit address. The slave compares one received byte for a 7-bit address or two received
bytes for a 10-bit address. A 7-bit address also contains an R/W status bit that specifies the direc-
tion of the data transfer after the address. If R/W = 0, a write is specified and the slave receives
data from the master. If R/W = 1, a read is specified and the slave sends data to the master. The
10-bit address contains an R/W status bit; however, by definition, it is always R/W = 0 because
the slave must receive the second byte of the 10-bit address.
7.3.1 SLAVE ADDRESS MASKING
The I2CxMSK register masks the address bit positions, designating them as “don’t care” bits for
both 10-Bit and 7-Bit Addressing modes. When a bit in the I2CxMSK register is set (= 1), the
slave responds when the bit in the corresponding location of the address is a ‘0’ or ‘1’. For
example, in 7-Bit Slave mode with I2CxMSK = 0100000, the slave module Acknowledges
addresses, ‘0000000’ and ’0100000’, as valid.
To enable address masking, the IPMI must be disabled by clearing the IPMIEN bit (I2CxCON<11>).
7.3.2 7-BIT ADDRESS AND SLAVE WRITE
After the Start condition, the module shifts 8 bits into the I2CxRSR register, as illustrated in
Figure 7-2. The value of the I2CxRSR register is evaluated against that of the I2CxADD and
I2CxMSK registers on the falling edge of the eighth clock (SCLx). If the address is valid (that is,
an exact match between unmasked bit positions), the following events occur:
• An ACK is generated if the AHEN bit is clear
• The D/A and R/W status bits are cleared
• The module generates the SI2CxIF interrupt on the falling edge of the ninth SCLx clock
• The module waits for the master to send data
Figure 7-2: Slave Write 7-Bit Address Detection Timing Diagram
Note:
The AHEN bit may not be available on all devices. Refer to the specific device data
sheet for availability. If this bit is not present, then the device will generate an (ACK )
on an address match.
SCLx (Master)
SDAx (Master)
SDAx (Slave)
SI2CxIF Interrupt
4 5
13
Detecting Start bit enables1
I
2
C Bus State
(D) (D) (A)(D)
A5A6A7 A4 A3 A2 A1
D/A
ADD10
SCLREL
R/W
address detection. If SCIE is set, then
R/W = 0 indicates that slave 3
receives data bytes.
Valid address of first byte clears D/A
4
status bit. Slave generates an ACK.
R/W status bit cleared. Slave
5
generates interrupt.
6
Bus waiting. Slave ready to6
receive data.
R/W = 0
(S) (Q)
2
2User software clears the interrupt
flag.
(1)
Note 1: The SCIE bit may not be available on all devices. Refer to the specific device data sheet for availability.
the slave interrupt is asserted.
(1)
 2007-2015 Microchip Technology Inc. DS70000195G-page 39
Inter-Integrated Circuit (I
2
C)
7.3.3 7-BIT ADDRESS AND SLAVE WRITE WITH THE AHEN AND DHEN BITS
The slave device reception, with the AHEN and DHEN bits set, operates with extra interrupts and
clock stretching added after the eighth falling edge of SCLx. These additional interrupts allow the
slave software to decide whether it wants to ACK the receive address or data byte, rather than
the hardware. This functionality adds support for the PMBus™ that was not present on previous
versions of this module.
Note:
The SI2CxIF interrupt is still set after the ninth falling edge of the SCLx clock, even
if there is no clock stretching and the RBF bit has been cleared. The SI2CxIF
interrupt is not asserted if a NACK is sent to the master.
 2007-2015 Microchip Technology Inc. DS70000195G-page 41
Figure 7-4: I
2
C Slave, 7-Bit Address, Reception (STREN = 1, AHEN = 0, DHEN = 0)
A7 A3A6 A5 A4 A2 A1 D7 D6 D5 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2D4SDAx
SCLx 1 2 3 4 5 6 7 8 9 123456789 1 2 3 4 5 6
SCLREL
I2COV
RBF
ACK
SI2CxIF
1 3 4 5 6 7 8 11109
1
Detecting Start bit, enables address detection, interrupt is set if SCEN is set.
3
4
5
9
11
12
RBF is set on the 8th falling clock, address is loaded into I2CxRCV. RBF is asserted.
Interrupt is asserted.
SCLx is stretched low until SCLREL is set.
User software reads the I2CxRCV buffer, that clears the RBF flag.
User software releases the SCLx line by writing SCLREL to ‘1’.
Data is loaded into I2CxRCV. RBR flag is asserted.
On the 9th falling clock edge, interrupt is asserted.
SCLx is stretched and held low until SCLREL is set
User software releases SCLx line by writing SCLRE
NACK is received (SCLx is not stretched to low).
2
2
User software clears the interrupt flag.
13
Slave recognizes the Stop event.
7
6
8
10
R/W = 0
ACK
 2007-2015 Microchip Technology Inc. DS70000195G-page 43
Figure 7-6: I
2
C Slave, 7-Bit Address, Transmission (AHEN = 1)
A7 A6 A5 A4 A3 A2 A1 D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D
12345678 9 123456789 123456
SDAx
SCLx
SI2CxIF
RBF
ACKDT
SCLREL
ACK
R/W = 1
ACK
ACKTIM
TBF
1 2 3 4 5 6 7 8 9 1110
1
Detecting Start bit enables address detection, interrupt is set if the SCIE bit is set.
2
User software clears the interrupt flag.
3
Slave receives the address byte with R/W = 1. Hardware clears SCLREL to
suspend master clock. ACKTIM and interrupt flag are asserted.
4
User software clears the interrupt flag.
5
Software reads the I2CxRV register, that clears the RBF flag.
6
ACKDT is written with ACK.
7
User software sets SCLREL to release clock hold. Master clocks in the
Acknowledgment sequence. ACKTIM is cleared by hardware.
9
User software clears the interrupt flag.
10
User software loads the I2CxTRN register with respons
indicates that the buffer is full.
11
After last bit, module clears TBF bit, indicating buffer is av
12
At the end of ninth clock, if master sent NACK, no mor
Module does not suspend the clock.
13
Module recognizes Stop event.
8
Hardware clears SCLREL to suspend master clock if R
10
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 46  2007-2015 Microchip Technology Inc.
7.3.6 SLAVE MODE BUS COLLISION
On a read request from the master, the slave begins shifting data out on the SDAx line. If a bus
collision is detected and the SBCDE bit (I2CxCONH<2>) is set, then the I2CxBCIF bit will be set.
After detecting the bus collision, the slave goes into Idle mode and waits to be addressed again.
User software can use the I2CxBCIF bit or vectors to the bus collision interrupt to handle a slave
bus collision.
7.3.7 GENERAL CALL OPERATION
The addressing procedure for the I
2
C bus is such that the first byte after a Start condition usually deter-
mines which slave device the master is addressing. The exception is the general call address, which
can address all devices. When this address is used, all the enabled devices respond with an Acknowl-
edge. The general call address is one of the eight addresses reserved for specific purposes by the
I
2
C protocol. It consists of all ‘0’s with R/W = 0. The general call is always a slave write operation.
The general call address is recognized when the General Call Enable bit, GCEN (I2CxCON<7>
or I2CxCONL<7>), is set, as illustrated in Figure 7-9. Following a Start bit detect, 8 bits are shifted
into the I2CxRSR register, and the address is compared against the I2CxADD register and the
general call address.
If the general call address matches, the following events occur:
• An ACK is generated
• The slave will set the GCSTAT status bit (I2CxSTAT<9>)
• The D/A and R/W status bits are cleared
• The module generates the SI2CxIF interrupt on the falling edge of the ninth SCLx clock
• The I2CxRSR register is transferred to the I2CxRCV register and the RBF status bit
(I2CxSTAT<1>) is set (during the eighth bit)
• The module waits for the master to send data
When the interrupt is serviced, the cause for the interrupt can be checked by reading the contents of
the GCSTAT status bit to determine if the device address was device-specific or a general call address.
Note:
The SBCDE and I2CxBCIF bits may not be available on all the devices. Refer to the
specific device data sheet for availability.
Note 1:
General call addresses are 7-bit addresses. If configuring the slave for 10-bit
addresses and the A10M and GCEN bits are set, the slave will continue to detect
the 7-bit general call address.
2:
The slave will Acknowledge the general call address (7-bit address, 0x00) only if
GCEN is set, and independent of the STRICT and A10M bits.
dsPIC33/PIC24 Family Reference Manual
DS70000195G-page 48  2007-2015 Microchip Technology Inc.
7.3.9 STRICT SUPPORT
The slave module Acknowledges all the addresses, including the reserved addresses, when
STRICT reserved addressing is not enforced (STRICT = 0). The slave device does not
Acknowledge the reserved address space if the STRICT bit (I2CxCONL<11>) is set.
Table 7-1: Slave Response to Reserved Addresses
7.3.10 WHEN AN ADDRESS IS INVALID
If a 7-bit address does not match the contents of the I2CxADD<6:0> bits, the slave will return to
an Idle state and ignore any activity on the I
2
C bus until after the Stop condition.
If the first byte of a 10-bit address does not match the contents of the I2CxADD<9:8> bits, the
slave will return to an Idle state and ignore all bus activity until after the Stop condition.
If the first byte of a 10-bit address matches the contents of the I2CxADD<9:8> bits, but the
second byte of the 10-bit address does not match the I2CxADD<7:0> bits, the slave will return
to an Idle state and ignore all bus activity until after the Stop condition.
STRICT Bit I2CxADD
Slave Address
Received Address
into I2CxRSR Slave Acknowledge
x0x1F 0x1F ACK
10x1F C-Bus Address NACK
1C-Bus Address C-Bus Address NACK
0C-Bus Address C-Bus Address ACK
0C-Bus Address 0x1F NACK
00x1F C-Bus Address NACK
Note:
When the STRICT bit is cleared, the ACK signal is generated only if the address is
matched, even for reserved addresses. The slave device does not generate an ACK
if there is an address mismatch, even if the address is a reserved address. Irrespec-
tive of the STRICT bit setting, and the address is reserved or not, an ACK signal is
generated for a proper address match.
 2007-2015 Microchip Technology Inc. DS70000195G-page 49
Inter-Integrated Circuit (I
2
C)
7.3.11 ADDRESSES RESERVED FROM MASKING
Even when enabled, there are several addresses that are ignored by the I
2
C module. For these
addresses, an Acknowledge will not be issued independent of the mask setting. These
addresses are listed in Table 7-2.
Table 7-2: Reserved I
2
C Bus Addresses
( )3
7.4 Receiving Data from a Master Device
When the R/W status bit of the device address byte is ‘0’ and an address match occurs, the R/W
status bit (I2CxSTAT<2>) is cleared. The slave enters a state waiting for data to be sent by the
master. After the device address byte, the contents of the data byte are defined by the system
protocol and are only received by the slave.
The slave shifts 8 bits into the I2CxRSR register. On the falling edge of the eighth clock (SCLx),
the following events occur:
• The module begins to generate an ACK or NACK.
• The RBF status bit (I2CxSTAT<1>) is set to indicate received data.
• The I2CxRSR register byte is transferred to the I2CxRCV register for access by the user
software.
• The D/A status bit is set.
• A slave interrupt is generated. User software can check the status of the I2CxSTAT register
to determine the cause of the event and then clear the SI2CxIF interrupt flag.
• The module waits for the next data byte.
7-Bit Address Mode
Slave Address R/W Bit Description
0000 000 0 General Call Address
( )1
0000 000 1 Start Byte
0000 001 x C-Bus Address
0000 010 x Reserved
0000 011 x Reserved
0000 1xx x HS Mode Master Code
1111 1xx x Reserved
1111 0xx x 10-Bit Slave Upper Byte
( )2
Note 1:
Address will be Acknowledged only if GCEN = 1.
2:
A match on this address can only occur as the upper byte in 10-Bit Addressing mode.
3:
These addresses will not be Acknowledged, independent of mask settings and
STRICT = 1.
 2007-2015 Microchip Technology Inc. DS70000195G-page 53
Figure 7-12: Slave Message (Write Data to Slave: 10-Bit Address; Address Matches; A10M = 1, GCEN = , IPMIEN = 0 0, AHEN
STRICT = 0 and BOEN = 0)
1 Slave recognizes Start event, S and P bits set/clear accordingly.
SCLx (Master)
SDAx (Master)
SCLx (Slave)
SDAx (Slave)
I2CxRCV
RBF
SI2CxIF
STREN
12345678
A9A8
9
A
A7A6A5A4A3A2 A1
123456789
1 32
A
4 4
2 Slave receives address byte. High-order address matches.
3 Slave receives address byte. Low-order address matches.
4 Next received byte is message data. Byte moved to the I2CxR
5 User software reads the I2CxRCV register. RBF bit clears.
6 Slave recognizes Stop event, S and P bits set/clear according
Slave Acknowledges and generates interrupt. Address byte is
Slave Acknowledges and generates interrupt.
S
P
I2COV
R/W
D/A
D7D6D5D4D3D2D1
123456789
A
D7D6D5D4D3D2D1
123456789
A
D7D6D5D4D3
12345
SCLREL
5 5
1 1 1 1 0
Slave Acknowledges and generates interrupt. Address byte is
moved to the I2CxRCV register and is read by user software to prevent
moved to the I2CxRCV register and is read by user software to prevent
buffer overflow.
buffer overflow.
W A0 D0 D0
SI2CxIF Cleared by User Software
DS70000195G-page 54  2007-2015 Microchip Technology Inc.
Figure 7-13: Slave Message (Write Data to Slave: 7-Bit Address; Buffer Overrun; A10M = 0, GCEN = 0, IPMIEN = 0, AHEN = 0,
STRICT = 0 and BOEN = 0)
SCLx (Master)
SDAx (Master)
SCLx (Slave)
SDAx (Slave)
I2CxRCV
RBF
SI2CxIF
STREN
1 2 3 4 5 6 7 8
A2 A1
9
A
D7 D6 D5 D4 D3 D2 D1
1 2 3 4 5 6 7 8 9
21
A
3 4
1Slave receives address byte. Address matches. Slave generates interrupt. Address byte
2Next received byte is message data. The byte is moved to the I2CxRCV register, sets RBF.
5 User software reads the I2CxRCV register. RBF
6User software clears the I2COV bit. Reception wil
Slave generates interrupt. Slave Acknowledges reception.
A7 A6 A5 A4 A3
S
P
I2COV
R/W
D/A
D7 D6 D5 D4 D3 D2 D1
1 2 3 4 5 6 7 8 9
N
D7 D3 D2 D1D6 D5 D4
1 2 3 4 5 6 7 8 9
D7 D6 D5 D4 D3
1 2 3 4 5
SCLREL
5
3Next byte received before I2CxRCV is read by software. I2CxRCV register is unchanged.
I2COV overflow bit is set. Slave generates interrupt. Slave sends NACK for reception.
N
6
4 Next byte also received before I2CxRCV is read
reception. The master state machine should not b
register is unchanged. Slave generates interrup
D0 D0W D0
5
normally until the module sees a Stop/Repeated S
conditions is met, an additional transmission will b
sends a NACK and sets the I2COV bit again.
another byte after receiving a NACK in this manne
the transmission with a Stop condition or send a R
and attempt to retransmit the data.
is moved to the I2CxRCV register and must be read by user software to prevent buffer overflow.
SI2CxIF Cleared by User Software


Produktspezifikationen

Marke: Microchip
Kategorie: Nicht kategorisiert
Modell: PIC24HJ32GP204

Brauchst du Hilfe?

Wenn Sie Hilfe mit Microchip PIC24HJ32GP204 benĂśtigen, stellen Sie unten eine Frage und andere Benutzer werden Ihnen antworten




Bedienungsanleitung Nicht kategorisiert Microchip

Bedienungsanleitung Nicht kategorisiert

Neueste Bedienungsanleitung fĂźr -Kategorien-