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: What error is returned if an I2C Write/Read times out?  (Read 13932 times)

allenhuffman

  • Newbie
  • *
  • Posts: 49
  • Mostly harmless.
    • View Profile
    • Sub-Etha Software
What error is returned if an I2C Write/Read times out?
« on: August 03, 2023, 02:50:00 PM »

It is my understanding that FT_SetTimeouts() will cause a Read/Write to timeout. How can you tell if this happened? I did not see an obvious return code.

Code: [Select]
ftStatus = FT_SetTimeouts (ftHandle, 5000, 5000);

...

ft4222Status = FT4222_I2CMaster_Read (ftHandle, address, buffer, bufferSize, &sizeTransferred);

In this I2C example, suppose the slave device invoked clock stretching and held it longer than 5000ms. I would expect the Read call to return due to the SetTimeouts.

We sometimes see unexpected FT4222_FAILED_TO_READ_DEVICE errors, so I added code to print any time "bufferSize" and "sizeTransferred" do not match (and did the same in the Master_Write. I am not seeing those print, but I do see the program hang for 5 seconds from time to time, which makes me think it's being stuck in I/O then timing out.

Thanks, much. I am working on a project that uses FTDI I2C to communicate between a host PC and almost 30 boards using a write/read protocol. While it's been proven very solid (I've personally tested it with over 41 million messages with 0 errors), if/when a line glitch does happen, I want to make the master code robust.
« Last Edit: August 03, 2023, 03:33:12 PM by allenhuffman »
Logged

FTDI Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 897
    • View Profile
Re: What error is returned if an I2C Write/Read times out?
« Reply #1 on: August 03, 2023, 04:34:48 PM »

Hello,

When FT_SetTimeouts() is not used, standard d2xx read and write API's would not return as they are blocking calls.

When FT_SetTimeouts() is set to say 5 seconds, that would give plenty time for Read and Write API calls and it would return if there were any issues with the Read or Write.

Best Regards,
FTDI Community
Logged