UM10208_2
© NXP B.V. 2007. All rights reserved.
User manual
Rev. 02 — 1 June 2007
204 of 362
NXP Semiconductors
UM10208
Chapter 16: LPC2800 I
2
C
If NAI is 1 but TFE (also in I2STS) is 0, unused entries remain in the Tx FIFO, and the ISR
should write a 1 to the SoftReset bit in I2CTL, to flush the Tx FIFO in preparation for
resuming I
2
C activity.
Another possible event during Master Transmission is that the I
2
C interface sends all of
the bytes in the Tx FIFO, but the last one is not marked “send a Stop condition after this
byte”. In this case the interface sets the Master Data Request (DRMI) bit in I2STS.
Assuming that DRMIE in I2CTL is 1, this results in an interrupt. On seeing DRMI set, the
interrupt service routine should write more data to I2TX, then dismiss the interrupt.
The final possible outcome of Master Transmission is that the I
2
C interface sends all of
the bytes in the Tx FIFO, and the last one
is
marked “send a Stop condition after this
byte”. In this case the interface sets the Operation Complete bit (OCI) in I2STS. Assuming
that OCIE in I2CTL is 1, this results in an interrupt. The interrupt service routine should
write a 1 to OCI in I2STS to clear the condition, and can then proceed to initiate further
Master Transmission or Reception. Otherwise it should set the central state variable to
“idle”, write I2CTL with RFNEE if another master can address the LPC288x as a slave, or
0 if not, and dismiss the interrupt.
8.4 Master Receive mode
Software should initiate Master Receive mode by calling “set_IEs” with the same interrupt
enables as in Master Transmit mode: 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 1 for slave-to-master
transmission, and bit 8=1 indicating that a Start condition should be sent before the byte.
For Master Receive mode, this description assumes that the software knows the format of
the frame for reading data from the slave. Following the address/direction byte, software
or a DMA channel should write I2TX with bytes indicating whether Start conditions should
precede, or Stop conditions should follow, each of the subsequent received bytes. When
these bytes have been written to the Tx FIFO, software should store the number of bytes
in a variable.
As for Master Transmit mode, 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 interface drives a Start condition on the bus and
begins to send the address/direction byte.
In Master Receive mode, arbitration can only be lost in the address/direction byte. As in
Master Transmit mode, when the ISR sees AFI set, it should clear AFI by writing to I2STS,
set the central state variable to “master receive”, then add Receive FIFO Not Empty to the
set of interrupt enables in I2CTL. It can then reload the Tx FIFO for a future retry of the
Master Receive operation. If the number of bytes written to the Tx FIFO differs from the
previous loading, the ISR should update the variable noted above.
If arbitration is lost and the I
2
C interface then detects its slave address, it places the
address/direction byte in the Rx FIFO, which results in an interrupt as described for
Master Transmit mode. If the ISR sees RFE=0 in I2STS with the central state variable set
to “master receive”, this may mean either of two things: 1) the winning master has
addressed the LPC288x, or 2) the winning master addressed some other slave, the I
2
C
interface has retried the Master Receive operation, sent the address/direction byte, had it
acknowledged by the slave, and has since received the first data byte from the slave.