UM10208_2
© NXP B.V. 2007. All rights reserved.
User manual
Rev. 02 — 1 June 2007
203 of 362
NXP Semiconductors
UM10208
Chapter 16: LPC2800 I
2
C
8.3 Master Transmit mode
Software should initiate Master Transmit mode first calling “set_IEs” with OCIE, DRMIE,
and NAIE, plus AFIE if there’s another master in the application. Then software or a DMA
channel should write an address/direction byte to the I2TX register, with the direction bit 0
for master-to-slave transmission and bit 8=1 indicating that a Start condition should be
sent before the byte. (Software may as well write the whole frame to I2TX, or fill the Tx
FIFO if the frame is longer than 16 bytes.)
In a multi-master application, the I
2
C interface may need to wait until it detects a Stop
condition at the end of the current frame. Thereafter, or immediately if no frame is in
progress, the I
2
C interface drives a Start condition on the bus and begins to send the
address/direction byte.
For each bit in each byte that it sends, the I
2
C interface waits for the time specified in
I2CLKHI, drives SCL low, then releases SDA for a 1 bit or drives SDA low for a 0 bit, then
waits for the time specified in I2CLKLO, then releases SCL. It samples the state of SDA
when SCL goes high.
If this interface isn’t driving SDA low because the current bit is a 1, and it samples SDA
low from another master, this signifies that this master has lost arbitration for the current
frame. In this case the I
2
C interface:
1. flushes the Tx FIFO
2. stops driving SCL and SDA
3. sets the AFI bit in I2STS. Assuming that this interrupt is enabled by the AFIE bit in
I2CTL, this results in an interrupt to inform the software of the arbitration loss.
Software should write a 1 to AFI in I2STS to clear the condition, set the central state
variable to “master transmit”, then add Receive FIFO Not Empty to the interrupts
enabled in I2CTL (making OCIE, NAIE, DRMIE, ASFIE, and RFNE). Typically
software would then rewrite the frame to I2TX for future retransmission.
4. If arbitration is lost in the address/direction byte, the I
2
C interface will continue to
assemble the byte, and will compare it to the value in I2ADR when it’s complete. It the
value matches, the interface will store the byte in the Rx FIFO, clearing the Receive
FIFO Empty (RFE) bit in I2STS, which will result in an interrupt.
If the ISR sees RFE=0 with the central state variable = “master transmit”, it’s clear that the
LPC288x lost arbitration in the address/direction byte and was then addressed by that
byte. The ISR should proceed as described in “Slave mode” on page 205.
Another possible result in Master Transmission is that the I
2
C interface completes sending
a byte, waits for the time defined in I2CLKHI, drives SCL low again for the following
acknowledge bit, releases SDA, waits for the time defined in I2CLKLO, and releases SCL.
When SCL goes high the I
2
C interface samples the state of SDA.
If SDA is high, no slave acknowledged the byte, and the I
2
C interface responds by setting
the NAI bit in I2STS. Since NAIE is 1 in I2CTL, this results in an interrupt. When the
service routine sees NAI set in I2STS, it can determine which byte was not acknowledged
by reading the I2TXB register. If NAI is set for the address/direction byte, this probably
indicates that no slave is configured to respond to the address value. If NAI is set for a
subsequent byte, it probably indicates that the slave cannot accept the current byte at this
time, but may be able to accept it in the future.