CH341中關(guān)于CH341WriteRead的I2C時(shí)序

1. 在檢查CH341StreamI2C的部分源碼后,好像是需要手動(dòng)發(fā)START/STOP的,但是之前打電話詢問(wèn)的時(shí)候,給我的答案是CH341WriteRead可以自動(dòng)產(chǎn)生START/STOP位,無(wú)需手動(dòng)發(fā)送。

不知道哪種調(diào)用CH341WriteRead,需要在手動(dòng)的產(chǎn)生START/STOP(就是在寫buffer里面增加START/STOP的內(nèi)容)?

2. CH341WriteRead的iReadStep參數(shù)是否可以為指定的讀寫長(zhǎng)度,而非mCH341A_CMD_I2C_STM_MAX?

3. CH341WriteRead回傳到指定讀buffer的內(nèi)容是純粹的I2C幀內(nèi)容,還是有帶其他的USB幀的內(nèi)容?例如讀長(zhǎng)度為0byte(實(shí)際上是用于寫的ACK檢查)就回讀一個(gè)byte包含ACK內(nèi)容。但是如果是從I2C上面讀10byte,回讀到buffer里面的內(nèi)容是純粹的I2C總線回傳的數(shù)據(jù),還是有帶USB幀的封裝包其他數(shù)據(jù)?


熱門產(chǎn)品 : USB3.0 HUB控制器:CH634

1-我們推薦您使用CH341StreamI2C來(lái)處理I2C數(shù)據(jù)流,CH341StreamI2C是通過(guò)調(diào)用CH341WriteRead來(lái)寫、讀指定的i2c命令來(lái)產(chǎn)生i2c時(shí)序


之前的帖子http://wch.cn/bbs/View.asp?T=1&S=101&I=52582 不是說(shuō)CH341StreamI2C不支持ACK回復(fù)嗎?


那你應(yīng)該使用該帖子的方法實(shí)現(xiàn)i2c通訊 請(qǐng)使用下面的函數(shù)替換 /* ********************************************************************************************** */ /* 例子:兼容IIC總線的通用操作時(shí)序 */

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為長(zhǎng)度 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為長(zhǎng)度,0長(zhǎng)度則只發(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為長(zhǎ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 == 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為長(zhǎng)度,0長(zhǎng)度則只接收一個(gè)字節(jié)并發(fā)送無(wú)應(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 ); }


那使用上面方法的時(shí)候,要發(fā)送數(shù)據(jù)的時(shí)候是只要直接調(diào)用IIC_OutByteCheckAck等讀寫操作函數(shù),還是必須得同時(shí)調(diào)用IIC_IssueStart/Stop函數(shù)來(lái)操作時(shí)序(實(shí)際上就是我問(wèn)的第一個(gè)問(wèn)題)


必須得同時(shí)調(diào)用IIC_IssueStart/Stop函數(shù)來(lái)操作時(shí)序


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

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