Software example, 1 initialization routine, 2 start master transmit function – NXP Semiconductors LPC24XX UM10237 User Manual

Page 603: 3 start master receive function, Section 22–10.1, Nxp semiconductors

Advertising
background image

UM10237_4

© NXP B.V. 2009. All rights reserved.

User manual

Rev. 04 — 26 August 2009

603 of 792

NXP Semiconductors

UM10237

Chapter 22: LPC24XX I

2

C interfaces I

2

C0/1/2

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.

9.12.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.

9.12.3 The state service routines

Each state routine is part of the I

2

C interrupt routine and handles one of the 26 states.

9.12.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 timeout during I

2

C

operations, in order to trap an inoperative bus or a lost service routine.

10. Software example

10.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.

10.2 Start master transmit function

Begin a Master Transmit operation by setting up the buffer, pointer, and data count, then
initiating a Start.

1. Initialize Master data counter.

2. Set up the Slave Address to which data will be transmitted, and add the Write bit.

3. Write 0x20 to I2CONSET to set the STA bit.

4. Set up data to be transmitted in Master Transmit buffer.

5. Initialize the Master data counter to match the length of the message being sent.

6. Exit

10.3 Start master receive function

Begin a Master Receive operation by setting up the buffer, pointer, and data count, then
initiating a Start.

1. Initialize Master data counter.

Advertising