14 I
2
C (I2C)
S1C17M20/M21/M22/M23/M24/M25
Seiko Epson Corporation
14-5
TECHNICAL MANUAL (Rev. 1.0)
14.4.2 Data Transmission in Master Mode
A data sending procedure in master mode and the I2C Ch.
n
operations are shown below. Figures 14.4.2.1 and 14.4.2.2
show an operation example and a flowchart, respectively.
Data sending procedure
1. Issue a START condition by setting the I2C
n
CTL.TXSTART bit to 1.
2. Wait for a transmit buffer empty interrupt (I2C
n
INTF.TBEIF bit = 1) or a START condition interrupt (I2C-
n
INTF.STARTIF bit = 1).
Clear the I2C
n
INTF.STARTIF bit by writing 1 after the interrupt has occurred.
3. Write the 7-bit slave address to the I2C
n
TXD.TXD[7:1] bits and 0 that represents WRITE as the data trans-
fer direction to the I2C
n
TXD.TXD0 bit.
4. Wait for a transmit buffer empty interrupt (I2C
n
INTF.TBEIF bit = 1) generated when an ACK is received or
a NACK reception interrupt (I2C
n
INTF.NACKIF bit = 1) generated when a NACK is received.
i. Go to Step 5 if transmit data remains when a transmit buffer empty interrupt has occurred.
ii. Go to Step 7 or 1 after clearing the I2C
n
INTF.NACKIF bit when a NACK reception interrupt has oc-
curred.
5. Write transmit data to the I2C
n
TXD register.
6. Repeat Steps 4 and 5 until the end of transmit data.
7. Issue a STOP condition by setting the I2C
n
CTL.TXSTOP bit to 1.
8. Wait for a STOP condition interrupt (I2C
n
INTF.STOPIF bit = 1).
Clear the I2C
n
INTF.STOPIF bit by writing 1 after the interrupt has occurred.
Data sending operations
Generating a START condition
The I2C Ch.
n
starts generating a START condition when the I2C
n
CTL.TXSTART bit is set to 1. When the
generating operation has completed, the I2C Ch.
n
clears the I2C
n
CTL.TXSTART bit to 0 and sets both the
I2C
n
INTF.STARTIF and I2C
n
INTF.TBEIF bits to 1.
Sending slave address and data
If the I2C
n
INTF.TBEIF bit = 1, a slave address or data can be written to the I2C
n
TXD register. The I2C
Ch.
n
pulls down SCL to low and enters standby state until data is written to the I2C
n
TXD register. The
writing operation triggers the I2C Ch.
n
to send the data to the shift register automatically and to output
eight clock pulses and data bits to the I
2
C bus.
When the slave device returns an ACK as the response, the I2C
n
INTF.TBEIF bit is set to 1. After this inter-
rupt occurs, the subsequent data may be sent or a STOP/repeated START condition may be issued to termi-
nate transmission. If the slave device returns NACK, the I2C
n
INTF.NACKIF bit is set to 1 without setting
the I2C
n
INTF.TBEIF bit.
Generating a STOP/repeated START condition
After the I2C
n
INTF.TBEIF bit is set to 1 (transmit buffer empty) or the I2C
n
INTF.NACKIF bit is set to 1
(NACK received), setting the I2C
n
CTL.TXSTOP bit to 1 generates a STOP condition. When the bus free
time (t
BUF
defined in the I
2
C Specifications) has elapsed after the STOP condition has been generated, the
I2C
n
CTL.TXSTOP bit is cleared to 0 and the I2C
n
INTF.STOPIF bit is set to 1.
When setting the I2C
n
CTL.TXSTART bit to 1 while the I2C
n
INTF.TBEIF bit = 1 (transmit buffer empty)
or the I2C
n
INTF.NACKIF bit = 1 (NACK received), the I2C Ch.
n
generates a repeated START condition.
When the repeated START condition has been generated, the I2C
n
INTF.STARTIF and I2C
n
INTF.TBEIF
bits are both set to 1 same as when a START condition has been generated.