EZ-USB FX3 Technical Reference Manual, Document Number: 001-76074 Rev. *F 173
Low Performance Peripherals (LPP)
/* Initialize the LPP block if not already started. */
CyU3PLppInit (CY_U3P_LPP_I2C, CyU3PI2cInt_ThreadHandler);
CyU3PMutexCreate (&glI2cLock, CYU3P_NO_INHERIT);
/* Power on the I2C module */
I2C->lpp_i2c_power = 0;
CyU3PBusyWait (10);
I2C->lpp_i2c_power |= 1 << 31;
while (!(I2C->lpp_i2c_power & CY_U3P_LPP_I2C_ACTIVE));
/* Clear the error status */
glI2cStatus = 0;
/* Mark the module as active. */
glIsI2cActive = CyTrue;
}
8.2.4.2 Configure I2C Block
The CyU3PI2cSetConfig API configures the FX3 I2C block. Following is the code for setting the I2C bus frequency to 400
kHz. DMA transfers are not enabled in the following code. i2cConfig.isDma would need to be set CyTrue(1) to enable DMA
transfers.
/* Start the I2C master block. The bit rate is set at 100 kHz. */
CyU3PMemSet ((uint8_t *)&i2cConfig, 0, sizeof(i2cConfig));
i2cConfig.bitRate = 400000;
i2cConfig.busTimeout = 0xFFFFFFFF;
i2cConfig.dmaTimeout = 0xFFFF;
i2cConfig.isDma = CyFalse;
CyU3PI2cSetConfig (&i2cConfig, NULL);
8.2.4.3 Reads and Writes Using Register Transfers
The CyU3PI2cReceiveBytes API reads data from the I2C slave in register mode, and the CyU3PI2cTransmitBytes API writes
data to an I2C slave in register mode. The following code performs reads and writes to an I2C slave using register transfers.
CyFxUsbI2cTransfer (uint16_t byteAddress, uint8_t devAddr, uint16_t byteCount, uint8_t
*buffer, CyBool_t isRead)
{
CyU3PI2cPreamble_t preamble;
uint16_t pageCount = (byteCount / glI2cPageSize);
uint16_t resCount = glI2cPageSize;
CyU3PReturnStatus_t status = CY_U3P_SUCCESS;
if ((byteCount % glI2cPageSize) != 0)
{
pageCount ++;
resCount = byteCount % glI2cPageSize;
}
while (pageCount != 0)
{
if (isRead) /* Read */
{
/* Update the preamble information. */
preamble.length = 4;
preamble.buffer[0] = devAddr;