FTDI Community

General Category => Discussion - Software => Topic started by: bryantsorensen on July 31, 2023, 10:42:16 PM

Title: Multi-byte read fails in I2C_DeviceRead, LibMPSSE_1.0.3 - no NACK by FT2232H
Post by: bryantsorensen on July 31, 2023, 10:42:16 PM
I'm using LibMPSSE_1.0.3 and encountered a problem doing multi-byte reads using I2C_DeviceRead on an FT2232H (FTDI-Click board).  The FT2232H reads the first byte (from an EEPROM) correctly, but shows a NACK.  This causes the following bytes to be read as 0xFF, 0xFF, etc. which also have NACKs.

I'm using the command:

      FtStatus = I2C_DeviceRead(FtHandle, SlaveAddress, sizeof(ReadData), ReadData, &SizeXferred,
                     I2C_TRANSFER_OPTIONS_START_BIT |        // Give repeated start after address write
                     I2C_TRANSFER_OPTIONS_STOP_BIT |
                                I2C_TRANSFER_OPTIONS_FAST_TRANSFER_BYTES );

I also tried:

      FtStatus = I2C_DeviceRead(FtHandle, SlaveAddress, sizeof(ReadData), ReadData, &SizeXferred,
                     I2C_TRANSFER_OPTIONS_START_BIT |        // Give repeated start
                     I2C_TRANSFER_OPTIONS_STOP_BIT |
                     I2C_TRANSFER_OPTIONS_NACK_LAST_BYTE);

This also reads the data back as <correct 1st byte>, 0xFF, 0xFF...

This appears to be related to an older post: http://www.ftdicommunity.com/index.php?topic=241.msg741#msg741

Given the age of the previous post, and that it refers to lib SW which I can no longer find (for example, the poster refers to changing an "if 1" statement to an "if 0" statement on line 1400 of ftdi_i2c.c - and there's no statement anything like that in the latest ftdi_i2c.c), I'm wondering the following:


Thanks,
Bryant (just getting started with FTDI devices, appreciate the help)
Title: Re: Multi-byte read fails in I2C_DeviceRead, LibMPSSE_1.0.3 - no NACK by FT2232H
Post by: bryantsorensen on July 31, 2023, 10:44:17 PM
BTW - this happens at every speed I've tried - 100kHz, 400kHz, 1Mhz.
Title: Re: Multi-byte read fails in I2C_DeviceRead, LibMPSSE_1.0.3 - no NACK by FT2232H
Post by: bryantsorensen on August 02, 2023, 02:13:30 PM
There were 3 errors in the FTDI LibMPSEE.dll source code.

This is library release 1.0.3, in file LibMPSSE_1.0.3.zip found at https://ftdichip.com/software-examples/mpsse-projects/libmpsse-i2c-examples/


1.  See http://www.ftdicommunity.com/index.php?topic=644.0 - post made August 16, 2022, 10:48:47 AM

I2C_Read8bitsAndGiveAck(...) function, in $\LibMPSSE_1.0.3\source\ftdi_i2c.c, around line 941 - change:

Code: [Select]
buffer[noOfBytes++] = DIRECTION_SCLOUT_SDAOUT;  // was DIRECTION_SCLOUT_SDAIN; make SDA output to provide read ACK

2. Related to #1:

I2C_FastRead(...) function, in $\LibMPSSE_1.0.3\source\ftdi_i2c.c, around line 1314 - change:

Code: [Select]
outBuffer[i++] = DIRECTION_SCLOUT_SDAOUT;   // was DIRECTION_SCLOUT_SDAIN; make SDA output to provide read ACK

3. I2C_FastRead(...) returns number of bits read always, not bytes

I2C_FastRead(...) function, in $\LibMPSSE_1.0.3\source\ftdi_i2c.c, around line 1324:

In the released code, it has the statement: 
Code: [Select]
*sizeTransferred = j;where 'j' is the number of bits to be read.  However, this only is correct for option flag I2C_TRANSFER_OPTIONS_FAST_TRANSFER_BITS if the actual bits read match the requested bits to read (this statement may be premature - may be better to wait for actual read), as I read the manual and the code comments.

(A) Put this statement behind something like: 

Code: [Select]
if (options & I2C_TRANSFER_OPTIONS_FAST_TRANSFER_BITS)
(B) Below this code, towards the bottom of the function, there is released code:

Code: [Select]
if (options & I2C_TRANSFER_OPTIONS_FAST_TRANSFER_BYTES)
    status = FT_Channel_Read(I2C, handle, bytesToTransfer, buffer, &bytesRead);

Replace this with something like:

Code: [Select]
if (options & I2C_TRANSFER_OPTIONS_FAST_TRANSFER_BYTES)
{
    status = FT_Channel_Read(I2C, handle, bytesToTransfer, buffer, &bytesRead);
    *sizeTransferred = bytesRead;
}



Title: Re: Multi-byte read fails in I2C_DeviceRead, LibMPSSE_1.0.3 - no NACK by FT2232H
Post by: FTDI Community on August 02, 2023, 03:37:27 PM
Hi,

Thanks for the information. I will pass this on to the developers and raise a bug. It will be fixed in the next release of the library. 

Best regards

FTDI Community
Title: Re: Multi-byte read fails in I2C_DeviceRead, LibMPSSE_1.0.3 - no NACK by FT2232H
Post by: Petrov on August 21, 2023, 09:07:43 PM
Is there any update on this issue?
When can we expect the next release of the library?
Title: Re: Multi-byte read fails in I2C_DeviceRead, LibMPSSE_1.0.3 - no NACK by FT2232H
Post by: FTDI Community on August 22, 2023, 10:34:48 AM
HI Petrov,

We are not sure when the next update for the library will be released, however, as the source code is available on the website, customers can make their own changes and rebuild the library for their own use.

Customers can also develop their own code using D2XX direct driver. You can have a look at Command Processor For MPSSE and MCU Host Bus Emulation Modes (https://ftdichip.com/wp-content/uploads/2020/08/AN_108_Command_Processor_for_MPSSE_and_MCU_Host_Bus_Emulation_Modes.pdf) this will allow you to not rely on LibMPSSE.

Best Regards
FTDI Community 
Title: Re: Multi-byte read fails in I2C_DeviceRead, LibMPSSE_1.0.3 - no NACK by FT2232H
Post by: BigApple on January 08, 2024, 08:23:39 PM
You should fix these bugs.  I just ran into similar issues.