FTDI Community

General Category => Discussion - Software => Topic started by: petewall on April 25, 2018, 03:25:59 PM

Title: Issue with FT4222 and I2C
Post by: petewall on April 25, 2018, 03:25:59 PM
I am having some trouble communicating with a chip over I2C and I'm wondering if I'm doing something wrong when setting up the FT4222 chip.

Some overview of my circuit, I have the FT4222 chip connected to my computer over USB, and I want to use it to communicate to other chips on circuit over I2C.  The first chip to communicate with is a PCA9570, a four pin GPIO chip, that controls two LEDs and two reset pins for other chips on the board.  Initially, the PCA9570 is high on all four outputs, so my first job is to tell the PCA9570 to set those outputs low.

I'm building the software on Mac OS X 10.13.4, with g++:
Code: [Select]
$ g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.1.0 (clang-902.0.39.1)

Here's an overview of the software:
I find any available chips...
Code: [Select]
FT_CreateDeviceInfoList(&numOfDevices)... connect to the first one...
Code: [Select]
FT_OpenEx(locationId, FT_OPEN_BY_LOCATION, &ftHandle);... Initialize I2C...
Code: [Select]
FT4222_I2CMaster_Init(ftHandle, 400);... and reset I2C.
Code: [Select]
All of these succeed with FT_OK return codes.  A call to FT4222_I2CMaster_GetStatus returns 0x20 (controller idle).

The PCA9570's data sheet (https://www.nxp.com/docs/en/data-sheet/PCA9570.pdf (https://www.nxp.com/docs/en/data-sheet/PCA9570.pdf)) specifies running these commands.  First, I send the general I2C reset (sending 0x06 to 0x00):
Code: [Select]
uint8 buffer = 0x06;
uint16 sizeTransferred;
FT4222_STATUS status = FT4222_I2CMaster_Write(ftHandle, 0x00, &buffer, 1, &sizeTransferred);
This succeeds and another call to FT4222_I2CMaster_GetStatus still returns 0x20 (controller idle).

Now, I send the command to pull all pins low on the GPIO chip:
Code: [Select]
uint8 pins = 0x00;
uint16 sizeTransferred;
FT4222_STATUS status = FT4222_I2CMaster_Write(ftHandle, GPIO_CHIP_ADDR, &pins, 1, &sizeTransferred);

The status for this is still FT_OK, but the LEDs are still on.  Also, the next call to FT4222_I2CMaster_GetStatus returns 0x3e.

So, how can I best debug why my I2C commands are not going through?
Title: Re: Issue with FT4222 and I2C
Post by: FTDI Community on April 25, 2018, 04:19:22 PM

Unfortunately we don't have any particular experience using the PCA9570.

However, we do provide code examples as part of the LibFT4222, so it would be worth taking a look at these:

http://www.ftdichip.com/Products/ICs/FT4222H.html (http://www.ftdichip.com/Products/ICs/FT4222H.html)

There is also a lot of information in LibFT4222 User Guide (http://www.ftdichip.com/Support/Documents/AppNotes/AN_329_User_Guide_for_LibFT4222.pdf) including details of the FT4222_STATUS return codes (Appendix A – Enumeration and Structure Definitions) and FT4222_I2CMaster_GetStatus controllerStatus bit definitions which should help with your debug.

Best Regards,
FTDI Community