12 I
2
C (I2C)
12-12
Seiko epson Corporation
S1C17F13 TeChniCal Manual
(Rev. 1.0)
Data transmission
End
YES
NO
I2C
n
INTF.NACKIF = 1 ?
Write data to the I2C
n
TXD register
Wait for an interrupt request
(I2C
n
INTF.TBEIF = 1 or I2C
n
INTF.NACKIF = 1)
4.5.2 Slave Mode Data Transmission Flowchart
Figure 12.
Data Reception in Slave Mode
12.4.6
A data receiving procedure in slave mode and the I2C Ch.
n
operations are shown below. Figures 12.4.6.1 and 12.4.6.2
show an operation example and a flowchart, respectively.
Data receiving procedure
1. Wait for a START condition interrupt (I2C
n
INTF.STARTIF bit = 1).
2. Check to see if the I2C
n
INTF.TR bit = 0 (reception mode).
(Start a data sending procedure if I2C
n
INTF.TR bit = 1.)
3. Clear the I2C
n
INTF.STARTIF bit by writing 1.
4. Wait for a receive buffer full interrupt (I2C
n
INTF.RBFIF bit = 1) generated when a one-byte reception has
completed or an end of transfer interrupt (I2C
n
INTF.BYTEENDIF bit = 1).
Clear the I2C
n
INTF.BYTEENDIF bit by writing 1 after the interrupt has occurred.
5. If the next receive data is the last one, write 1 to the I2C
n
CTL.TXNACK bit to send a NACK after it is re-
ceived.
6. Read the received data from the I2C
n
RXD register.
7. Repeat Steps 4 to 6 until the end of data reception.
Data receiving operations
START condition detection and slave address check
It is the same as the data transmission in slave mode.
However, the I2C
n
INTF.TR bit is cleared to 0 and the I2C
n
INTF.TBEIF bit is not set.
If the I2C
n
MOD.GCEN bit is set to 1 (general call address response enabled), the I2C Ch.
n
starts data re-
ceiving operations when the general call address is received.
Slave mode can be operated even in SLEEP mode, it makes it possible to wake the CPU up using an inter-
rupt when an address match is detected.
Receiving the first data byte
After the valid slave address has been received, the I2C Ch.
n
sends an ACK and pulls down SCL to low un-
til 1 is written to the I2C
n
INTF.STARTIF bit. This puts the I
2
C bus into clock stretching state and the exter-
nal master into standby state. When 1 is written to the I2C
n
INTF.STARTIF bit, the I2C Ch.
n
releases SCL
and receives data sent from the external master into the shift register. After eight-bit data has been received,
the I2C Ch.
n
sends an ACK and pulls down SCL to low. The received data in the shift register is transferred
to the receive data buffer and the I2C
n
INTF.RBFIF and I2C
n
INTF.BYTEENDIF bits are both set to 1. Af-
ter that, the received data can be read out from the I2C
n
RXD register.
Receiving subsequent data
When the received data is read out from the I2C
n
RXD register after the I2C
n
INTF.RBFIF bit has been set to 1,
the I2C Ch.
n
clears the I2C
n
INTF.RBFIF bit to 0, releases SCL, and receives subsequent data sent from the
external master. After eight-bit data has been received, the I2C Ch.
n
sends an ACK and pulls down SCL to
low. The received data in the shift register is transferred to the receive data buffer and the I2C
n
INTF.RBFIF
and I2C
n
INTF.BYTEENDIF bits are both set to 1.