現(xiàn)在設(shè)備地址存在兩個(gè),一個(gè)是0x1A,一個(gè)是0x1B,有什么方案可以去做應(yīng)答位的檢測嗎?
您好,可參考如下blog:https://blog.csdn.net/WCH_TechGroup/article/details/130932558?
使用如下接口函數(shù)可實(shí)現(xiàn):
BOOL WINAPI IIC_OutByteCheckAck( // 輸出一字節(jié)數(shù)據(jù)并檢查應(yīng)答是否有效
ULONG iIndex, // 指定CH341設(shè)備序號(hào)
UCHAR iOutByte ) // 準(zhǔn)備寫出的數(shù)據(jù)
{
UCHAR mBuffer[ mCH341_PACKET_LENGTH ];
ULONG mLength, mInLen;
mBuffer[ 0 ] = mCH341A_CMD_I2C_STREAM; // 命令碼
mBuffer[ 1 ] = mCH341A_CMD_I2C_STM_OUT; // 輸出數(shù)據(jù),位5-位0為長度,0長度則只發(fā)送一個(gè)字節(jié)并返回應(yīng)答
mBuffer[ 2 ] = iOutByte; // 數(shù)據(jù)
mBuffer[ 3 ] = mCH341A_CMD_I2C_STM_END; // 當(dāng)前包提前結(jié)束
mLength = 4;
mInLen = 0;
if ( CH341WriteRead( iIndex, mLength, mBuffer, mCH341A_CMD_I2C_STM_MAX, 1, &mInLen, mBuffer ) ) { // 執(zhí)行數(shù)據(jù)流命令,先輸出再輸入
if ( mInLen && ( mBuffer[ mInLen - 1 ] & 0x80 ) == 0 ) return( TRUE ); // 返回的數(shù)據(jù)的位7代表ACK應(yīng)答位,ACK=0有效
}
return( FALSE );