關於 FT260Q 開發版 DS_UMFT260EV1A I2C操作方法(Windows)
FT260Q 對I2C的指令做的比較單純, 大部份FT260Q已包裹起來(類似Linux 的 I2C_dev )
如果想要自己下達I2C每一個步驟的指令, 可以考慮使用CH341A
CH341A優點是可以完全自行控制, 缺點是程式碼要增加百倍.
(CH341也有提供簡單的包裹式指令集)
SCL : GPIO0
SDL : GPIO1
開發版上面還多掛了一顆 EEPROM AT24C02D
Device Address: 0x50
如果要取消這顆EEPROM , 把開發版之 JP8 切斷
EEPROM AT24C02D
https://www.microchip.com/en-us/product/at24c02d
FT260Q
https://ftdichip.com/products/ft260q/
LibFT260
Application Note AN_395 User Guide for LibFT260
https://www.ftdichip.com/Support/Documents/AppNotes/AN_395_User_Guide_for_LibFT260.pdf這是原廠提供的一組函式庫,可以將指量傳輸給FT260Q
https://ftdichip.com/software-examples/
最下面那個沒有說明的 Libft260
https://ftdichip.com/wp-content/uploads/2022/10/LibFT260-v1.1.6.zip
解壓縮後
\LibFT260-v1.1.6\imports\LibFT260\inc\LibFT260.h
\LibFT260-v1.1.6\imports\LibFT260\lib\i386\LibFT260.lib, LibFT260.dll
範例程式 (須要使用 Visual Studio )
\LibFT260-v1.1.6\samples\I2C
原始範例程式可以使用 Device Address 0x50 對EEPROM AT24C02D直接讀寫.
下面是直接修改對EEPROM AT24C256 直接讀寫.
// Open Device
FT260_HANDLE mhandle1 = INVALID_HANDLE_VALUE;
FT260_STATUS ftStatus = FT260_OK;
DWORD devNum = 0;
FT260_CreateDeviceList(&devNum);
// #define VID 0x0403 #define PID 0x6030
ftStatus = FT260_OpenByVidPid(VID ,PID, 0, &mhandle1) ;
printf("FT260_OpenByVidPid = %d\n",ftStatus );
ftStatus = FT260_I2CMaster_Init(mhandle1, 100);
// (5)Read EEPROM
unsigned long len;
DWORD writeLength = 0;
DWORD readLength = 0;
char dataw[10], datar[10];
gI2CAddr = 0x51;
writeLength = 0;
dataw[0] = 0x00;
dataw[1] = 0x00;
FT260_I2CMaster_Write(mhandle1, gI2CAddr, FT260_I2C_START, &dataw, 2, &writeLength);
writeLength = 0;
len = 8;
FT260_I2CMaster_Read(mhandle1, gI2CAddr, (FT260_I2C_FLAG)(FT260_I2C_REPEATED_START | FT260_I2C_STOP),
datar, len, &readLength, 5000);
// (6)Write EEPROM
unsigned long len;
DWORD writeLength = 0;
char data[10];
char addr;
FT260_STATUS ftStatusW1, ftStatusW2 = FT260_OK;
gI2CAddr = 0x51;
writeLength = 0;
data[0] = 0x00; // Data Address MSB
data[1] = 0x00; // Data Address LSB
ftStatusW1 = FT260_I2CMaster_Write(mhandle1, gI2CAddr, FT260_I2C_START, &addr, 2, &writeLength);
data[0] = 0xAA; // Write Data
data[1] = 0x22;
data[2] = 0x33;
data[3] = 0x44;
data[4] = 0x55;
data[5] = 0x66;
data[6] = 0x77;
data[7] = 0x88;
ftStatusW2 = FT260_I2CMaster_Write(mhandle1, gI2CAddr, FT260_I2C_STOP, &data[0], 8, &writeLength);
比較難的是 I2C_FLAG 的選擇
建議是各種指令都下一次, 使用分析儀來解析其不同之處
enum FT260_I2C_FLAG
{
FT260_I2C_NONE = 0,
FT260_I2C_START = 0x02,
FT260_I2C_REPEATED_START = 0x03,
FT260_I2C_STOP = 0x04,
FT260_I2C_START_AND_STOP = 0x06
};
相關解釋可以查看AN_395_User_Guide_for_LibFT260.pdf
Page 20 4.2 I2C Master Functions
沒有留言:
張貼留言