1

I have been working on FTDI FT2232H chip to interface with I2C devices. I have started to learn AN_177 application note pdf. I have no EEPROM to expreience,no oscilloscope to see waveforms. My goal is to comprehend the code itself and taking notes for my future projects. Here is the code snippet that i dont completely understand:

FT_STATUS write_byte(uint8 slaveAddress, uint8 registerAddress, uint8 data)
{
    uint32 bytesToTransfer = 0;
    uint32 bytesTransfered;
    bool writeComplete=0;
    uint32 retry=0;
    bytesToTransfer=0;
    bytesTransfered=0;
    buffer[bytesToTransfer++]=registerAddress; /* Byte addressed inside EEPROM */
    buffer[bytesToTransfer++]=data;
    status = I2C_DeviceWrite(ftHandle, slaveAddress, bytesToTransfer, buffer, &bytesTransfered, I2C_TRANSFER_OPTIONS_START_BIT|I2C_TRANSFER_OPTIONS_STOP_BIT);

    /* poll to check completition */
    while((writeComplete==0)&& (retry<I2C_WRITE_COMPLETION_RETRY))
    {
        bytesToTransfer=0;
        bytesTransfered=0;
        buffer[bytesToTransfer++]=registerAddress; /* Addressed inside EEPROM  */
        status = I2C_DeviceWrite(ftHandle, slaveAddress, bytesToTransfer,buffer, &bytesTransfered, I2C_TRANSFER_OPTIONS_START_BIT|I2C_TRANSFER_OPTIONS_BREAK_ON_NACK);

        if((FT_OK == status) && (bytesToTransfer == bytesTransfered))
        {
            writeComplete=1;
            printf("  ... Write done\n");
        }
        retry++;
    }
    return status;
}

You can see and understand that the while loop is the polling part.

I checked the datasheet of 24LC024H I2C EEPROM and they mentioned about Acknowladge Polling (Page 10) is a feature of this kind of EEPROMs'. Acknowladge Polling basicly checks when the device is ready to send data. There is a flow diagram too... you could take a look. Flowchart

Here comes the what i want to point out:

buffer[bytesToTransfer++]=registerAddress; /* Addressed inside EEPROM  */

In the 24LC024H datasheet related to Acknowladge Polling they say polling part consist of START + Control Byte (or Slave address) + R/W bit, not include address inside EEPROM (Word address in I2C protocol) . So why FTDI guys included this line of code? Am I missing something?

Best regards...

hex
  • 21
  • 6
  • It doesn't hurt anything and isn't needed. Perhaps the API requires at least one byte of data and won't work without it (I've encountered I2C implementations like that), but it isn't needed according to spec and doesn't hurt be be transmitted even so since data to write at the address isn't provided. – Mark Tolonen May 08 '20 at 22:59
  • You are right it doesnt hurt anything. "Perhaps the API requires at least one byte of data" -> I think so but then why they wouldn't use dummy register address like 0xFF or something? Code is from FTDI and ı have mailed them about this issue. – hex May 09 '20 at 23:38
  • By the way, "I've encountered I2C implementations like that" -> Could you find an implementation of that you come accross? – hex May 09 '20 at 23:48
  • Private implementations of I2C implementations. Also the address doesn’t matter if only the address is sent with no data – Mark Tolonen May 10 '20 at 06:51

0 Answers0