This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

EZUSB FX2 I2C EZUSB_WaitForEEPROMWrite() problem

Hi,

I'm trying to access an EEPROM with an EZUSB FX2 dev board. I have written the following code to write to the EEPROM

   eeprom_buf[0]  = LSB(0);
   eeprom_buf[1]  = value;
   eeprom_buf[2] = EZUSB_WriteI2C(0x53, 2, eeprom_buf);
   EZUSB_WaitForEEPROMWrite(0x53);


This writes the device I2C address(0x53), the internal EEPROM address(0) followed by the actual data value. It used to work, but suddenly it doesn't seem to work anymore.

I've checked the actual SDA/SCL lines to see what's going through, and it seems that the problem lies with EZUSB_WaitForEEPROMWrite(). Right before this function is called, the SDA waveform looks fine. It shows 101001100(address 0x53, a WR, and finally an ACK), followed by 000000000(address 0, ACK), followed by 000011100(value 0xE, ACK), then a 1(STOP).

Once I include the EZUSB_WaitForEEPROMWrite() function, the device address(1010011) keeps getting written to the bus over and over again, and the controller keeps receiving a NACK instead. EZUSB_WriteI2C() returns 1, so apparently it is successful.

Does anyone know why? Do I even need to run EZUSB_WaitForEEPROMWrite()?

  • After you send the write operation to the EEPROM, it is busy for a while. In this period, the EEPROM will not respond until the write is complete. This period is called as Write Cycle Time and it takes 5ms or so. See the datasheet of your EEPROM.

    EZUSB_WaitForEEPROMWrite() is designed to detect the response of the EEPROM. When you continue EEPROM operation further after the write operation, you need to call it to know the end of the write operation.

    Of course, you can insert another short task between the EEPROM operation.

    Tsuneo

  • Thanks. That makes sense. I guess that's why the EEPROM device keeps sending NAKs...signalling that it's not ready. However, I don't understand why I'm getting problems when I put EZUSB_WaitForEEPROMWrite() in my code. When I try to read back the data from the same address, I don't get the previously written data.

  • EZUSB_WriteI2C() kicks the I2C write session.
    However, when this routine returns, the write session is still going on, using the I2C ISR. Then, you have to wait until I2CPckt.status becomes I2C_IDLE, which shows the end of the session.

    EZUSB_WaitForEEPROMWrite() disturbs the write session. This routine should be called while I2C_IDLE.

    #define EEPROM_ADDR    0x53
    
    eeprom_buf[0]  = LSB(0);
    eeprom_buf[1]  = value;
    if ( EZUSB_WriteI2C( EEPROM_ADDR, 2, eeprom_buf ) != I2C_OK )
        return FALSE;
    while( I2CPckt.status != I2C_IDLE );      // wait for write session
    EZUSB_WaitForEEPROMWrite( EEPROM_ADDR );  // wait for Write Cycle Time
    EZUSB_ReadI2C( EEPROM_ADDR, 1, &(eeprom_buf[2]) );
    

    Tsuneo

  • hello..
    have someone tell me how to use EZUSB_WriteI2C() pagewrite(64byte) eeprom ? thanks