There is a very good device named FT4222H from FTDI Chip which can be used for multi-interfaces like GPIO, I2C, SPI, Interrupt. The nicest thing is you could access all those communication protocols directly using LabVIEW. Generally speaking, if you work with a controlling application where your end-device uses such protocols, you could use this device to communicate with the end-device and make the life easier and design would be low cost too (device costs only $2.30).
- I2C Master
- I2C Slave
- SPI Master
- SPI Slave
Initially I assumed that this device would be straight forward to use for my application which required three of those features viz.. a master I2C, a GPIO and an Interrupt. However, it turned out there are only few documentation about the configuration of this device in the manufacturer end or out there in forums. Eventually it ended-up as empirical (trial-error) method to make the device work for all three interfaces. I have highlighted the key points below which I found in this empirical way that can help in future.
- If this device got registered in a mode when you plug-in to Windows, then the same mode gets detected by Windows even after you change the mode and re-plugin. The device has 4 different modes in which Mode-0 is the one which can support GPIO+Interrupt+I2C simultaneously. Earlier I used it in Mode-3 in which I2C works and in Mode-3 only one interface had installed in Windows. Changing the mode to zero, the driver didn’t get update with two interfaces. I had to manually uninstall the drier in Windows Device Manager to get the M0de-0 interface installed. I will put up the necessary images later here.
Interrupt trigger for the GPIOs are predefined in the UMFT4222EV and it can’t modified. Trying to set that trigger condition led me to wrong direction of debugging it.
- There is an external pull-down resistor required for interrupt pin (as it’s pre-configured for raising edge) in order to detect the next interrupt.
- FTDI has given LabVIEW drivers for D2XX DLL (base interface) for this device, which is a basic one. In order to do the above advanced functions there is different LibFT4222 DLL . And there is no LabVIEW drivers from FTDI for this advanced DLL and I had to write it manually.
- There is an API for enabling/disabling the Suspend and Wake-up/Interrupt modes and the device starts by default in suspend enabled mode and interrupt disabled mode. How to set the device in only-interrupt mode is not straightly documented and the empirical work gave the clue like below table
Suspend Enable Wake-up/Interrupt Enable Eventual Device Configuration TRUE FALSE Device configures in some suspend mode. I’m not sure how the device wake up happens in this mode. TRUE TRUE Device configures in some suspend mode with interrupt for waking up the device. FALSE TRUE Interrupt only mode. This enables the interrupt to be detected in GPIO3 and can be read directly using GPIO Read API FALSE FALSE GPIO only mode. All GPIOs work normally unless the GPIO_0 and GPIO_1 is initialized for I2C/SPI.
- The error codes generated from the DLL is brief and short and debugging using those error codes are quite tricky. Few of the errors I faced and it’s meaning are given below
FT4222_INVALID_HANDLE The handle is a U32 bit number and there are chances that this number might changed during type conversion or coercion FT4222_DEVICE_NOT_FOUND The device is not connected to the PC via USB FT4222_DEVICE_NOT_OPENED APIs of I2C/GPIO are used without Initialization API in the begging of the calls. FT4222_INVALID_PARAMETER If the device is not configured for such operation then you get this error. For eg. If you try to set the trigger condition for the interrupt while you have not set it as FT4222_DEVICE_NOT_OPENED_FOR_WRITE If the GPIO is initialized as Read then you get this error.
Ajay is a professional developer and architect of LabVIEW applications with extreme interest in getting the hardware connected to LabVIEW and automate the stuffs. He is also a good mentor for the various interns in his career. He is ready to help the people in techie roles.