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

Show Posts

You can view here all posts made by this member. Note that you can only see posts made in areas to which you currently have access.

Messages - allenhuffman

Pages: 1 [2] 3 4
16
Since the bug in the FTDI I2C chip presents using FT4222_I2CMaster_GetStatus() after a write (unless you can wait long enough to know the write has completed), I came up with a workaround.

We blindly write our our message (without knowing if anything saw it and ACK'd it), then we go to read our special protocol.

We read the first two bytes (a start code, and number of data bytes) like this:

Code: [Select]
// Read two bytes (Start Code, Number of Data Bytes).
ft4222Status = FT4222_I2CMaster_ReadEx (ftHandle, deviceAddress, START, buffer, 2, &sizeTransferred);

Initially, I thought we might be able to use GetStatus() hear and see if the READ was ACK'd, but it will return a BUS_BUSY due to the ReadEx being in the middle (no STOP bit yet). At least that's what it looks like -- always BUS_BUSY until I do the second ReadEx.

I do a check like this:

Code: [Select]
// Fake it. Reads from non-responding devices will return FFs.
if ((buffer[0] == 0xff) && (buffer[1] == 0xff))
{
    // Nothing responded, or other issue.
}

...BUT, this means I never got to the second half of the ReadEx that completes it, with the STOP:

Code: [Select]
ft4222Status = FT4222_I2CMaster_ReadEx (ftHandle, deviceAddress, STOP, &buffer[2], messageSize-2, &sizeTransferred);
/code]

How can I just send the "STOP"? I tried this (ReadEx with 0 bytes) and that doesn't do it:

[code]// Fake it. Reads from non-responding devices will return FFs.
if ((buffer[0] == 0xff) && (buffer[1] == 0xff))
{
    // Nothing responded, or other issue.
    FT4222_I2CMaster_ReadEx (ftHandle, deviceAddress, STOP, buffer, 0, &sizeTransferred);
}

Looking at the I2C line in my Saleae analyzer, I see no STOP bit, though the next write/read is still able to happen.

How can I send a STOP without reading data? Is that possible?

17
The feedback from our R&D team is that there is nothing that can be done with the library.

The issue is not related to the driver but the I2C IP.

Adding a delay is the only solution.

FYI to others who find this topic:  Calculating the delay is problematic when the output (under Windows, at least) has inconsistent gaps between each byte. In my testing today, I've seen some as small as 7 uS and as long as 63 uS. (See attachment.)  You really do end up Sleeping way too long to cover "worst case", and even then be sure to error check in case the data corruption does occur.



18
As has been reported elsewhere in this forum...

https://www.ftdicommunity.com/index.php?topic=822

...problems can happen if you try to use FT4222_I2CMaster_GetStatus() after a Write operation if the Write has not completed.

See: https://ftdichip.com/wp-content/uploads/2022/03/TN_161_FT4222H-Errata-Technical-Note.pdf
Section 3.4.2

FT4222_I2CMaster_GetStatus() is used to determine if the I2C write was ACK'd by a device. But, you are told to only use it AFTER transmisson is complete:

Quote
Read the status of the I2C master controller. This can be used to poll a slave after i2c transmission is complete.

One of the GetStatus bits is "BUS BUSY" and it seems you could have used it to determine when a write was complete, but due to the problem in the FTDI chip, you cannot. I suspect something like this was the intent:

Code: [Select]
// This WILL NOT WORK. See:
//
// TTN_161 FT422H Errate Technical Note
// Version 1.5
// Document Reference No.: FT_001198
//
// Section 3.4.2
// 'I2C data is corrupt when FT4222_I2CMaster_GetStatus" is being called'
//

// Write message.
ft4222Status = FT4222_I2CMaster_Write(ftHandle, deviceAddress,
&msg[0], sizeof(msg), &sizeTransferred);

if (ft4222Status == FT4222_OK)
{
// Wait for it to be sent so we can check status.
unsigned char controllerStatus;
NAKSeen = false;

// Deadlock prevention. Try up to 10 times...
for (int tries = 0; tries < 10; tries++)
{
ft4222Status = FT4222_I2CMaster_GetStatus (ftHandle,
&controllerStatus);

if (ft4222Status == FT4222_OK) // We have a status.
{
// If CONTROLLER BUSY, no status bits are valid.
if (I2CM_CONTROLLER_BUSY(controllerStatus)==1)
{
// controller busy: all other status bits invalid
continue;
}

// If here, status bits are valid.

// If BUS BUSY, we are still writing.
if (I2CM_BUS_BUSY(controllerStatus))
{
continue;
}

// Check to see if ADDR was ACK'd.
if (I2CM_ADDRESS_NACK(controllerStatus))
{
NAKSeen = true;
}
// If here, we were NACK'd or ACK'd.
break;
}
else // ft4222Status NOT OK
{
// Considered.
}
} // end of for.

if (NAKSeen == true)
{
printf ("NAK\n");

// Handle...
}
else // ACK'd
{
// Write was okay.
printf ("Wrote %u bytes.\n", sizeTransferred);

// Handle...

} // end of if (NAKSeen == true) else

} // end of if (ft4222Status == FT4222_OK)

If FTDI releases a fixed chip in the future, that code could be enhanced to check for other error conditions as well.

Currently, if you want to use it to see if your write was received (ACK), you have to wait until transmission is complete then use GetStatus. For casual hobby projects, it may be fine to just blindly write to non-existent (or locked up) devices, but if the project is important knowing is a device is present (and has received the message) may be required.

Since FT4222_I2CMaster_Write() is non-blocking, the call returns immediately, and the write is handled in the background. This means if you do a Write and follow it with a GetStatus, problems may occur. The above-linked post demonstrates data corruption as one such problem.

I am not sure what happens if you try doing a Write while a previous Write is still in progress, but I *assume* it may also be bad. It is unfortunate this defect exists.

FTDI Workaround

The FTDI response is to wait before calling GetStatus, so I thought I'd provide details in one post (which I will edit with corrections/updates if needed) for others who have run in to this.

The delay can be calculated by knowing the baud rate -- the kbps used in FT4222_I2CMaster_Init() -- and the number of bytes written.

Keep in mind that each byte has an ACK/NAK bit added, so calculate 9 bits per byte rather than 8.

Also, if you look at the output of the I2C write under a logic analyzer (such as a Saleae), you will see there are also gaps between bytes (see attached screenshot). These gaps are not consistent. In my example, I see sending a byte took about 10 uS, with a gap afterwards that ranged from 7 uS to more than 60 uS.

To use the following workaround, you need to use a worst-case "gap time" and add it to the calculation. I am unsure. I am going to *assume* that this gap time can vary -- on a busy Windows machine I expect they could be much larger in time.

Calculating

The FTDI part can operate from 60 kbps to 3400 kbps. Since the Sleep resolution may be limited to milliseconds, a Sleep(1) is the minimal time. This may be long enough to cover writing 128 bytes of I2C data at high baud rates (1000 or faster). But, at slower speeds, you will see the calculated write time needs to be much longer. Just doing a Sleep(1) is not enough if you plan to use a lower baud rate.

The wait time formula is basically something like:"

Code: [Select]
ms = (9 * (1000/(kbps)) * (sizeTransferred+1)) / 1000;
The 9 is for the 9 clock pulses to send a byte (8 pulses for the 8 bits, plus 1 pulse for ack/nak).

The sizeTransferred (bytes sent) has 1 added to it to round up.

Unfortunately, this does not take in to consideration the gaps between bytes.  If I knew that it took 10 uS to send a byte, and then there was a 7 uS gap after, I could tweak this time by adding extra bits. Say, 7 bits of overhead (worth of time):  "(9+7) * ..."

BUT, since I see that sometimes the gap might be closer to 70 uS (7 times as long as it took to send the byte), I might just want to use "9" there, and multiply the "sizeTransferred" by 7. Worst case.

This produces much longer waits than are needing, slowing down the I2C system considerably. But, if you really need to use GetStatus, this may be the only option.

Here is a C program to print out an example table. You can see the formula I was using added 6 extra bits, but I have since found this is not long enough:

Code: [Select]
#include <stdio.h>  // for printf
#include <stdint.h> // for uint16_t
#include <stdlib.h> // for EXIT_SUCCESS

// Table of I2C baud rates.
uint16_t kbps[] = { 60, 100, 300, 500, 1000, 3400 };

int main()
{
    // Print header.
    printf ("bytes  ");

    for (int idx=0; idx<sizeof(kbps)/sizeof(kbps[0]); idx++)
    {
        printf ("%4u  ", kbps[idx]);
    }
    printf ("\n");

    // Print table entries.
    for (uint16_t sizeTransferred=0; sizeTransferred<=128; sizeTransferred++)
    {
        printf ("%5u  ", sizeTransferred); // Bytes written.

        for (int speed=0; speed<sizeof(kbps)/sizeof(kbps[0]); speed++)
        {
            // "Since there is a separate byte for the address, and since
    // there are 9 pulses for each byte (ack/nak bit), a formula
    // probably needs to take that in to consideration."
    //
    // "When looking at the FTDI Master (Windows 11) in a Saleae capture,
    // I also see gaps between each byte that range from 10us to 14us, so
    // I added some worst-case extra bits (6 for my case) to that to cover
    // it:"
    //
    //             (bits ) * (         uS       ) * (      bytes      )
        uint32_t ms = ((8+1+6) * (1000/(kbps[speed])) * (sizeTransferred+1)) / 1000;
        if (ms < 1)
        {
        ms = 1;
        }

            printf ("%4u  ", ms);
        }
        printf ("\n");
    }

    return EXIT_SUCCESS;
}

And here is the output:

Code: [Select]
bytes    60   100   300   500  1000  3400
    0     1     1     1     1     1     1
    1     1     1     1     1     1     1
    2     1     1     1     1     1     1
    3     1     1     1     1     1     1
    4     1     1     1     1     1     1
    5     1     1     1     1     1     1
    6     1     1     1     1     1     1
    7     1     1     1     1     1     1
    8     2     1     1     1     1     1
    9     2     1     1     1     1     1
   10     2     1     1     1     1     1
   11     2     1     1     1     1     1
   12     3     1     1     1     1     1
   13     3     2     1     1     1     1
   14     3     2     1     1     1     1
   15     3     2     1     1     1     1
   16     4     2     1     1     1     1
   17     4     2     1     1     1     1
   18     4     2     1     1     1     1
   19     4     3     1     1     1     1
   20     5     3     1     1     1     1
   21     5     3     1     1     1     1
   22     5     3     1     1     1     1
   23     5     3     1     1     1     1
   24     6     3     1     1     1     1
   25     6     3     1     1     1     1
   26     6     4     1     1     1     1
   27     6     4     1     1     1     1
   28     6     4     1     1     1     1
   29     7     4     1     1     1     1
   30     7     4     1     1     1     1
   31     7     4     1     1     1     1
   32     7     4     1     1     1     1
   33     8     5     1     1     1     1
   34     8     5     1     1     1     1
   35     8     5     1     1     1     1
   36     8     5     1     1     1     1
   37     9     5     1     1     1     1
   38     9     5     1     1     1     1
   39     9     6     1     1     1     1
   40     9     6     1     1     1     1
   41    10     6     1     1     1     1
   42    10     6     1     1     1     1
   43    10     6     1     1     1     1
   44    10     6     2     1     1     1
   45    11     6     2     1     1     1
   46    11     7     2     1     1     1
   47    11     7     2     1     1     1
   48    11     7     2     1     1     1
   49    12     7     2     1     1     1
   50    12     7     2     1     1     1
   51    12     7     2     1     1     1
   52    12     7     2     1     1     1
   53    12     8     2     1     1     1
   54    13     8     2     1     1     1
   55    13     8     2     1     1     1
   56    13     8     2     1     1     1
   57    13     8     2     1     1     1
   58    14     8     2     1     1     1
   59    14     9     2     1     1     1
   60    14     9     2     1     1     1
   61    14     9     2     1     1     1
   62    15     9     2     1     1     1
   63    15     9     2     1     1     1
   64    15     9     2     1     1     1
   65    15     9     2     1     1     1
   66    16    10     3     2     1     1
   67    16    10     3     2     1     1
   68    16    10     3     2     1     1
   69    16    10     3     2     1     1
   70    17    10     3     2     1     1
   71    17    10     3     2     1     1
   72    17    10     3     2     1     1
   73    17    11     3     2     1     1
   74    18    11     3     2     1     1
   75    18    11     3     2     1     1
   76    18    11     3     2     1     1
   77    18    11     3     2     1     1
   78    18    11     3     2     1     1
   79    19    12     3     2     1     1
   80    19    12     3     2     1     1
   81    19    12     3     2     1     1
   82    19    12     3     2     1     1
   83    20    12     3     2     1     1
   84    20    12     3     2     1     1
   85    20    12     3     2     1     1
   86    20    13     3     2     1     1
   87    21    13     3     2     1     1
   88    21    13     4     2     1     1
   89    21    13     4     2     1     1
   90    21    13     4     2     1     1
   91    22    13     4     2     1     1
   92    22    13     4     2     1     1
   93    22    14     4     2     1     1
   94    22    14     4     2     1     1
   95    23    14     4     2     1     1
   96    23    14     4     2     1     1
   97    23    14     4     2     1     1
   98    23    14     4     2     1     1
   99    24    15     4     3     1     1
  100    24    15     4     3     1     1
  101    24    15     4     3     1     1
  102    24    15     4     3     1     1
  103    24    15     4     3     1     1
  104    25    15     4     3     1     1
  105    25    15     4     3     1     1
  106    25    16     4     3     1     1
  107    25    16     4     3     1     1
  108    26    16     4     3     1     1
  109    26    16     4     3     1     1
  110    26    16     4     3     1     1
  111    26    16     5     3     1     1
  112    27    16     5     3     1     1
  113    27    17     5     3     1     1
  114    27    17     5     3     1     1
  115    27    17     5     3     1     1
  116    28    17     5     3     1     1
  117    28    17     5     3     1     1
  118    28    17     5     3     1     1
  119    28    18     5     3     1     1
  120    29    18     5     3     1     1
  121    29    18     5     3     1     1
  122    29    18     5     3     1     1
  123    29    18     5     3     1     1
  124    30    18     5     3     1     1
  125    30    18     5     3     1     1
  126    30    19     5     3     1     1
  127    30    19     5     3     1     1
  128    30    19     5     3     1     1

You will see that at the lowest baud rate, writing out 128 bytes is calculated to take around 30 ms. If you actually test this in a logic analyzer, you will see it's not very accurate. See my second screen shot and you will see that when writing 128 bytes, the gaps between the bytes vary - some are 7 uS, some are 13 uS, some are 51 uS (!), even 63 uS. There is overhead on the Windows system and other things are happening.

My table claims that 128 bytes at 1000 kbps should need a 1ms delay. BUT, when I actually look at the time it took, it was OVER 3ms. I was off by a factor of 3! Using my formula to calculate wait time could have led to reading corrupt data (per the poster in the other topic).

Because of this, the formula I was using will not work. As far as I know, currently, you just have to make sure you always wait a worst-worst case amount of time before trying to use GetStatus. And since I don't know how fast the PC will be that runs my I2C code, whatever timing I come up with may not be long enough.

That's the problem.

Ever since we tried to implement ACK/NAK detection (probing for devices), we've had occasional problems, and it seems this is the culprit.

I hope this information helps others who run in to this. What we really need is a way to determine if a Write is busy, but at least when I asked last year, the only option was "Sleep". But...how long?

Cheers!


19
Hello,
Here is some information that should help you:

Thank you for this. I am about to do some updating to our I2C code and decided to look and see what new information I could find. I missed this reply when it was added last November. Good tips.

20
Discussion - Software / Re: I2C Master Read in multiple read requests.
« on: November 14, 2022, 08:03:16 PM »
Update: I have done tests, and verified under a Saleae logic analyzer, that this does work. There's just a huge gap between the reads on my Windows system.

Without full error checking (because this is bad code you shouldn't use for production):

Code: [Select]
uint8_t buffer[128];
memset (buffer, 0x0, sizeof(buffer));

ft4222Status = FT4222_I2CMaster_ReadEx (ftHandle, UNIVERSAL_BOARD_ADDRESS, START, &buffer[0], 2, &sizeTransferred);

if (ft4222Status == FT4222_OK)
{
    uint16_t numDataBytes = 0;

    printf ("Read %d bytes.\n", sizeTransferred);

    // buffer[0] is our Start Code, and we'd error check that here.

    // buffer[1] is the number of data bytes in our payload (if any)

    numDataBytes = buffer[1];

    printf ("Repsonse num data bytes %d.\n", numDataBytes);

    ft4222Status = FT4222_I2CMaster_ReadEx (ftHandle, UNIVERSAL_BOARD_ADDRESS, STOP, &buffer[2], 3+numDataBytes+2, &sizeTransferred);

In our case, our message format is a 5-byte header (starting with a Star Code, # of PayLoad Data Byters, and three other items), then payload bytes (if any), then a 2-byte CRC.

In testing, we took out all error checking and just did the two reads back to back.  This works, but will have a 150uS-300uS gap between reading the first two bytes and reading the rest, due to overhead of Windows and such. We haven't benchmarked it under Linux yet, but that's on the list.

Hope this helps others.

21
Discussion - Software / I2C Master Read in multiple read requests.
« on: November 14, 2022, 05:27:55 PM »
UPDATE: Next post has confirmation this works, with a Saleae capture showing the start and stop bits are handled properly.

We use a custom protocol over I2C that embeds message length in our messages. In our PIC24 firmware, we have one board that will read the first two bytes (to get our protocol start code, and the number of data bytes in the message) and then it will read only the expected number of bytes. (Our actual protocol does more - having CRC and other things we validate, but I am simplyfing it here for example and removing most error checking.)

Code: [Select]
i2c_start (I2C_SUBNET_BUS);

i2c_write (I2C_SUBNET_BUS, I2CSlaveAddress + 1);

// Read the message on the I2C bus.
startCode = i2c_read (I2C_SUBNET_BUS, 1); // Start Code

numDataBytes = i2c_read (I2C_SUBNET_BUS, 1); // Num Data Bytes

for (int idx = 0; idx<(numDataBytes-1); idx++)
{
    RXBuffer[idx] = i2c_read (I2C_SUBNET_BUS, 1);
}

// Read the last byte, but don't ACK.
RXBuffer[idx] = i2c_read (I2C_SUBNET_BUS, ZERO);

i2c_stop (I2C_SUBNET_BUS);

Our system is fairly complex with as many as 27 different boards in communication over I2C.

On our FTDI Windows host program side, we hard code the expected response message size. We do something like:

Code: [Select]
FT4222_I2CMaster_Write(ftHandle, slaveAddress, buffer, bytesToWrite, &sizeTransferred);
...
FT4222_I2CMaster_Read(ftHandle, slaveAddress, responseBufferPtr, ExpectedResponseSizeForThatMessage, &sizeTransferred);

This is fine, but if we are writing something that has a large message expected, and there is a problem, the slave board will return a NACK message (7 bytes in our case) and the Master reads that and keeps reading up to the expected size.

No big deal, since our firmware zeros out the response buffer so if the Master reads 10 bytes at any time, it just gets back 10 0s.

BUT, I wanted to make our messages more flexible and maybe speeds things up. It looks like I could recreate what I want using ReadEx(), since I see:

Quote
The I2C condition will be sent with this I2C transaction
 START = 0x02
 Repeated_START = 0x03
 Repeated_START will not send master code in HS mode
 STOP = 0x04
 START_AND_STOP = 0x06

It looks like I would do a ReadEx of 2 bytes, with the flag set to START, then I can error check our start code (byte 0) and number of data bytes (byte 1) and then issue a ReadEx of that many bytes with flag set to Repeated_Start (for one less byte) then read the final byte using STOP.

I thought I'd ask if this was worth trying, or if there was a better way. Perhaps the driver handles doing a read with just STOP and I can save a step.

I plan to experiment on this before the end of the year, but thought I'd ask in case I couldn't even do this.

Thanks, much.



22
Sorry to bump such an old topic, but we'd still like to find examples of how to properly detect and recover from an I2C bus lock. There was an API call added that does appear to send the clock pulses, but we haven't found any examples of what process to follow to shut down/recover when issues happen.

23
Hello,

This will be included in the LibFT422 release notes in future releases.

I will also check if anything can be done in the driver or library to help improve this.

Best Regards,
FTDI Community

Thank you. A simple blocking option (don't return until all bytes have been sent) would be great.

24
Since there is a separate byte for the address, and since there are 9 pulses for each byte (ack/nak bit), a formula probably needs to take that in to consideration. Something like:

Code: [Select]
#define I2C_KHZ 400

ms = ((8+1) /*bits*/ * (1000/(I2C_KHZ)) /*us*/ * (bytesTransferred+1)) / 1000;

if (ms < 1) ms = 1;

Sleep (ms);

When looking at the FTDI Master (Windows 11) in a Salae capture, I also see gaps between each byte that range from 10us to 14us, so I added some worst-case extra bits (6 for my case) to that to cover it:

ms = ((8+1+6) ....etc...

I am not sure what the FTDI driver does that causes those gaps, but I expect the reason they vary in length is due to Windows not being a realtime OS.  Perhaps the gaps are even larger when using more CPU time or running more stuff.  That would throw all these calculations off.

There really should be a way to query the driver and find out if it's done writing.

25
Thank you for the reply. Please consider to update the wording in the errata sheet and mention the affected libFT4222 APIs explicitly.

Having just ran in to this on our project, yes, please.

26
Discussion - Software / msvcp100.dll and msvcr100.dll dependencies?
« on: March 29, 2022, 03:04:51 PM »
We have a large LabWindows program and the only external component it uses is the FTDI drivers:

ftd2xx.lib
LibFT4222-64.lib and LibFT4222-64.dll

When we first ran it under Windows 10 LTSC, it complained about missing msvcp100.dll and msvcr100.dll. These come from the Visual C++ 2010 redistributable. These files are included with Windows 10, but are not part of LTSC and have to be installed separately.

Are these FTDI files what is needing them? A simple LabWindows U.I. program that does not use the FTDI code seems to work.

It appears the dependency is either in the FTDI software, or some library item that LabWindows is pulling in for our product (FTDI is the only component we use that is not built-in to LabWindows).

Hopefully someone can confirm whether or not these DLLs are used by FTDI. That would greatly help me know where to focus my research in to this issue.

Thanks, much!

27
Discussion - Software / Re: FT260 - Pauses in I2C comunication.
« on: August 26, 2021, 08:28:50 PM »
This may not help, but...

Using the FT4222, we noticed timing gaps between groups of data (I seem to recall odd spacing every 3 bytes).

Somewhere (support? random internet searching?) we were told to look at the SetClock speed and set it to SYS_CLK_24.

FT4222_SetClock (ftHandle, clock);

I do not know if this changed anything.

28
We make use of LibFT4222.dll for I2C Master communication on a Windows PC.

I would like to make our error detection much more robust. For example, I want to be able to detect issues such as:
  • USB cable disconnected.
  • I2C bus lock up.
  • ? ? ?
I get back an FT4222_STATUS from all read/write operations, but I am not real sure which errors are "best practice" to try to detect and handle.  I expect we can put in things like:

If we think I2C bus is locked, try an FT4222_I2CMaster_ResetBus().

If we think the USB connection is bad, un-init, close and try to re-open and init.

Library functions such as FT_CyclePort() may also be useful.

Could someone point me to some documention on "best practices" for a robust I2C system?

Thanks, much.

29
We use Windows and the FT4222 driver to talk to a variety of boards over I2C. Over the years, we have seen many issues with I2C bus locks and have tried to mitigate them in software/firmware.

I thought I'd ask here if folks had any elegant solutions for detecting an I2C bus lock and attempting recovery.

The last release of the library (1.4.4) added FT4222_I2CMaster_ResetBus(); and finally allowed sending the 9 clock pulses to try to unstick a stuck I2C slave device. Before this function was added, we tried doing it manually but found you could not access the GPIO pins when in I2C mode.

I believe we may have been able to just uninitialized from I2C and initialize in GPIO mode to do this:

Code: [Select]
FT_HANDLE ftHandle = NULL;

ftStatus = FT_OpenEx ("PrecisePower B", FT_OPEN_BY_DESCRIPTION,
                      &ftHandle);

if (ftStatus == FT_OK)
{
     GPIO_Dir gpioDir[4] = { GPIO_OUTPUT, GPIO_OUTPUT, GPIO_OUTPUT, GPIO_OUTPUT };
     
     ft4222Status = FT4222_GPIO_Init(ftHandle, gpioDir);

     //disable suspend out , enable gpio 2
     ft4222Status = FT4222_SetSuspendOut(ftdiInfoPtr->ftHandle, false);
     
     //disable interrupt , enable gpio 3
     ft4222Status = FT4222_SetWakeUpInterrupt(ftdiInfoPtr->ftHandle, false);
     
     // set gpio0/gpio1/gpio2/gpio3 output level high
     for (int pulse=0; pulse<9; pulse++)
     {
        ft4222Status = FT4222_GPIO_Write(ftHandle, GPIO_PORT0, 1); // Clock pin
        ft4222Status = FT4222_GPIO_Write(ftHandle, GPIO_PORT0, 0); // Clock pin
     }
     Sleep (1);
     
     FT4222_UnInitialize(ftHandle);

    // Re-init as I2C and use it...           
}
FT_Close (ftHandle);

(Untested; not sure the timing from within Windows toggling that pin on/off would do the trick.)

I wondered if anyone had any clever ways of detecting an I2C stuck bus condition (like when a slave device is using clock stretching, and the master doesn't do a read).

I'll do another post about our experiments with ACK/NACK.

Cheers.

30
During some early testing, I noticed that Write worked even if nothing was on the other side (no address ACK). Today, I am doing the write, and if it returns OK, I am checking controller status looking to see if the write was acknowledged.

But, I also saw the errata saying reading that register while a write was in progress could corrupt data.

Pages: 1 [2] 3 4