I2C Read/Write in FX2LP - KBA224159

Version 2

    Version: **

     

    Translation - Japanese: FX2LPでのI2C読み取り/書き込み - KBA224159 - Community Translated (JA)

     

    Question:

    How can I perform an I2C read followed by an I2C write in FX2LP?

     

    Answer:

    The EZUSB.LIB library can be used for performing I2C read/write in FX2LP. To perform an I2C write and read back the data from an I2C slave device, use the following sequence of commands:

     

    BYTE xdata BUFFER[2];

    DATA01[2] = { 0x00, 0xAA }      // First byte indicates the internal address of EEPROM

                                  // Second byte indicates the data to be written                     

     

    //I2C Write

    EZUSB_WriteI2C(0x50, 0x02, DATA01);     // Write the data to the slave device with address 0x50

    EZUSB_WaitForEEPROMWrite(0x50);         // Wait until the I2C write is completed

     

     

    //I2C Read

    EZUSB_WriteI2C(0x50, 0x01, DATA01);   // Write the internal slave address from which the data is  to be read

    EZUSB_ReadI2C(0x50, 0x01, BUFFER[0]); // Read the data from the slave device and store it in BUFFER