I2C API 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 receive mode, all of these addresses (or groups if masks are used) will be monitored for a match. If the General Call bit (least significant bit of any of the four slave address bytes) is set, then the General Call address of 0x00 is monitored as well.

I2C slave mode set-up address packing

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);-->
error_code = LPC_I2CD_API->i2c_set_slave_addr((I2C_HANDLE_T*)i2c_handle,slave_addr, slave_addr_mask) ;-->