ch341T能不能實(shí)現(xiàn)這種自定義IIC協(xié)議

20134272052929.jpg 如圖,CH341T能不能實(shí)現(xiàn)這種IIC協(xié)議,發(fā)兩個(gè)字節(jié)才收一個(gè)ACK,發(fā)送完命令以后等待18MS后再收數(shù)據(jù)。

沒有大大指點(diǎn)一下嗎?


我的意思是兩個(gè)數(shù)據(jù)間連續(xù)發(fā)送,中間沒有ACK及一個(gè)SCL。


可以實(shí)現(xiàn)! 使用下面的接口 BOOL WINAPI IIC_IssueStart( ULONG iIndex ) // 指定CH341設(shè)備序號(hào) { UCHAR mBuffer[ mCH341_PACKET_LENGTH ]; ULONG mLength; mBuffer[ 0 ] = mCH341A_CMD_I2C_STREAM; // 命令碼 mBuffer[ 1 ] = mCH341A_CMD_I2C_STM_STA; // 產(chǎn)生起始位 mBuffer[ 2 ] = mCH341A_CMD_I2C_STM_END; // 當(dāng)前包提前結(jié)束 mLength = 3; return( CH341WriteData( iIndex, mBuffer, &mLength ) ); // 寫出數(shù)據(jù)塊 }

BOOL WINAPI IIC_IssueStop( ULONG iIndex ) // 指定CH341設(shè)備序號(hào) { UCHAR mBuffer[ mCH341_PACKET_LENGTH ]; ULONG mLength; mBuffer[ 0 ] = mCH341A_CMD_I2C_STREAM; // 命令碼 mBuffer[ 1 ] = mCH341A_CMD_I2C_STM_STO; // 產(chǎn)生停止位 mBuffer[ 2 ] = mCH341A_CMD_I2C_STM_END; // 當(dāng)前包提前結(jié)束 mLength = 3; return( CH341WriteData( iIndex, mBuffer, &mLength ) ); // 寫出數(shù)據(jù)塊 }

BOOL WINAPI IIC_OutBlockSkipAck( // 輸出數(shù)據(jù)塊,不檢查應(yīng)答 ULONG iIndex, // 指定CH341設(shè)備序號(hào) ULONG iOutLength, // 準(zhǔn)備寫出的數(shù)據(jù)字節(jié)數(shù),單次必須小于29字節(jié) PVOID iOutBuffer ) // 指向一個(gè)緩沖區(qū),放置準(zhǔn)備寫出的數(shù)據(jù) { UCHAR mBuffer[ mCH341_PACKET_LENGTH ]; ULONG mLength; if ( iOutLength == 0 || iOutLength > ( mCH341_PACKET_LENGTH - 1 - 1 - 1 ) ) return( FALSE ); mBuffer[ 0 ] = mCH341A_CMD_I2C_STREAM; // 命令碼 mBuffer[ 1 ] = (UCHAR)( mCH341A_CMD_I2C_STM_OUT | iOutLength ); // 輸出數(shù)據(jù),位5-位0為長度 memcpy( &mBuffer[2], iOutBuffer, iOutLength ); // 數(shù)據(jù) mBuffer[ 1 + 1 + iOutLength ] = mCH341A_CMD_I2C_STM_END; // 當(dāng)前包提前結(jié)束 mLength = 1 + 1 + iOutLength + 1; return( CH341WriteData( iIndex, mBuffer, &mLength ) ); // 寫出數(shù)據(jù)塊 }

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 ); }

BOOL WINAPI IIC_InBlockByAck( // 輸入數(shù)據(jù)塊,每輸入一個(gè)字節(jié)都產(chǎn)生有效應(yīng)答 ULONG iIndex, // 指定CH341設(shè)備序號(hào) ULONG iInLength, // 準(zhǔn)備讀取的數(shù)據(jù)字節(jié)數(shù),單次必須小于32字節(jié) PVOID oInBuffer ) // 指向一個(gè)緩沖區(qū),返回后是讀入的數(shù)據(jù) { UCHAR mBuffer[ mCH341_PACKET_LENGTH ]; ULONG mLength, mInLen; if ( iInLength == 0 || iInLength > mCH341A_CMD_I2C_STM_MAX ) return( FALSE ); mBuffer[ 0 ] = mCH341A_CMD_I2C_STREAM; // 命令碼 mBuffer[ 1 ] = (UCHAR)( mCH341A_CMD_I2C_STM_IN | iInLength ); // 輸入數(shù)據(jù),位5-位0為長度 mBuffer[ 2 ] = mCH341A_CMD_I2C_STM_END; // 當(dāng)前包提前結(jié)束 mLength = 3; mInLen = 0; if ( CH341WriteRead( iIndex, mLength, mBuffer, mCH341A_CMD_I2C_STM_MAX, 1, &mInLen, mBuffer ) ) { // 執(zhí)行數(shù)據(jù)流命令,先輸出再輸入 if ( mInLen == iInLength ) { memcpy( oInBuffer, &mBuffer[0], iInLength ); // 數(shù)據(jù) return( TRUE ); } } return( FALSE ); }

BOOL WINAPI IIC_InByteNoAck( // 輸入一字節(jié)數(shù)據(jù),但是不產(chǎn)生應(yīng)答 ULONG iIndex, // 指定CH341設(shè)備序號(hào) PUCHAR oInByte ) // 指向一個(gè)字節(jié)的緩沖區(qū),返回后是讀入的數(shù)據(jù) { UCHAR mBuffer[ mCH341_PACKET_LENGTH ]; ULONG mLength, mInLen; mBuffer[ 0 ] = mCH341A_CMD_I2C_STREAM; // 命令碼 mBuffer[ 1 ] = mCH341A_CMD_I2C_STM_IN; // 輸入數(shù)據(jù),位5-位0為長度,0長度則只接收一個(gè)字節(jié)并發(fā)送無應(yīng)答 mBuffer[ 2 ] = mCH341A_CMD_I2C_STM_END; // 當(dāng)前包提前結(jié)束 mLength = 3; mInLen = 0; if ( CH341WriteRead( iIndex, mLength, mBuffer, mCH341A_CMD_I2C_STM_MAX, 1, &mInLen, mBuffer ) ) { // 執(zhí)行數(shù)據(jù)流命令,先輸出再輸入 if ( mInLen ) { *oInByte = mBuffer[ mInLen - 1 ]; // 數(shù)據(jù) return( TRUE ); } } return( FALSE ); }


請(qǐng)問CH341能不能用于監(jiān)聽IIC數(shù)據(jù),有沒有相就的操作軟件,能讀取IIC數(shù)據(jù),保存,發(fā)送等功能,


您好,CH341的I2C是用于作為主機(jī)使用的。也即時(shí)序是由CH341來控制,無法直接監(jiān)聽總線上的I2C數(shù)據(jù)。您需要的功能,建議考慮我司USB MCU來實(shí)現(xiàn),將I2C實(shí)現(xiàn)為設(shè)備功能,獲取USB數(shù)據(jù)然后上報(bào)給計(jì)算機(jī)。


只有登錄才能回復(fù),可以選擇微信賬號(hào)登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频