FTDI Community

Please login or register.

Login with username, password and session length.
Advanced Search  

News:

Welcome to the FTDI Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ FTDI Support


New Bridgetek Community is now open

Please note that we have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Author Topic: LibMPSSE-I2C : FT2232H is not sending ACK  (Read 508 times)

Tycoon

  • Newbie
  • *
  • Posts: 2
    • View Profile
LibMPSSE-I2C : FT2232H is not sending ACK
« on: June 07, 2019, 08:47:10 AM »

Hello,

I'm trying to use LibMPSSE-I2C to communicate between an FT2232H (in a FTDI Click board) and MCP23017 and MCP3426.

Almost everything runs fine, including opening the channels and writing, but I have some issue with the I2C_DeviceRead function : it doesn't seem to send ACK after every byte the device sends. It's not an issue with the MCP23017 as the device sends only one byte at a time, but with the MCP3426 it's more problematic : the device sends back 3 bytes, but because it doesn't receive an ACK from the FT2232H after the first byte, it just stops the transfer.

Here's what it looks like under the oscilloscope :



I numbered the bits. Every nine bits, I've written an 'X' where either the FT2232H or the device is supposed to ACK. The first 'X' is correctly ACKed by the device, but the second 'X' is not ACKed by the FT2232H, causing the MCP3426 to stop the transfer. In the end, I get the first byte (which I assume is correct), but the two remaining bytes ends up being 0xFF which is incorrect.

Here's the DeviceRead I tried:

Code: [Select]
int err = I2C_DeviceWrite(i2cChannel->handle, address, size, payload, byte_transfered, I2C_TRANSFER_OPTIONS_START_BIT | I2C_TRANSFER_OPTIONS_STOP_BIT | I2C_TRANSFER_OPTIONS_FAST_TRANSFER_BYTES);
Code: [Select]
int err = I2C_DeviceWrite(i2cChannel->handle, address, size, payload, byte_transfered, I2C_TRANSFER_OPTIONS_START_BIT | I2C_TRANSFER_OPTIONS_STOP_BIT);
Code: [Select]
int err = I2C_DeviceWrite(i2cChannel->handle, address, size, payload, byte_transfered, I2C_TRANSFER_OPTIONS_START_BIT | I2C_TRANSFER_OPTIONS_STOP_BIT | I2C_TRANSFER_OPTIONS_NACK_LAST_BYTE);
Neither of them makes the FT2232H ACK.

Any idea where the problem could be ? Is it even a software problem ? On the hardware level, both SDA and SCL are pulled-up to the 3.3V (actually more like 3V but eh) with 4.7K resistors.

Thanks a lot !
Logged

Tycoon

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: LibMPSSE-I2C : FT2232H is not sending ACK
« Reply #1 on: June 20, 2019, 08:39:53 AM »

Hello !

I finally found a workaround ! For posteriority, I'll explain what I did to obtain the correct behavior.

It was indeed a software problem, in particular the problem seems to come from the LibMPSSE-I2C library. Basically, you need to recompile the lib after activating a workaround in the source code. It seems some guy named Grahal had the same issue and submitted a fix. The issue has to do with an SCL glitch, but I'll admit I'm not sure of the detail.

So, once you have download the source files of the library, open the ftdi_i2c.c file in the TopLayer folder. On line 1400, disable the proposition 2 by replacing the
Code: [Select]
if 1 with
Code: [Select]
if 0 Just below that, on line 1412, enable the proposition 3 by replacing the
Code: [Select]
if 0 with
Code: [Select]
if 1
Alternatively, you can activate the proposition 1 on line 1378 instead, it actually seems to work better for me.

Note that this fixes the FastRead function, so I'm not sure it'll fix the issue if you don't use
Code: [Select]
I2C_TRANSFER_OPTIONS_FAST_TRANSFER_BYTES
Recompile the project, and it should now work. If you use GCC, there's a build folder with a makefile and a script. If you use MSVC, there's some changes to do before it will compile :

  • In ftdi_infra.c, comment out every declaration and definition of my_init and my_exit
  • In ftdi_infra.h, replace the likely(x) and unlikely(x) macro so that they don't do anything because __builtin_expect doesn't exist in MSVC

Finally, place yourself in the LibMPSSE folder and compile using
Code: [Select]
cl /LD /I../External/Windows/CDM /ICommon/inc /IInfra/inc /IMiddleLayer/inc /ITopLayer/I2C/inc Common/src/ftdi_common.c Infra/src/ftdi_infra.c MiddleLayer/src/ftdi_mid.c TopLayer/I2C/src/ftdi_i2c.c /FeLibMPSSE-I2C.dll or similar to create the shared library.

Maybe it'll help other people !

Cheers
« Last Edit: June 20, 2019, 08:58:21 AM by Tycoon »
Logged

FTDI Community

  • Administrator
  • Sr. Member
  • *****
  • Posts: 335
    • View Profile
Re: LibMPSSE-I2C : FT2232H is not sending ACK
« Reply #2 on: June 20, 2019, 11:54:50 AM »

Hello,

Thanks for sending a follow up to your question explaining the workaround, I'm sure this will be a good resource for the Community.

Many thanks,
FTDI Community
Logged