Visual Studio环境下无法运行,建议参考:编译连接
获取当前主机已连接I2C通道数目
函数:FTDI_API FT_STATUS I2C_GetNumChannels(uint32 *numChannels)
验证程序
#include "stdafx.h"
#include <windows.h>
#pragma comment(lib, "FTD2XX.lib")
#include "FTD2XX.h"
//========================================================================
#include <stdlib.h>
#include "libMPSSE_i2c.h"
FT_STATUS ftStatus; //Status defined in D2XX to indicate operation result
FT_HANDLE ftHandle; //Handle of FT2232H device port
int _tmain(int argc, _TCHAR* argv[])
{
//
/// INITIALIZE SECTION
///
//
// Define the variables used
//
DWORD dwCount;
DWORD devIndex = 0;
UINT8 Buf[4];
uint32 sizeTransfered = 0;
ChannelConfig vChannelConfig;
ftStatus = I2C_GetNumChannels(&dwCount);
if (ftStatus == FT_OK) {
printf("The number of I2C channel on the host is %d\n", dwCount);
}
return 0;
}
验证结果
由于FT2232H有两个MPSSE端口,因此,返回结果符合预期。
获取I2C通道信息
函数:FTDI_API FT_STATUS I2C_GetChannelInfo(uint32 index, FT_DEVICE_LIST_INFO_NODE *chanInfo)
其中,
index:表示目标I2C通道的索引号,通道索引从0开始;以FT2232H为例,共有两个port,那么index可以是0或1
chanInfo:表示指向FT_DEVICE_LIST_INFO_NODE的指针
验证程序
#include "stdafx.h"
#include <windows.h>
//============================================================================
// Use of FTDI D2XX library:
//----------------------------------------------------------------------------
// Include the following 2 lines in your header-file
#pragma comment(lib, "FTD2XX.lib")
#include "FTD2XX.h"
//============================================================================
#include <stdlib.h>
#include "libMPSSE_i2c.h"
FT_STATUS ftStatus; //Status defined in D2XX to indicate operation result
FT_HANDLE ftHandle; //Handle of FT2232H device port
int _tmain(int argc, _TCHAR* argv[])
{
//
/// INITIALIZE SECTION
///
//
// Define the variables used
//
DWORD dwCount;
DWORD devIndex = 0;
UINT8 Buf[4];
uint32 sizeTransfered = 0;
ChannelConfig vChannelConfig;
FT_DEVICE_LIST_INFO_NODE chanInfo;
ftStatus = I2C_GetNumChannels(&dwCount);
if (ftStatus == FT_OK) {
printf("The number of I2C channel on the host is %d\n", dwCount);
}
ftStatus = I2C_GetChannelInfo(1, &chanInfo);
if (ftStatus == FT_OK) {
printf("description: %s\n", chanInfo.Description);
printf("flags: %x\n", chanInfo.Flags);
printf("id: %x\n", chanInfo.ID);
printf("lolid: %x\n", chanInfo.LocId);
printf("serial number: %s\n", chanInfo.SerialNumber);
printf("type: %x\n", chanInfo.Type);
}
return 0;
}
验证结果# 打开I2C通道
函数:FTDI_API FT_STATUS I2C_OpenChannel(uint32 index, FT_HANDLE *handle)
其中,
index:目标I2C通道索引编号
handle:返回I2C通道操作句柄
初始化I2C通道
FTDI_API FT_STATUS I2C_InitChannel(FT_HANDLE handle, ChannelConfig *config)
其中,
handle:I2C通道操作句柄
config:I2C通道配置信息
关闭I2C通道
FTDI_API FT_STATUS I2C_CloseChannel(FT_HANDLE handle)