EZ-USB FX3 Technical Reference Manual, Document Number: 001-76074 Rev. *F 174
Low Performance Peripherals (LPP)
preamble.buffer[1] = (uint8_t)(byteAddress >> 8);
preamble.buffer[2] = (uint8_t)(byteAddress & 0xFF);
preamble.buffer[3] = (devAddr | 0x01);
preamble.ctrlMask = 0x0004;
status = CyU3PI2cReceiveBytes (&preamble, buffer, (pageCount == 1) ? resCount :
glI2cPageSize, 0);
}
else /* Write */
{
/* Update the preamble information. */
preamble.length = 3;
preamble.buffer[0] = devAddr;
preamble.buffer[1] = (uint8_t)(byteAddress >> 8);
preamble.buffer[2] = (uint8_t)(byteAddress & 0xFF);
preamble.ctrlMask = 0x0000;
status = CyU3PI2cTransmitBytes (&preamble, buffer, (pageCount == 1) ? resCount :
glI2cPageSize, 0);
/* Wait for the write to complete. */
preamble.length = 1;
status = CyU3PI2cWaitForAck(&preamble, 200);
}
/* An additional delay seems to be required after receiving an ACK. */
CyU3PThreadSleep (1);
/* Update the parameters */
byteAddress += glI2cPageSize;
buffer += glI2cPageSize;
pageCount --;
}
}
8.2.4.4 Reads and Writes Using DMA Transfers
A DMA channel (glI2cTxHandle) is created to transfer data to an I2C slave device, and another DMA channel
(glI2cRxHandle) is created to read data from the I2C slave device. The following code reads and writes to an I2C slave using
DMA transfers.
CyFxUsbI2cTransfer (uint16_t byteAddress, uint8_t devAddr, uint16_t byteCount, uint8_t
*buffer, CyBool_t isRead)
{
CyU3PDmaBuffer_t buf_p;
CyU3PI2cPreamble_t preamble;
uint16_t pageCount = (byteCount / glI2cPageSize);
CyU3PReturnStatus_t status = CY_U3P_SUCCESS;
if ((byteCount % glI2cPageSize) != 0)
{
pageCount ++;
}
/* Update the buffer address. */
buf_p.buffer = buffer;
buf_p.status = 0;