15.11.2012 Views

LPC2131/2132/2138 User Manual - mct.net

LPC2131/2132/2138 User Manual - mct.net

LPC2131/2132/2138 User Manual - mct.net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Philips Semiconductors Preliminary <strong>User</strong> <strong>Manual</strong><br />

ARM-based Microcontroller<br />

SOFTWARE EXAMPLE<br />

Initialization Routine<br />

Example to initialize I 2 C Interface as a Slave and/or Master.<br />

<strong>LPC2131</strong>/<strong>2132</strong>/<strong>2138</strong><br />

11. Load I2ADR with own Slave Address, enable general call recognition if needed.<br />

12. Enable I2 C interrupt.<br />

13. Write 0x44 to I2CONSET to set the I2EN and AA bits, enabling Slave functions. For Master only funcitons, write 0x40 to<br />

I2CONSET.<br />

Start Master Transmit Function<br />

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

14. Initialize Master data counter.<br />

15. Set up the Slave Address to which data will be transmitted, and add the Write bit.<br />

16. Write 0x20 to I2CONSET to set the STA bit.<br />

17. Set up data to be transmitted in Master Transmit buffer.<br />

18. Initialize the Master data counter to match the length of the message being sent.<br />

19. Exit<br />

Start Master Receive Function<br />

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

20. Initialize Master data counter.<br />

21. Set up the Slave Address to which data will be transmitted, and add the Read bit.<br />

22. Write 0x20 to I2CONSET to set the STA bit.<br />

23. Set up the Master Receive buffer.<br />

24. Initialize the Master data counter to match the length of the message to be received.<br />

25. Exit<br />

I 2 C Interrupt Routine<br />

Determine the I 2 C state and which state routine will be used to handle it.<br />

26. Read the I2C status from I2STA.<br />

27. Use the status value to branch to one of 26 possible state routines.<br />

Non Mode Specific States<br />

State : 00<br />

Bus Error. Enter not addressed Slave mode and release bus.<br />

28. Write 0x14 to I2CONSET to set the STO and AA bits.<br />

29. Write 0x08 to I2CONCLR to clear the SI flag.<br />

I2C Interfaces I2C0 and I2C1 144 November 22, 2004

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!