I2C Read using FX2™ and FX2LP™ - KBA85382

Version 1
    Version: **


    Question: How is I2C read implemented in FX2 and FX2LP?



    I2C read implementation is illustrated in the file i2c.c, which is available in the path \Cypress\USB\Target\Lib\LP\i2c.c.

    In this file, the implementation of read occurs in the ISR. The I2C_Read function sends the Read Command and changes the I2C.PktStatus to I2C_PRIME. The I2C enters the ISR every time a byte of data is successfully transferred when the DONE bit is set High.

    When the following section of code is executed for the first time, the data that has been read is stored to I2CPckt.dat and the status is changed to I2C_RECEIVING:

    case I2C_PRIME:
    I2CPckt.dat[I2CPckt.count] = I2DAT;
    I2CPckt.status = I2C_RECEIVING;
    if(I2CPckt.length == 1) // may be only one byte read
    I2CS |= bmLASTRD;

    To read more data, the following section of the code is executed the next time the ISR is serviced:

    case I2C_RECEIVING:
    if(I2CPckt.count == I2CPckt.length - 2)
    I2CS |= bmLASTRD;
    if(I2CPckt.count == I2CPckt.length - 1)
    I2CS |= bmSTOP;
    I2CPckt.status = I2C_IDLE;
    I2CPckt.dat[I2CPckt.count] = I2DAT;