LibMPSSE I2C学习笔记

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)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值