Download UM10601 LPC800 User manual

Transcript
UM10601
NXP Semiconductors
Chapter 24: LPC800 I2C-bus ROM API
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.
pI2cApi = ROM_DRIVERS_PTR->pI2CD; //setup I2C function table pointer
size_in_bytes = pI2cApi->i2c_get_mem_size();
i2c_handle = pI2cApi->i2c_setup(LPC_I2C_BASE, (uint32_t *)&I2C_Handle[0] );
error_code = pI2cApi->i2c_set_bitrate((I2C_HANDLE_T*)i2c_handle, PCLK_in_Hz,
bps_in_hz);
24.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
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.
ϯϭϮϱ Ϯϰ Ϯϯ
ϭϳ ϭϲ
ϭϱ
^ůĂǀĞĚĚƌĞƐƐϯ
'
^ůĂǀĞĚĚƌĞƐƐϮ
'
ϭ
Ϭ
^ůĂǀĞĚĚƌĞƐƐϬ
'
ϵ
ϴ ϳ
^ůĂǀĞĚĚƌĞƐƐϭ
'
Fig 48. I2C slave mode set-up address packing
pI2cApi = ROM_DRIVERS_PTR->pI2CD; //setup I2C function table pointer
size_in_bytes = pI2cApi->i2c_get_mem_size();
i2c_handle = pI2cApi->i2c_setup(LPC_I2C_BASE, (uint32_t *)&I2C_Handle[0] );
error_code = pI2cApi->i2c_set_bitrate((I2C_HANDLE_T*)i2c_handle, PCLK_in_Hz,
bps_in_hz);
error_code = pI2cApi->i2c_set_slave_addr((I2C_HANDLE_T*)i2c_handle, slave_addr,
slave_addr_mask) ;
UM10601
User manual
All information provided in this document is subject to legal disclaimers.
Rev. 1.2 — 14 March 2013
© NXP B.V. 2013. All rights reserved.
298 of 337