UM10360 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2013. All rights reserved.
User manual Rev. 3 — 19 December 2013 466 of 841
NXP Semiconductors
UM10360
Chapter 19: LPC176x/5x I2C0/1/2
19.9.8 I
2
C state service routines
This section provides examples of operations that must be performed by various I
2
C state
service routines. This includes:
• Initialization of the I
2
C block after a Reset.
• I
2
C Interrupt Service
• The 26 state service routines providing support for all four I
2
C operating modes.
19.9.8.1 Initialization
In the initialization example, the I
2
C block is enabled for both master and slave modes.
For each mode, a buffer is used for transmission and reception. The initialization routine
performs the following functions:
• The I2ADR registers and I2MASK registers are loaded with values to configure the
part’s own slave address(es) and the General Call bit (GC)
• The I
2
C interrupt enable and interrupt priority bits are set
• The slave mode is enabled by simultaneously setting the I2EN and AA bits in I2CON
and the serial clock frequency (for master modes) is defined by loading the
I2SCLH
and I2SCLL registers.
The master routines must be started in the main program.
The I
2
C hardware now begins checking the I
2
C-bus for its own slave address and General
Call. If the General Call or the own slave address is detected, an interrupt is requested
and I2STAT is loaded with the appropriate state information.
19.9.8.2 I
2
C interrupt service
When the I
2
C interrupt is entered, I2STAT contains a status code which identifies one of
the 26 state services to be executed.
19.9.8.3 The state service routines
Each state routine is part of the I
2
C interrupt routine and handles one of the 26 states.
19.9.8.4 Adapting state services to an application
The state service examples show the typical actions that must be performed in response
to the 26 I
2
C state codes. If one or more of the four I
2
C operating modes are not used, the
associated state services can be omitted, as long as care is taken that the those states
can never occur.
In an application, it may be desirable to implement some kind of time-out during I
2
C
operations, in order to trap an inoperative bus or a lost service routine.