由于设备准备数据耗时比较长,用CH341控制时需要在写入设备地址后等待SDA变低后再去读寄存器。
public static bool WriteReadI2C1(UInt32 iIndex, byte iDevice, byte iAddr, ref byte iByte) //读8位寄存器 { uint i = 0, iStatus = CH341DLL.mStateBitSDA; byte[] iOutBuffer = new byte[2] { iDevice, iAddr }; //设备写地址+寄存器地址 byte iDevice2 = (byte)(iDevice | 1); //设备读地址 IIC_OutBlockSkipAckStart(iIndex, 2, iOutBuffer); //Start+写16bit IIC_OutByteCheckAckStart(iIndex, iDevice2); //Restart+写8bit while (i < 100) //等待SDA变低 { CH341DLL.CH341GetInput(iIndex, ref iStatus); if ((iStatus & CH341DLL.mStateBitSDA) == 0) break; i++; } return IIC_InByteNoAckStop(iIndex, ref iByte); //读8bit+Stop }
请问用CH347能否实现类似功能?
热门产品 :
CH32L103: 32位PDUSB低功耗单片机