How to use FTDI FT4222H in LabVIEW

Home / Blogs / How to use FTDI FT4222H in LabVIEW

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).

Fig. FTDI FT4222H Device Image
  • GPIO
  • Interrupt
  • 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.

  1. 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.
  2. Fig. FTDI FT4222H EVM UMFT4222EV Image

    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.

  3. 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.
  4. 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.
  5. 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.
  6. 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.

12 Comments

  • Dear Ajay
    Glad to contact you.
    We make Vibration Monitors for e.g. Wind Turbines. I work as an Embedded R&D engineer. We use SPI Accelerometers for monitoring of (very low frequency) vibrations in a Wind Turbine. We are a small company of 25 people totally in R&D and the Production Department in Denmark. I use LabVIEW 2016.
    I’m trying to use FT4222H as SPI Slave. I want to be able to stream digital signals from a PC to Monitor. The length of the signal will be e.g. 60 seconds. The FTDI must work as an artificial SPI Accelerometer. The sampling frequency will be 3200 Hz. There must be no “holes” in the signal.
    I have tried to use a library from Ovak Technologies (a trial license – via NI) but I get an license-not-found error message when I run it.
    Question:
    Would you be interested in selling us a working LabVIEW demo application (with or without the Ovak library)?
    Best Regards.
    Knud

    • Ajay

      @B Krishnan Iyer, Unfortunately, this driver mostly is mostly at the LabVIEW surface, I doubt I can clarify your question here. Since this driver does use the FT4222 dll behind the scene, let me give it a shot at your GitHubGist.

  • Ilan

    Which mode i have to work with FTDI as I2C (FTDI is MASTER I2C) to operate the IC FTDI 4222H with LABVIEW 2016 that will make the task fast and work ok.

    • Ajay

      It really depends on hardware and datarate in your design. Ideally, default modes would help to start with then you can move on to tuning it.

  • Bruce

    GPIO Does not appear to work, for any of the pins. Can you please elaborate of the need to uninstall the drivers for Mode changes?

    • Ajay

      Hi Bruce

      – Try going to device manager and find FT4222 under some tree branch. I think it should be under USB.
      – Right click that item and uninstall that item (you might see two items like FT4222-A and FT42222-B, uninstall both).
      – Then change your device to desired GPIO mode physically before connecting USB.
      – Finally connect the USB. Hope this helps

      -AJ

  • Ilan

    Hi Aj,

    I download the code FT4222 I2C from your WEB.
    when i run it in the labview 16 ,windows 16 it is not read the id chip of I2C in index 0 .
    in other index it read some charcters .
    i get the error 5103 -D2xx_Error_decoder.vi.

    what i am missing here?

    thank you.
    Ilan.

    • Ajay

      Hi Ilan

      Please check if you’re using 32-bit LabVIEW as this tool doesn’t support in 64-bit. For further clarifications you can always email me at mail@digiajay.com , it would be easy to debug if the error is seen visually with screenshots.

      Thanks
      Aj

Leave a Reply to Ajay Cancel reply

Your email address will not be published. Required fields are marked *