© Koninklijke Philips Electronics N.V. 2005. All rights reserved.
User manual
Rev. 01 — 15 August 2005
163
Philips Semiconductors
UM10139
Volume 1
Chapter 11: I
2
C interfaces
•
The 26 state service routines providing support for all four I
2
C operating modes.
11.8.15 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:
•
I2ADR is loaded with the part’s own slave address 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 CR0 and CR1
in I2CON. 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.
11.8.16 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.
11.8.17 The State service routines
Each state routine is part of the I
2
C interrupt routine and handles one of the 26 states.
11.8.18 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 timeout during I
2
C
operations, in order to trap an inoperative bus or a lost service routine.
11.9 Software example
11.9.1 Initialization
routine
Example to initialize I
2
C Interface as a Slave and/or Master.
1. Load I2ADR with own Slave Address, enable general call recognition if needed.
2. Enable I
2
C interrupt.
3. Write 0x44 to I2CONSET to set the I2EN and AA bits, enabling Slave functions. For
Master only functions, write 0x40 to I2CONSET.
11.9.2 Start Master Transmit function
Begin a Master Transmit operation by setting up the buffer, pointer, and data count, then
initiating a Start.