Do you have a question about the LibFT4222 and is the answer not in the manual?
Questions and answers
Subscribe to Our Youtube Channel
Summary of Contents for FTDI LibFT4222
Page 1
The application note is a guide for LibFT4222 based on D2XX. It provides high-level and convenient APIs for FT4222H application development. Use of FTDI devices in life support and/or safety applications is entirely at the user’s risk, and the user agrees to defend, indemnify and hold FTDI harmless from any and all damages, claims, suits or expense resulting from such use.
FTDI FT4222H chip Figure 1.1 The Software Stack Note that the Window, Linux and MAC OS version of LibFT4222 have D2XX and mini-boost built-in. The LibFT4222 sample code, release notes, and all necessary files can be downloaded from the FTDI website at: https://www.ftdichip.com/Products/ICs/FT4222H.html...
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 1.1 Overview The FT4222H supports 4 operation modes to allow various I C/SPI devices to be connected to USB bus. The attachable device configuration for each mode is listed below: ...
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Figure 1.2 Mode 0: FT4222H works as SPI master (Quad Mode) Figure 1.3 Mode 0: FT4222H works as I C Master Product Page Document Feedback...
Document Reference No.: FT_001060 Clearance No.: FTDI#406 Figure 1.4 Mode 2: FT4222H works as SPI Master 1.2 Scope The guide is intended for developers who are creating applications, extending FTDI provided applications or implementing FTDI’s applications for the FT4222H. Product Page Document Feedback...
Document Reference No.: FT_001060 Clearance No.: FTDI#406 2 Getting Started A LibFT4222 application usually starts with FT_CreateDeviceInfoList and FT_GetDeviceInfoList as a traditional D2XX application does. Under different chip modes, FT_CreateDeviceInfoList reports a different number of interfaces as shown in the table below.
The functions listed in this section are system-wise configuration functions. 3.2.1 Open and Close An application of LibFT4222 should open the device and get a handle for subsequent accesses by calling FT_Open or FT_OpenEx. Both are D2XX API. Please refer to the D2XX Programmers Guide for more details.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 FT4222 chip version Supported FT4222 Rev A FT4222 Rev B FT4222 Rev C FT4222 Rev D Summary: Release allocated resources. FT4222_Uninitialize should be called before calling FT_Close.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 FT4222 Rev B FT4222 Rev C FT4222 Rev D Summary: Set the system clock rate. The FT4222H supports 4 clock rates: 80MHz, 60MHz, 48MHz, or 24MHz.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Summary: Get the current system clock rate. Parameters: ftHandle Handle of the device. pClk Pointer to a variable of type FT4222_ClockRate where the value will be stored.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 The default value of suspend-out polarity is active high. It means suspend-out pin output low in normal mode and output high in suspend mode. Suspend-out polarity only can be adjusted by FT_PROG.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 GPIO3 acts as a wakeup pin. An example is provided with the support-lib. The file is located in the following path: example\samples\interrupt\interrupt.cpp Parameters: ftHandle Handle of the device.
Page 17
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Parameters: ftHandle Handle of the device. trigger Trigger condition. One of the following: GPIO_TRIGGER_RISING GPIO_TRIGGER_FALLING GPIO_TRIGGER_LEVEL_HIGH GPIO_TRIGGER_LEVEL_LOW Return Value: FT4222_OK if successful, otherwise the return value is an FT error code.
Page 18
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 BOOL value; WaitForSingleObject(hRxEvent,INFINITE); // FT4222_GPIO_Read is a read clear function for interrupt if(FT4222_GPIO_Read(ftHandle, (GPIO_Port)GPIO_PORT3, &value) == FT4222_OK) if(value == TRUE) // got interrupt else // no interrupt FT4222_UnInitialize(ftHandle);...
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 FT4222_UnInitialize(ftHandle); FT_Close(ftHandle); 3.2.8 Get Max Transfer Size FT4222_STATUS FT4222_GetMaxTransferSize(FT_HANDLE ftHandle, uint16* pMaxSize) Supported Chip: FT4222 chip version Supported FT4222 Rev A FT4222 Rev B...
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 HANDLE hRxEvent; ftStatus = FT_Open(0, &ftHandle); if (FT_OK != ftStatus) // open failed return; ft4222Status = FT4222_SPISlave_InitEx(ftHandle, SPI_SLAVE_NO_ACK); if (FT4222_OK != ft4222Status) // init spi slave failed return;...
Page 22
Revision C chips report chipVersion as 0x42220300. Revision D chips report chipVersion as 0x42220400. Revision B chips require version 1.2 or later of LibFT4222, indicated by dllVersion being greater than 0x01020000; Revision C chips require version 1.3 or later of LibFT4222, indicated by dllVersion being greater than 0x01030000;...
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 3.2.11 Chip Reset FT4222_STATUS FT4222_ChipReset(FT_HANDLE ftHandle) Supported Chip: FT4222 chip version Supported FT4222 Rev A FT4222 Rev B FT4222 Rev C FT4222 Rev D Summary: Software reset for device.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 DUAL SPI Transfer/Receive - Data is transferred out or received in on 2 SPI lines simultaneously QUAD SPI Transfer/Receive – Data is transferred out or received in on 4 SPI lines...
Page 25
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 SPI_IO_QUAD clock_div Clock divider: CLK_DIV_2 (1/2 System Clock) CLK_DIV_4 (1/4 System Clock) CLK_DIV_8 (1/8 System Clock) CLK_DIV_16 (1/16 System Clock) ...
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Parameters: ftHandle Handle of the device. spiMode SPI mode could be: SPI_IO_SINGLE SPI_IO_DUAL SPI_IO_QUAD Return Value: FT4222_OK if successful, otherwise the return value is an FT error code.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 isEndTransaction If TRUE the Slave Select pin will be raised at the end of the write. Return Value: FT4222_OK if successful, otherwise the return value is an FT error code.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Supported Chip: FT4222 chip version Supported FT4222 Rev A FT4222 Rev B FT4222 Rev C FT4222 Rev D Summary: Under SPI single mode, full-duplex write data to and read data from an SPI slave.
Page 31
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 FT4222_SPIMaster_init Example: // This example is for mxic flash to read out RDSR(read status register) // bit0 (WIP: write in progress bit). When WIP bit sets to 1, which means the device is //busy in program/erase/write status register progress FT_HANDLE ftHandle = NULL;...
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Figure 3.3 Quad SPI communication Parameters: ftHandle Handle of the device. readBuffer Pointer to the buffer that receives the data from the device. writeBuffer Pointer to the buffer that contains the data to be written to the device.
SPI Master. SPI_SLAVE_WITH_PROTOCOL The FT4222H and LibFT4222 design have implemented an SPI slave protocol which must be used to handle the integrity of data transmission. The API “FT4222_SPISlave_Init” is used to initialize the slave with this mode.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Figure 3.5 SPI Master Transfer Request Here is an example of an ACK packet. The SN field of the ACK packet identifies which request it corresponds to.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 The encapsulation of header is done by support-lib. Figure 3.8 Slave sends transfer request SPI_SLAVE_NO_ACK This option is to reduce the complication of SPI_SLAVE_WITH PROTOCOL.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Supported Chip: FT4222 chip version Supported FT4222 Rev A FT4222 Rev B FT4222 Rev C FT4222 Rev D Summary: Initialize the FT4222H as an SPI slave. Default SPI_SlaveProtocol is SPI_SLAVE_WITH_PROTOCOL.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Error code: FT4222_DEVICE_NOT_SUPPORTED: This device is not a FT4222 chip. 3.4.3 SPI Slave Set mode function FT4222_STATUS FT4222_SPISlave_SetMode(FT_HANDLE ftHandle ,FT4222_SPICPOL cpol, FT4222_SPICPHA cpha) Supported Chip:...
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 // init spi slave failed return; // set spi cpol and cpha to mode 3 if (FT4222_OK != FT4222_SPISlave_SetMode(ftHandle, CLK_IDLE_HIGH, CLK_TRAILING)) // set spi mode failed return;...
Page 41
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Supported Chip: FT4222 chip version Supported FT4222 Rev A FT4222 Rev B FT4222 Rev C FT4222 Rev D Summary: Read data from the receive queue of the SPI slave device.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Rule 2: SPI slave device receives USB maximum bulk size in specific time. The device returns full packet data. Rule 3: The option only takes effect when FT4222_SPISlave_RxQuickResponse is on.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Parameters: ftHandle Handle of the device. spiIdx The index of the SPI transaction, which ranges from 0~3 depending on the mode of the chip. For example, under mode 0 and mode 3 as we mentioned in chapter 1.1, it should be 0 because there is only one SPI master or slave connection, and...
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Summary: Reset the SPI master or slave device. If the SPI bus encounters errors or works abnormally, this function will reset the SPI device. It is not necessary to call SPI init function again after calling this reset function.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 DS_12MA DS_16MA Return Value: FT4222_OK if successful, otherwise the return value is an FT error code. Error code: FT4222_DEVICE_NOT_OPENED: The initialization API is not called.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Return Value: FT4222_OK if successful, otherwise the return value is an FT error code. Error code: FT4222_DEVICE_NOT_SUPPORTED: This device is not a FT4222 chip.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Error code: FT4222_DEVICE_NOT_OPENED: The initialization API is not called. FT4222_IS_NOT_I2C_MODE: The device is not in i2c slave mode FT4222_INVALID_POINTER: Parameter buffer is NULL FT4222_INVALID_PARAMETER: bytesToRead is equal to zero FT4222_FAILED_TO_READ_DEVICE: Failed to read data.
Page 50
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 FT4222 Rev C FT4222 Rev D Summary: Write data to the specified I C slave device with START and STOP conditions. Parameters: ftHandle Handle of the device.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 FT4222_INVALID_POINTER: Parameter buffer is NULL FT4222_INVALID_PARAMETER: bytesToWrite is equal to zero FT4222_FAILED_TO_WRITE_DEVICE: Failed to write data. Prerequisite: FT4222_I2CMaster_Init Example: FT_HANDLE ftHandle = NULL; FT_STATUS ftStatus;...
Page 53
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Supported Chip: FT4222 chip version Supported FT4222 Rev A FT4222 Rev B FT4222 Rev C FT4222 Rev D Summary: Read data from the specified I C slave device with the specified I C condition.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 SR = repeated START condition Here is an example for typical usage of I C combined message: // Write to I2C slave with START bit...
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 3.6.7 I C Master Reset FT4222_STATUS FT4222_I2CMaster_Reset(FT_HANDLE ftHandle) Supported Chip: FT4222 chip version Supported FT4222 Rev A FT4222 Rev B FT4222 Rev C FT4222 Rev D...
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Supported Chip: FT4222 chip version Supported FT4222 Rev A FT4222 Rev B FT4222 Rev C FT4222 Rev D Parameters: ftHandle Handle of the device.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Parameters: ftHandle Handle of the device. pAddr Pointer to a variable of type uint16 which receives the address of the I C slave device.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Supported Chip: FT4222 chip version Supported FT4222 Rev A FT4222 Rev B FT4222 Rev C FT4222 Rev D Summary: Set the address of the I C slave device.
Page 59
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Error code: FT4222_DEVICE_NOT_OPENED: The initialization API is not called. FT4222_INVALID_POINTER: Parameter pRxSize is NULL Prerequisite: FT4222_I2CSlave_Init Example: FT_HANDLE ftHandle = NULL; FT_STATUS ftStatus; FT4222_STATUS ft4222Status;...
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Return Value: FT4222_OK if successful, otherwise the return value is an FT error code. Error code: FT4222_DEVICE_NOT_OPENED: The initialization API is not called. FT4222_IS_NOT_I2C_MODE: The device is not in i2c slave mode...
Page 62
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Supported Chip: FT4222 chip version Supported FT4222 Rev A FT4222 Rev B FT4222 Rev C FT4222 Rev D Summary: Reset the I C slave device. This function will maintain the original i2c slave setting and clear all cache in the device.
The FT4222H contains 4 GPIO. When the USB GPIO interface is supported, chip mode 0 and mode 1, LibFT4222 helps application developers to control GPIO directly. However, each GPIO pin is multiplexed with interrupt/suspend out/SPI slave select/I2C functions as listed below: ...
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Parameters: ftHandle Handle of the device. gpioDir An array defines the directions of 4 GPIO pins. The GPIO direction will be: GPIO_OUTPUT ...
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Error code: FT4222_DEVICE_NOT_OPENED: The initialization API is not called. FT4222_GPIO_NOT_SUPPORTED_IN_THIS_MODE: GPIO function is not supported in mode 2 and mode 3 Example: // this is an example for gpio read FT_HANDLE ftHandle = NULL;...
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 GPIO_PORT0 GPIO_PORT1 GPIO_PORT2 GPIO_PORT3 bValue The output value. Return Value: FT4222_OK if successful, otherwise the return value is an FT error code.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Supported Chip: FT4222 chip version Supported FT4222 Rev A FT4222 Rev B FT4222 Rev C FT4222 Rev D Summary: Set software trigger conditions on the specified GPIO pin.
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Supported Chip: FT4222 chip version Supported FT4222 Rev A FT4222 Rev B FT4222 Rev C FT4222 Rev D Summary: Get the size of trigger event queue.
Page 70
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Parameters: ftHandle Handle of the device. portNum One of the following GPIO port: GPIO_PORT0 GPIO_PORT1 GPIO_PORT2 GPIO_PORT3 events Pointer to the buffer that receives the values of the trigger event queue. The value of events will be: ...
Page 72
FTDI disclaims all liability for system designs and for any applications assistance provided by FTDI. Use of FTDI devices in life support and/or safety applications is entirely at the user’s risk, and the user agrees to defend, indemnify and hold harmless FTDI from any and all damages, claims, suits or expense resulting from such use.
Page 73
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Appendix A – Enumeration and Structure Definitions Enumeration FT4222_STATUS FT4222_DEVICE_NOT_SUPPORTED = 1000 FT4222_CLK_NOT_SUPPORTED // spi master do not support 80MHz/CLK_2 FT4222_VENDER_CMD_NOT_SUPPORTED FT4222_IS_NOT_SPI_MODE FT4222_IS_NOT_I2C_MODE FT4222_IS_NOT_SPI_SINGLE_MODE...
Page 74
= 0x04 START_AND_STOP = 0x06 // START condition followed by SEND and STOP condition Structure Definitions struct FT4222_Version DWORD chipVersion; // The version of FT4222H chip DWORD dllVersion; // The version of LibFT4222 struct SPI_Slave_Header uint8 syncWord; uint8 cmd; uint8 uint16 size;...
Page 75
Document References DS_FT4222H D2XX Programmers Guide D2XX Drivers FT_PROG Acronyms and Abbreviations Terms Description D2XX FTDI’s proprietary “direct” driver interface via FTD2XX.DLL GPIO General-purpose input/output Inter-Integrated Circuit Serial Peripheral Interconnect Universal Serial Bus USB-IF USB Implementers Forum Product Page Document Feedback...
Page 76
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Appendix C – List of Tables & Figures List of Tables Table 2.1 Chip Mode and Device Functions ................8 List of Figures Figure 1.1 The Software Stack ....................4 Figure 1.2 Mode 0: FT4222H works as SPI master (Quad Mode) ..........
Page 77
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Appendix D – D2XX API support D2XX supported API FT_CreateDeviceInfoList FT_GetDeviceInfoList FT_GetDeviceInfoDetail FT_ListDevices FT_Open FT_OpenEx FT_Close FT_SetTimeouts FT_SetLatencyTimer 10. FT_GetLatencyTimer 11. FT_GetDeviceInfo 12. FT_SetBitMode 13.
Page 78
Application Note AN_329 User Guide For LibFT4222 Version 1.5 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Appendix E – Revision History Document Title: AN_329 User Guide for LibFT4222 Document Reference No.: FT_001060 Clearance No.: FTDI#406 Product Page: http://www.ftdichip.com/FTProducts.htm Document Feedback:...
Need help?
Do you have a question about the LibFT4222 and is the answer not in the manual?
Questions and answers