An 329 User Guide For LibFT4222-V1.8
An 329 User Guide For LibFT4222-V1.8
AN_329
Version 1.8
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.
Table of Contents
1 Introduction .............................................................. 4
1.1 Overview ............................................................................5
1.2 Scope .................................................................................8
1
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
2
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
3
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
1 Introduction
The FT4222H is a USB interface device which supports SPI and I2C communication protocol. It is
accompanied with the support library “LibFT4222” based on D2XX, which provides high-level APIs
to facilitate user application development. At the time of writing support for Windows and Linux OS
has been published. Android support uses a different package also available from the FTDI website.
The FT4222H contains SPI/I2C configurable interfaces. The SPI interface can be configured as master
mode with single, dual, quad bits wide data transfer or slave mode with single bit wide data transfer.
The I2C interface can be configured as master or slave mode.
User Application
LibFT4222
(SPI/I2C Library)
D2XX API
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://ftdichip.com/products/ft4222h/
The sample source code contained in this application note is provided as an example and is neither
guaranteed nor supported by FTDI.
4
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
1.1 Overview
The FT4222H supports 4 operation modes to allow various I2C/SPI devices to be connected to USB
bus. The attachable device configuration for each mode is listed below:
Operation mode is configured by DCNF0 & DCNF1 pins, please see below table for detail
The following shows the interface of different operation mode which displayed in device manager of
Windows OS.
5
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
In mode 0 and 3, the connected device can be a SPI/I2C master or slave, depending on how an
application developer initializes the FT4222H chip. Mode 1 and mode 2 are designed to connect to
multiple SPI slave devices.
The FT4222H can be configured with up to 4 GPIO pins for user applications in mode 0 and mode 1,
but each pin is multiplexed with interrupt/suspend out/SPI slave select/I2C functions as listed below:
If the FT4222H is initialized as an I2C device, with pins as shown above, the pins of gpio0 and gpio1
will be switched to scl and sda and cannot be used as GPIO.
By default, the pin for gpio2 is configured as suspend out, and the pin for gpio3 is configured as
wakeup/intr. Only those configured GPIO pins can support GPIO read/set operation through the
corresponding endpoint.
Figure 1.2, Figure 1.3, and Figure 1.4 shows the examples of FT4222H SPI/I2C master
connections.
6
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
7
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
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.
8
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
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 Table 2.1.
Number of
Mode Device Function
Interfaces
a. The first interface: it can be one of SPI master, SPI slave, I2C master,
0 2 or I2C slave device.
b. The second interface: GPIO device.
a. The first 3 interfaces: SPI master connects up to 3 SPI slaves.
1 4
b. The 4th interface: GPIO device.
a. SPI master connects up to 4 SPI slaves. Please refer figure 1.4.
2 4
FT4222H works as SPI master.
3 1 a. It can be one of SPI master, SPI slave, I2C master, or I2C slave device.
Table 2.1 Chip Mode and Device Functions
After opening the device with FT_Open, developers need to initialize the FT4222H device as either
SPI master, SPI slave, I2C master, or I2C slave. Different types of devices require different
configurations. For more details, please refer the next chapter.
Example#
include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include "ftd2xx.h"
#include "LibFT4222.h"
std::vector< FT_DEVICE_LIST_INFO_NODE > g_FT4222DevList;
inline std::string DeviceFlagToString(DWORD flags)
{
std::string msg;
msg += (flags & 0x1)? "DEVICE_OPEN" : "DEVICE_CLOSED";
msg += ", ";
msg += (flags & 0x2)? "High-speed USB" : "Full-speed USB";
return msg;
}
void ListFtUsbDevices()
{
DWORD numOfDevices = 0;
FT_STATUS status = FT_CreateDeviceInfoList(&numOfDevices);
status = FT_GetDeviceInfoDetail(iDev,
&devInfo.Flags, &devInfo.Type, &devInfo.ID, &devInfo.LocId,
devInfo.SerialNumber, devInfo.Description, &devInfo.ftHandle);
if (FT_OK == status)
9
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
{
printf("Dev %d:\n", iDev);
printf(" Flags= 0x%x, (%s)\n", devInfo.Flags,
DeviceFlagToString(devInfo.Flags).c_str());
printf(" Type= 0x%x\n", devInfo.Type);
printf(" ID= 0x%x\n", devInfo.ID);
printf(" LocId= 0x%x\n", devInfo.LocId);
printf(" SerialNumber= %s\n", devInfo.SerialNumber);
printf(" Description= %s\n", devInfo.Description);
printf(" ftHandle= 0x%x\n", devInfo.ftHandle);
if(g_FT4222DevList.empty()) {
printf("No FT4222 device is found!\n");
return 0;
}
FT4222_Uninitialize(ftHandle);
FT_Close(ftHandle);
return 0;
}
10
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
After calling FT_Open, the FT4222H is required to be initialized by one of the following initial
functions:
• FT4222_SPIMaster_Init
• FT4222_SPISlave_Init
• FT4222_I2CMaster_Init
• FT4222_I2CSlave_Init
• FT4222_GPIO_Init
The initialization functions help developers to switch the FT4222H into a specific mode.
At the end of the application, FT4222_Uninitialize should be called to release allocated resources,
before calling FT_Close.
All the APIs return an FT4222_STATUS, which extends FT_STATUS that is defined in the D2XX driver
(see the D2XX Programmer’s Guide). FT4222_STATUS defines additional values to report FT4222H
specific status.
All definitions with prefix “FT_” are defined in the D2XX driver.
3.1 Typedefs
The following typedefs have been defined for keeping cross platform portability:
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. In addition, please note that the FT4222H assigns different functions to different
interfaces. For example, under mode 0, interface A is assigned as SPI or I2C interface, and interface
B is assigned as GPIO interface.
After finishing using the device, FT_Close should be called to release the device.
11
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
3.2.2 Un-initialize
Supported Chip:
Summary:
• FT4222_SPIMaster_Init
• FT4222_SPISlave_Init
• FT4222_I2CMaster_Init
• FT4222_I2CSlave_Init
• FT4222_GPIO_Init
Parameters:
Return Value:
Error code:
Example:
FT4222_UnInitialize(ftHandle);
FT_Close(ftHandle);
12
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Supported Chip:
Summary:
Set the system clock rate. The FT4222H supports 4 clock rates: 80MHz, 60MHz, 48MHz, or 24MHz.
By default, the FT4222H runs at 60MHz clock rate.
Parameters:
Return Value:
Error code:
Example:
13
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Supported Chip:
Summary:
Parameters:
Return Value:
Error code:
Example:
FT_Close(ftHandle);
14
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Supported Chip:
Summary:
Enable or disable, suspend out, which will emit a signal when FT4222H enters suspend mode. Please
note that the suspend-out pin is not available under mode 2. By default, suspend-out function is on.
When suspend-out function is on, suspend-out pin emits signal according to suspend-out polarity.
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.
Parameters:
Return Value:
Error code:
Example:
FT_Close(ftHandle);
15
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Supported Chip:
Summary:
When Wake up/Interrupt function is on, GPIO3 pin acts as an input pin for wakeup/interrupt.
While system is in normal mode, GPIO3 acts as an interrupt pin. While system is in suspend mode,
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:
Return Value:
Error code:
Example:
Supported Chip:
Summary:
Set trigger condition for the pin wakeup/interrupt. By default, the trigger condition is
GPIO_TRIGGER_RISING.
16
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
When GPIO3 acts as wakeup pin. It means that ft4222H device has the capability to wake up the
host. Only GPIO_TRIGGER_RISING and GPIO_TRIGGER_FALLING is valid when GPIO3 act as a
wakeup pin. It is not necessary to call FT4222_GPIO_Init to set up wake-up function.
When GPIO3 acts as interrupt pin. All trigger condition can be set. The result of trigger status can
be inquired by FT4222_GPIO_ReadTriggerQueue or FT4222_GPIO_Read. This is because the trigger
status is provided by the GPIO pipe. Therefore, it is necessary to call FT4222_GPIO_Init to set up
interrupt function.
Parameters:
Return Value:
Error code:
Example:
17
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
GPIO_Dir gpioDir[4];
gpioDir[0] = GPIO_OUTPUT;
gpioDir[1] = GPIO_OUTPUT;
gpioDir[2] = GPIO_OUTPUT;
gpioDir[3] = GPIO_INPUT;
FT4222_GPIO_Init(ftHandle, gpioDir);
// enable interrupt
FT4222_SetWakeUpInterrupt(ftHandle, true);
// setup interrupt trigger level
FT4222_SetInterruptTrigger(ftHandle, GPIO_TRIGGER_RISING);
while(1)
{
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);
FT_Close(ftHandle);
GPIO_Dir gpioDir[4];
gpioDir[0] = GPIO_OUTPUT;
gpioDir[1] = GPIO_OUTPUT;
gpioDir[2] = GPIO_OUTPUT;
gpioDir[3] = GPIO_INPUT;
FT4222_GPIO_Init(ftHandle, gpioDir);
// enable interrupt
FT4222_SetWakeUpInterrupt(ftHandle, true);
// setup interrupt trigger level
18
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
FT4222_SetInterruptTrigger(ftHandle, GPIO_TRIGGER_RISING);
while(1)
{
uint16 queueSize;
// sleep 1s
Sleep(1000);
if(FT4222_GPIO_GetTriggerStatus(ftHandle, GPIO_PORT3, &queueSize) == FT4222_OK)
{
// got interrupt times in 1s
if(queueSize > 0)
{
BOOL value;
// clear the interrupt result
FT4222_GPIO_Read(ftHandle, (GPIO_Port)GPIO_PORT3, &value);
}
}
}
FT4222_UnInitialize(ftHandle);
FT_Close(ftHandle);
Supported Chip:
Summary:
This function returns the maximum packet size in a transaction. It will be affected by different bus
speeds, chip modes, and functions. The maximum transfer size is maximum size in writing path.
Parameters:
Return Value:
Error code:
Example:
19
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
if (FT_OK != ftStatus)
{
// open failed
return;
}
ft4222Status = FT4222_I2CMaster_Init(ftHandle, 1000);
if (FT4222_OK != ft4222Status)
{
// init i2c master failed
return;
}
ft4222Status = FT4222_GetMaxTransferSize(ftHandle, &maxSize);
if (FT4222_OK != ft4222Status)
{
// get max transfer size failed
return;
}
FT_Close(ftHandle);
Supported Chip:
Summary:
An application can use this function to set up conditions which allow a thread to block until one of
the conditions is met. Typically, an application will create an event, call this function, and then block
on the event. When the conditions are met, the event is set, and the application thread unblocked.
Usually, the event is set to notify the application to check the condition. The application needs to
check the condition again before it goes to handle the condition. The API is only valid when the
device acts as SPI slave and SPI slave protocol is not SPI_SLAVE_NO_PROTOCOL.
Parameters:
Return Value:
20
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Prerequisite:
FT4222_SPISlave_InitEx or FT4222_SPISlave_Init
Example:
hRxEvent = CreateEvent(
NULL,
false, // auto-reset event
false, // non-signalled state
NULL );
ft4222Status = FT4222_SetEventNotification(ftHandle, FT4222_EVENT_RXCHAR, hRxEvent);
if (FT4222_OK != ft4222Status)
{
//set event notification failed
return;
}
uint16 rxSize;
uint16 sizeTransferred;
while(1)
{
WaitForSingleObject(hRxEvent, 1000);
ft4222Status = FT4222_SPISlave_GetRxStatus(ftHandle, &rxSize);
if(ft4222Status == FT4222_OK)
{
if(rxSize>0)
{
std::vector<unsigned char> tmpBuf;
tmpBuf.resize(rxSize);
ft4222Status = FT4222_SPISlave_Read(ftHandle, &tmpBuf[0], rxSize, &sizeTransferred);
// handle receive data
}
}
}
21
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
FT_Close(ftHandle);
Supported Chip:
Summary:
Parameters:
struct FT4222_Version
{
DWORD chipVersion; // The version of FT4222H chip
DWORD dllVersion; // The version of LibFT4222
};
Return Value:
Error code:
Example:
22
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
return;
}
ft4222Status = FT4222_GetVersion(ftHandle, &ver);
if (FT4222_OK != ft4222Status)
{
// get version failed
return;
}
printf("%x %x\n",ver.chipVersion,ver.dllVersion);
FT_Close(ftHandle);
Supported Chip:
Summary:
This function is used to attempt to recover system after a failure. It is a software reset for device.
Parameters:
Return Value:
Error code:
Example:
23
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
}
FT_Close(ftHandle);
Supported Chip:
Summary:
This function is used to attempt to get chip mode information. The chip mode information is identified
when the system power on as defined by the {DCNF1, DCNF0} pins. If the chip mode is changed
after the system is powered, the chip mode value would keep the value from when the system was
powered on.
Parameters:
Return Value:
Error code:
Example:
}
FT_Close(ftHandle);
24
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
• Single SPI transfer – Standard data transfer format – data is read and written
simultaneously
• 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
simultaneously
For SPI Master Single mode, all data packets are terminated with a zero-length packet. Therefore,
after one data packet there will be one SOF then follows by the terminating zero-length packet then
ends with another SOF. As a result, under normal conditions, these two SOF’s will take approximately
250us.
Supported Chip:
Summary:
To support various types of SPI slave devices, the FT4222H SPI master is configurable using the
following parameters:
• IO lines: SPI transmission lines. The FT4222H SPI supports single, dual, or quad
transmission mode. An application may override this initial selection dynamically using
FT4222_SPIMaster_SetLines. For example, commands might be sent in single mode, but
data transferred in dual or quad mode.
• Clock divider: SPI clock rate is subject to system clock. The FT4222H SPI clock could be 1/2,
1/4, 1/8, 1/16, 1/32, 1/64, 1/128, 1/256, or 1/512 system clock rate.
• Clock polarity: Idle high or idle low.
• Clock phase: Data is sampled on the leading (first) or trailing (second) clock edge.
• Slave selection output pins: Select slave devices by ss0o, ss1o, ss2o, ss3o. The default slave
selection is active low.
• There is only one setting stored in the MCU. If there are multi-SPI masters to be initialized,
keep all settings the same, including ssoMap.
Please note that the FT4222H has only one SPI controller. Even though the FT4222H provides up to
4 interfaces for connecting up to 4 SPI slave devices as per Figure 1.4, the 4 slave devices share the
same SPI data bus: MOSI, MISO, and SCK. A user can decide how to map the 4 interfaces to the 4
SS signals (ss0o, ss1o, ss2o and ss3o) by the ssoMap parameter.
25
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
The 4 interfaces cannot work simultaneously because there is only one data bus.
Parameters:
Return Value:
Error code:
26
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
FT4222_UnInitialize(ftHandle);
FT_Close(ftHandle);
Example: multiple SPI master initialization, this sample runs in Mode 1 or Mode 2
FT4222_UnInitialize(ftHandle1);
FT4222_UnInitialize(ftHandle2);
FT_Close(ftHandle1);
FT_Close(ftHandle2);
27
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Supported Chip:
Summary:
Switch the FT4222H SPI master to single, dual, or quad mode. This overrides the mode passed to
FT4222_SPIMaster_init. This might be needed if a device accepts commands in single mode, but
data transfer is to use dual or quad mode.
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_SPIMaster_init
Supported Chip:
Summary:
28
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
• Clock phase: Data is sampled on the leading (first) or trailing (second) clock edge.
Below table shows 4 SPI Mode:
Parameters:
Return Value:
Prerequisite:
FT4222_SPIMaster_init
Supported Chip:
Summary:
Change chip select of FT4222H SPI master. If this function is not called, the default chip select is
active low.
Parameters:
Return Value:
29
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Prerequisite:
FT4222_SPIMaster_init
3.3.5 SPI Master Single Read
Supported Chip:
Summary:
Parameters:
Return Value:
Error code:
FT4222_SPIMaster_init
Example:
30
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
uint8 recvData[10];
uint16 sizeTransferred;
ft4222Status = FT4222_SPIMaster_SingleRead(ftHandle, &recvData[0], 10, &sizeTransferred,
true);
if (FT4222_OK != ft4222Status)
{
// spi master read failed
return;
}
FT4222_UnInitialize(ftHandle);
FT_Close(ftHandle);
Supported Chip:
Summary:
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_SPIMaster_init
31
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Example:
uint8 sendData[10];
uint16 sizeTransferred;
for(int idx=0;idx<10;idx++)
sendData[idx] = idx;
FT4222_UnInitialize(ftHandle);
FT_Close(ftHandle);
Summary:
Under SPI single mode, full-duplex write data to and read data from an SPI slave.
The standard SPI protocol simultaneously sends data onto the MOSI data line and receives data from
the MISO line as shown below -
32
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Return Value:
Error code:
Prerequisite:
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
33
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
if (FT_OK != ftStatus)
{
// open failed
return;
}
uint8 sendData[2];
uint8 readData[2];
uint16 sizeTransferred;
FT4222_UnInitialize(ftHandle);
FT_Close(ftHandle);
Supported Chip:
34
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Summary:
Under SPI dual or quad mode, write data to and read data from an SPI slave.
Figure 3.2 illustrates the dual-SPI protocol supported by the FT4222H SPI master. It is a mixed
protocol initiated with a single write transmission, which may be an SPI command and dummy cycles,
and followed by dual-write and dual-read transmission that use 2 signals in parallel for the data. All
three parts of the protocol are optional. For example, developers can ignore the multi-read part by
setting multiReadBytes=0.
Figure 3.3 illustrates the quad-SPI protocol supported by the FT4222H SPI master. It is the same
as the dual-protocol illustrated above - it is a mixed protocol initiated with a single write transmission
and followed by quad-write and quad-read transmission that use 4 signals in parallel for the data.
35
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
This table only takes effect on CLK division >=8. If CLK division is equal to 2 or 4, the time for T2
and T3 is very close and SPI Slave is hard to switch the I/O in such a short time.
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_SPIMaster_init
Example:
36
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
uint8 writeData[7];
uint8 readData[16];
uint32 sizeOfRead;
FT4222_UnInitialize(ftHandle);
FT_Close(ftHandle);
A USB-SPI bridge usually faces the challenge that USB cannot guarantee the throughput for each
endpoint, but SPI requires data transmission at a steady rate. It is highly possible when an SPI
master starts to request data from a USB-SPI slave bridge device, the data has not arrived from the
USB host side yet. In addition, SPI does not have a standard protocol to allow the master side to
check the status of the slave side. The protocol is usually provided by an SPI slave device on its own,
which makes the SPI master device communicate with the slave device by its specified commands.
• SPI_SLAVE_WITH_PROTOCOL
• SPI_SLAVE_NO_ACK
• SPI_SLAVE_NO_PROTOCOL
With all the SPI Slave operational modes listed, the support library will always add a dummy byte
37
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
of “0x00” as the first byte for every transmission. This is an internal sync byte that is needs to be
removed by the 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.
In this protocol, a master starts an SPI transaction by sending a packet in the format illustrated
below. The Sync Word “0x5A” is fixed with this slave mode and user applications do not need to do
any operations to add or remove the Sync Word. It is done by the support library.
The packet starts with Sync word: 0x5A, and followed by a Command field:
Command Value
Master Transfer 0x80
Slave Transfer 0x81
Short master transfer (without checksum) 0x82
Short slave transfer (without checksum) 0x83
ACK 0x84
SN stands for serial number. It is monotonically increased and helps to identify packets. Size is a
two-byte field, which is the size of the data field in big-endian order. The Checksum is the
summation of all data fields’ lower two bytes starting from the first byte, the sync word, to the latest
data byte.
The checksum is in big-endian order as well. When the slave, FT4222H, receives the transfer request
from the master, it will respond with an ACK. The master can confirm the transaction succeeded
when it receives the ACK from the slave.
When SPI Slave receives the Master transfer request, it will check if the format and checksum are
correct. If the answer is yes, the support-lib will send the response ACK automatically, grab the data
from the packet and send it to application.
38
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Here is an example of an ACK packet. The SN field of the ACK packet identifies which request it
corresponds to. An ACK packet has no data therefore the Size field should be 0.
If the SPI master does not receive the ACK response from the slave, it should send its request again.
Figure 3.7 An example of when the SPI master doesn’t receive ACK
When the FT4222H SPI slave wants to send data to the master, which may be requested by the
master, it just sends a transfer request in the same protocol format as shown in Figure 3.4.
In this case, it is not necessary to append any header while API FT4222_SPISlave_Write is called.
The encapsulation of header is done by support-lib.
39
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
◼ SPI_SLAVE_NO_ACK
◼ SPI_SLAVE_NO_PROTOCOL
This option provides no protocol for SPI Slave function, and it is configured and initialized with the
API FT4222_SPISlave_InitEx.
In this SPI Slave operational mode, the Sync Word “0x5A” is not inserted. And there is no additional
process in support-lib.
40
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Supported Chip:
Summary:
Parameters:
Return Value:
Error code:
Supported Chip:
Summary:
Parameters:
41
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Return Value:
Error code:
Supported Chip:
Summary:
Set SPI slave CPOL and CPHA. The Default value of CPOL is CLK_IDLE_LOW, default value of CPHA
is CLK_LEADING.
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_SPISlave_InitEx or FT4222_SPISlave_Init
Example:
42
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Summary:
Supported Chip:
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_SPISlave_InitEx or FT4222_SPISlave_Init
Example:
43
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Supported Chip:
Summary:
Read data from the receive queue of the SPI slave device.
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_SPISlave_InitEx or FT4222_SPISlave_Init
Example:
44
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
uint16 rxSize;
std::vector<unsigned char> recvBuf;
while(1)
{
if(FT4222_SPISlave_GetRxStatus(ftHandle, &rxSize) == FT4222_OK)
{
if(rxSize>0)
{
recvBuf.resize(rxSize);
if(FT4222_SPISlave_Read(ftHandle,&recvBuf[0], rxSize, &sizeTransferred)==
FT4222_OK)
{
// get data
}
else
{
// get data failed
}
}
}
}
FT4222_UnInitialize(ftHandle);
FT_Close(ftHandle);
Supported Chip:
Summary:
For some reasons, support lib will append a dummy byte (0x00) at the first byte automatically.
This additional byte exists at all the three transfer methods.
Parameters:
Return Value:
Error code:
45
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Prerequisite:
FT4222_SPISlave_InitEx or FT4222_SPISlave_Init
Example:
Supported Chip:
Summary:
Reset the SPI transaction. It would purge receive and transmit buffers in the device and reset the
transaction state. D2XX has a similar function (FT_PURGE) but strongly recommend to use
FT4222_SPI_ResetTransaction.
46
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Parameters:
Return Value:
Error code:
Prerequisite:
Example:
Supported Chip:
47
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
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. It remains all original setting of SPI.
Parameters:
Return Value:
Error code:
Prerequisite:
SPI_DrivingStrength clkStrength,
SPI_DrivingStrength ioStrength,
SPI_DrivingStrength ssoStrength)
Supported Chip:
Summary:
For the FT4222H SPI, set the driving strength of clk, io, and sso pins. The default driving strength
of all SPI pins are 4MA. DS_4MA is adopted mostly. Unless there is some hardware wiring
requirement for device, set driving strength to 4MA is enough.
Parameters:
48
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
• DS_12MA
• DS_16MA
Return Value:
Error code:
Prerequisite:
The FT4222H device can be initialized as either an I2C master or I2C slave under mode 0 and mode
3. Here is a brief overview of FT4222H I2C features:
Supported Chip:
Summary:
Initialize the FT4222H as an I2C master with the requested I2C speed.
Parameters:
49
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Return Value:
Error code:
Example:
Supported Chip:
Summary:
Read data from the specified I2C slave device with START and STOP conditions.
Parameters:
Return Value:
50
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Error code:
Prerequisite:
FT4222_I2CMaster_Init
Example:
FT4222_UnInitialize(ftHandle);
FT_Close(ftHandle);
51
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Supported Chip:
Summary:
Write data to the specified I2C slave device with START and STOP conditions.
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_I2CMaster_Init
Example:
52
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
FT4222_UnInitialize(ftHandle);
FT_Close(ftHandle);
Supported Chip:
Summary:
I²C defines basic types of transactions, each of which begins with a START and ends with a STOP:
In a combined transaction, each read or write begins with a START and the slave address. The START
conditions after the first are also called repeated START bits. Repeated STARTs are not preceded by
STOP conditions, which is how slaves know that the next message is part of the same transaction.
Parameters:
53
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Return Value:
Error code:
Prerequisite:
FT4222_I2CMaster_Init
Example:
54
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
FT4222_UnInitialize(ftHandle);
FT_Close(ftHandle);
Supported Chip:
Summary:
Read data from the specified I2C slave device with the specified I2C condition.
This function is supported by the Revision B FT4222H or later.
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_I2CMaster_Init
Example:
55
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
In a combined message, each read or write begins with a START and the slave address. After the
first START, the subsequent starts are referred to as repeated START bits; repeated START bits are
not preceded by STOP bits, which indicate to the slave the next transfer is part of the same message.
7 bit 7 bit
NACK
STOP
Read
Start
write
ACK
ACK
ACK
ACK
SR
slave 8 bit data slave 8 bit data 8 bit data
address address
Supported Chip:
Summary:
Read the status of the I2C master controller. This can be used to poll a slave after I2C transmission
is complete.
Parameters:
56
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Return Value:
Prerequisite:
FT4222_I2CMaster_Init
Supported Chip:
Summary:
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_I2CMaster_Init
Supported Chip:
57
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Summary:
If the data line (SDA) is pulled LOW by slave device, this API will send nine SCK clocks from master
to recover I2C bus. The slave device will release data line (SDA) when it receives the nine clocks
from master. If data line cannot be released by this API, HW reset or cycle power is another solution.
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_I2CMaster_Init
Example:
FT4222_UnInitialize(ftHandle);
FT_Close(ftHandle);
58
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
return;
}
// TODO
FT4222_UnInitialize(ftHandle);
FT_Close(ftHandle);
When the I2C slave receives data from the I2C bus, it will keep the data in its internal receive buffer
(256 bytes), and then send the data to the USB host through IN packets.
When data is requested by an I2C master, data will be moved from an OUT packet to the transmit
register directly.
Summary:
Initialize FT4222H as an I2C slave. After FT4222_I2CSlave_Init, I2C slave address is reset to 0x40.
Supported Chip:
Parameters:
Return Value:
Error code:
Example:
59
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Supported Chip:
Summary:
Get the address of the I2C slave device. The default address is 0x40.
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_I2CSlave_Init
Example:
60
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
{
// i2c slave init failed
return;
}
uint8 i2cAddr;
// set new i2c slave addr
i2cAddr =0x25;
ft4222Status = FT4222_I2CSlave_SetAddress(ftHandle, i2cAddr);
if (FT4222_OK != ft4222Status)
{
// i2c slave get addr failed
return;
}
ft4222Status = FT4222_I2CSlave_GetAddress(ftHandle, &i2cAddr);
if (FT4222_OK != ft4222Status)
{
// i2c slave get addr failed
return;
}
FT4222_UnInitialize(ftHandle);
FT_Close(ftHandle);
Supported Chip:
Summary:
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_I2CSlave_Init
Example:
61
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Supported Chip:
Summary:
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_I2CSlave_Init
Example:
62
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
while(1)
{
uint16 rxSize;
FT4222_UnInitialize(ftHandle);
FT_Close(ftHandle);
Supported Chip:
Summary:
Parameters:
Return Value:
63
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Error code:
Prerequisite:
FT4222_I2CSlave_Init
Example:
Summary:
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_I2CSlave_Init
Example:
64
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Supported Chip:
Summary:
Reset the I2C slave device. This function will maintain the original I2C slave setting and clear all
cache in the device. D2XX has a similar function (FT_PURGE) but strongly recommend to use
FT4222_I2CSlave_Reset.
Parameters:
Return Value:
Error code:
65
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Prerequisite:
FT4222_I2CSlave_Init
Example:
Supported Chip:
Summary:
Enable or disable Clock Stretch. The default setting of clock stretching is disabled.
Clock stretch is as a flow-control mechanism for slaves. An addressed slave device may hold the
clock line (SCL) low after receiving (or sending) a byte, indicating that it is not yet ready to process
more data. The master that is communicating with the slave may not finish the transmission of the
current bit but must wait until the clock line goes high.
Parameters:
66
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Return Value:
Error code:
Prerequisite:
FT4222_I2CSlave_Init
Example:
Supported Chip:
Summary:
This function only takes effect when Clock Stretch is disabled. When data is requested by an I2C
master and the device is not ready to respond, the device will respond a default value. Default value
is 0xFF. This function can be used to set the response word.
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_I2CSlave_Init
67
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
The number of GPIO pins available depends on the mode of the chip. For example, if the FT4222H
is initialized as an I2C device, as shown above, the pins of gpio0 and gpio1 will be switched to scl
and sda and cannot be used as GPIO. If suspend out and remote wakeup are enabled gpio2 and
gpio3 cannot be used as GPIO.
The FT4222H supports GPIO on the second USB interface in mode 0 or on the fourth interface in
mode 2. Please refer to Table 2.1 for chip mode and interface.
Supported Chip:
Summary:
Parameters:
Return Value:
Error code:
Example:
68
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Supported Chip:
Summary:
Parameters:
For Interrupt:
TRUE means trigger condition is invoked
FALSE means trigger condition is not invoked
Interrupt status is cleared after calling this function.
Return Value:
Error code:
Example:
69
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
gpioDir[3] = GPIO_INPUT;
FT4222_GPIO_Init(ftHandle, gpioDir);
//disable suspend out , enable gpio 2
FT4222_SetSuspendOut(ftHandle, false);
//disable interrupt , enable gpio 3
FT4222_SetWakeUpInterrupt(ftHandle, false);
BOOL value;
if(FT4222_GPIO_Read(ftHandle, (GPIO_Port)GPIO_PORT3, &value) == FT4222_OK)
{
// got gpio status
}
FT4222_UnInitialize(ftHandle);
FT_Close(ftHandle);
Supported Chip:
Summary:
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_GPIO_Init
70
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Example:
// open failed
return;
}
GPIO_Dir gpioDir[4];
gpioDir[0] = GPIO_OUTPUT;
gpioDir[1] = GPIO_OUTPUT;
gpioDir[2] = GPIO_OUTPUT;
gpioDir[3] = GPIO_OUTPUT;
FT4222_GPIO_Init(ftHandle, gpioDir);
Supported Chip:
Summary:
This function allows developers to monitor value changes of the GPIO pins. Values that satisfy the
trigger condition will be stored in a queue. For example, if GPIO_TRIGGER_RISING is set on GPIO0,
and GPIO0 then changes value from 0 to 1, the event GPIO_TRIGGER_RISING will be recorded into
the queue. Developers can query the queue status by FT4222_GPIO_GetTriggerStatus, and
FT4222_GPIO_ReadTriggerQueue.
This function can only set gpio trigger conditions. For interrupt trigger conditions, please refer to
FT4222_SetInterruptTrigger.
71
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_GPIO_Init
Example:
Supported Chip:
Summary:
Parameters:
72
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Return Value:
Error code:
Prerequisite:
FT4222_GPIO_Init
Example:
Supported Chip:
Summary:
Get events recorded in the trigger event queue. Trigger conditions are set by a call to
FT4222_GPIO_SetInputTrigger for a GPIO or FT4222_SetInterruptTrigger for an interrupt. After
calling this function, all events will be removed from the event queue.
Parameters:
73
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
For Interrupt:
The trigger condition needs to be set by the function
FT4222_SetInterruptTrigger
Return Value:
Error code:
FT4222_GPIO_Init
Example:
74
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Supported Chip:
Summary:
Enable or disable WaveForm Mode. When WaveForm mode is enabled, the device will record all GPIO
status periodically. The peeking time depends on the system clock. The default setting of WaveForm
mode is disabled.
Parameters:
Return Value:
Error code:
Prerequisite:
FT4222_GPIO_Init
75
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
4 Contact Information
Web Site
http://ftdichip.com
System and equipment manufacturers and designers are responsible to ensure that their systems, and any Future Technology
Devices International Ltd (FTDI) devices incorporated in their systems, meet all applicable safety, regulatory and system-level
performance requirements. All application-related information in this document (including application descriptions, suggested
FTDI devices and other materials) is provided for reference only. While FTDI has taken care to assure it is accurate, this
information is subject to customer confirmation, and 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. This document is subject to change without notice. No freedom to use patents or other intellectual property rights is
implied by the publication of this document. Neither the whole nor any part of the information contained in, or the product
described in this document, may be adapted or reproduced in any material or electronic form without the prior written consent
of the copyright holder. Future Technology Devices International Ltd, Unit 1, 2 Seaward Place, Centurion Business Park, Glasgow
G41 1HH, United Kingdom. Scotland Registered Company Number: SC136640
76
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
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
FT4222_IS_NOT_SPI_MULTI_MODE
FT4222_WRONG_I2C_ADDR
FT4222_INVAILD_FUNCTION
FT4222_INVALID_POINTER
FT4222_EXCEEDED_MAX_TRANSFER_SIZE
FT4222_FAILED_TO_READ_DEVICE
FT4222_I2C_NOT_SUPPORTED_IN_THIS_MODE
FT4222_GPIO_NOT_SUPPORTED_IN_THIS_MODE
FT4222_GPIO_EXCEEDED_MAX_PORTNUM
FT4222_GPIO_WRITE_NOT_SUPPORTED
FT4222_GPIO_PULLUP_INVALID_IN_INPUTMODE
FT4222_GPIO_PULLDOWN_INVALID_IN_INPUTMODE
FT4222_GPIO_OPENDRAIN_INVALID_IN_OUTPUTMODE
FT4222_INTERRUPT_NOT_SUPPORTED
FT4222_GPIO_INPUT_NOT_SUPPORTED
FT4222_EVENT_NOT_SUPPORTED
FT4222_FUN_NOT_SUPPORT
FT4222_ClockRate
SYS_CLK_60 = 0
SYS_CLK_24
SYS_CLK_48
SYS_CLK_80
FT4222_SPIMode
SPI_IO_NONE = 0
SPI_IO_SINGLE = 1
SPI_IO_DUAL = 2
SPI_IO_QUAD = 4
FT4222_SPIClock
CLK_NONE = 0
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
CLK_DIV_32 // 1/32 System Clock
CLK_DIV_64 // 1/64 System Clock
CLK_DIV_128 // 1/128 System Clock
CLK_DIV_256 // 1/256 System Clock
CLK_DIV_512 // 1/512 System Clock
FT4222_SPICPOL
CLK_IDLE_LOW =0
CLK_IDLE_HIGH =1
77
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
FT4222_SPICPHA
CLK_LEADING =0
CLK_TRAILING =1
SPI_DrivingStrength
DS_4MA
DS_8MA
DS_12MA
DS_16MA
enum GPIO_Port
GPIO_PORT0
GPIO_PORT1
GPIO_PORT2
GPIO_PORT3
enum GPIO_Dir
GPIO_OUTPUT
GPIO_INPUT
enum GPIO_Trigger
GPIO_TRIGGER_RISING
GPIO_TRIGGER_FALLING
GPIO_TRIGGER_LEVEL_HIGH
GPIO_TRIGGER_LEVEL_LOW
enum GPIO_Output
GPIO_OUTPUT_LOW
GPIO_OUTPUT_HIGH
enum I2C_MasterFlag
START = 0x02
Repeated_START = 0x03 // Repeated_START will not send master code in HS mode
STOP = 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 sn;
uint16 size;
};
78
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
FT_CreateDeviceInfoList
FT_GetDeviceInfoList
FT_GetDeviceInfoDetail
FT_ListDevices
FT_Open
FT_OpenEx
FT_Close
FT_SetTimeouts
FT_SetLatencyTimer
FT_GetLatencyTimer
FT_GetDeviceInfo
FT_SetBitMode
FT_SetUSBParameters
FT_VendorCmdSet
FT_VendorCmdGet
FT_VendorCmdGetEx
FT_Purge Chip rev must >= D
FT_ResetDevice Chip rev must >= D
FT_SetEventNotification This function can be use on SPI Slave (NO protocol), I2C slave,
interrupt
FT_GetStatus This function can be use on SPI Slave (NO protocol), I2C slave
FT_ResetPort
FT_Rescan
FT_Reload
FT_StopInTask
FT_RestartInTask
FT_CyclePort
Other APIs may conflict with FT4222 support-lib. Please inquiry FAE if you would like to use it.
79
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Appendix C – References
Document References
DS_FT4222H
D2XX Programmers Guide
D2XX Drivers
FT_PROG
Terms Description
80
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
List of Tables
Table 1.1 Chip Mode with DCNF0 and DCNF1 .......................................................................... 5
Table 2.1 Chip Mode and Device Functions ............................................................................. 9
Table 3.1 SPI Mode with CPOL and CPHA ............................................................................. 29
Table 3.2 SPI Timing for SPI Multi-IO mode ......................................................................... 36
List of Figures
Figure 1.1 The Software Stack .............................................................................................. 4
Figure 1.2 Mode 0: FT4222H works as SPI master (Quad Mode) ............................................... 6
Figure 1.3 Mode 0: FT4222H works as I2C Master ................................................................... 7
Figure 1.4 Mode 2: FT4222H works as SPI Master ................................................................... 7
Figure 3.1 SPI full duplex communication ............................................................................. 33
Figure 3.2 Dual SPI communications ................................................................................... 35
Figure 3.3 Quad SPI communication .................................................................................... 35
Figure 3.4 SPI Slave Protocol Format................................................................................... 38
Figure 3.5 SPI Master Transfer Request ............................................................................... 39
Figure 3.6 An example of the SPI slave responding with ACK .................................................. 39
Figure 3.7 An example of when the SPI master doesn’t receive ACK ........................................ 39
Figure 3.8 Slave sends transfer request ............................................................................... 40
Figure 3.9 SPI Master Transfer Request (NO ACK) ................................................................. 40
Figure 3.10 Slave sends transfer request (NO ACK) ............................................................... 40
81
Product Page
Document Feedback Copyright © Future Technology Devices International Limited
Application Note
AN_329 User Guide For LibFT4222
Version 1.8
Updated FT4222_I2CSlave_SetClockStretch,
1.3 03-08-2017
FT4222_I2CSlave_SetRespWord.
Updated FT4222_SPISlave_SetMode,
FT4222_GPIO_SetWaveFormMode,
1.4 FT4222_SPISlave_RxQuickResponse; error 19-04-2018
message; sample code; D2xx supported API &
prerequisite information.
82
Product Page
Document Feedback Copyright © Future Technology Devices International Limited