
UM10800
All information provided in this document is subject to legal disclaimers.
© NXP Semiconductors N.V. 2016. All rights reserved.
User manual
Rev. 1.2 — 5 October 2016
425 of 487
NXP Semiconductors
UM10800
Chapter 29: LPC82x ROM API I2C driver routines
2. Enable the two pins required for the SCL and SDA outputs of the I2C peripheral.
3. Allocate a RAM area for dedicated use of the I2C ROM Driver.
After the I2C block is configured, the I2C ROM driver variables have to be set up:
1. Initialize pointer to the I2C API function table.
2. Declare the PARAM and RESULT struct.
3. Declare Error Code struct.
4. Declare the transmit and receive buffer.
If interrupts are used, then additional driver variables have to be set up:
1. Declare the I2C_CALLBK_T type.
2. Declare callback functions.
3. Declare I2C ROM Driver ISR within the I2C ISR.
4. Enable I2C interrupt.
29.5.2 I2C Master mode set-up
The I2C ROM Driver support polling and interrupts. In the master mode, 7-bit and 10-bit
addressing are supported. The setup is as follows:
1. Allocate SRAM for the I2C ROM Driver by making a call to the i2c_get_mem_size()
function.
2. Create the I2C handle by making a call to the i2c_setup() function.
3. Set the I2C operating frequency by making a call to the i2c_set_bitrate() function.
size_in_bytes = LPC_I2CD_API->i2c_get_mem_size();
i2c_handle = LPC_I2CD_API->i2c_setup(LPC_I2C_BASE, (uint32_t *)&I2C_Handle[0] );
error_code = LPC_I2CD_API->i2c_set_bitrate((I2C_HANDLE_T*)i2c_handle, PCLK_in_Hz,
bps_in_hz);
29.5.3 I2C Slave mode set-up
The I2C ROM Driver support polling and interrupts in the slave mode. In the slave mode,
only 7-bit addressing is supported. The set-up is as follows:
1. Allocate SRAM for the I2C ROM Driver by making a call to the i2c_get_mem_size()
function.
2. Create the I2C handle by making a call to the i2c_setup() function.
3. Set the I2C operating frequency by making a call to the i2c_set_bitrate() function.
4. Set the slave address by making a call to the i2c_set_slave_addr() function.
The I2C ROM driver allows setting up to 4 slave addresses and 4 address masks as well
as possibly enabling the General Call address.
The four slave address bytes are packed into the 4 byte variable. Slave address byte 0 is
the least significant byte and Slave address byte 3 is the most significant byte. The Slave
address mask bytes are ordered the same way in the other 32 bit variable. When in slave