|
发表于 2020-6-29 09:39:02
|
显示全部楼层
PC 这边的程序很简单,这样写行不行,能给个 10bit 操作的例子吗? Demo 里面都是 7 bit的:
uint8_t rw_buffer[65536] = { 0 };
int _tmain(int argc, _TCHAR* argv[])
{
int ret, i;
VII_INIT_CONFIG I2C_Config;
VII_BOARD_INFO BoardInfo;
uint16_t SlaveReadLen;
//Scan device
ret = VII_ScanDevice(1);
if (ret <= 0) {
printf("No device connect!\n");
return ret;
}
//Open device
ret = VII_OpenDevice(VII_USBI2C, 0, 0);
if (ret != ERR_SUCCESS) {
printf("Open device error!\n");
return ret;
}
//Get product information
ret = VII_ReadBoardInfo(0, &BoardInfo);
if (ret != ERR_SUCCESS) {
printf("Read board information error!\n");
return ret;
}
else {
printf("Product Name:%s\n", BoardInfo.ProductName);
printf("Firmware Version:V%d.%d.%d\n", BoardInfo.FirmwareVersion[1], BoardInfo.FirmwareVersion[2], BoardInfo.FirmwareVersion[3]);
printf("Hardware Version:V%d.%d.%d\n", BoardInfo.HardwareVersion[1], BoardInfo.HardwareVersion[2], BoardInfo.HardwareVersion[3]);
printf("Serial Number:");
for (i = 0; i < 12; i++) {
printf("%02X", BoardInfo.SerialNumber);
}
printf("\n");
}
//Initializes the device
I2C_Config.AddrType = VII_ADDR_10BIT;
I2C_Config.ClockSpeed = 400000;
I2C_Config.ControlMode = VII_HCTL_SLAVE_MODE;
I2C_Config.MasterMode = VII_SLAVE;
I2C_Config.SubAddrWidth = VII_SUB_ADDR_NONE;
I2C_Config.Addr = 0xA0; //Must be set,very important
ret = VII_InitI2C(VII_USBI2C, 0, 0, &I2C_Config);
if (ret != ERR_SUCCESS) {
printf("Initialize device error!\n");
return ret;
}
while (1) {
Sleep(5);
SlaveReadLen = 1;
ret = VII_SlaveReadBytes(VII_USBI2C, 0, 0, rw_buffer, &SlaveReadLen);
if ((ret == ERR_SUCCESS) && (SlaveReadLen > 0)) {
ret = VII_SlaveWriteBytes(VII_USBI2C, 0, 0, rw_buffer, SlaveReadLen);
if (ret != ERR_SUCCESS) {
printf("Slave write data error!\n");
return ret;
}
printf("Slave read data %ld bytes, already rollback!\n", SlaveReadLen);
continue;
}
if (ret == ERR_READ_NO_DATA) {
continue;
}
else {
printf("Slave read data error!\n");
return ret;
}
}
return 0;
}
补充内容 (2020-6-29 09:42):
这样的 LOOP BACK 小测试程序,我们用来测试 7bit 读写, 10bit 写都是对的,唯独 10bit 读就不对 |
|