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()?

Parents
  • 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

Reply
  • 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

Children