請(qǐng)教CH341!

在貴公司的資料下載里看到一個(gè)EXAM.C文件: 中有下面四個(gè)子函數(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 ); }

/* ********************************************************************************************** */

請(qǐng)問(wèn),其中檢查ACK的兩個(gè)函數(shù)中ACK是一個(gè)字節(jié)還是一位? 現(xiàn)在碰到這樣的問(wèn)題: _____ _______ __________________________________ |___| |____| ACK 我在開發(fā)時(shí)的芯片在受到一個(gè)ACKbit后立即要發(fā)一個(gè)BYTE,這種情況能否直接調(diào)用:IIC_InBlockByAck 這樣的函數(shù)? [Emot]4[/Emot] 請(qǐng)教各位前輩!謝謝啦!

應(yīng)答信號(hào)ack是位。IIC總線上的第9個(gè)時(shí)鐘脈沖對(duì)應(yīng)于應(yīng)答位,相應(yīng)數(shù)據(jù)線上低電平時(shí)為“應(yīng)答” 信號(hào),高電平時(shí)為“非應(yīng)答”信號(hào)。 當(dāng)然可以!


呵呵,跟我們的問(wèn)題很像啊

這樣一個(gè)時(shí)序, ...|A1|A0|R/W|ACK|D7|D6|D5|... 地址幀 |ACK| 數(shù)據(jù)幀 用下面的程序可不可以呢?謝謝大俠!

IIC_IssueStart(iIndex); //Master發(fā)起始位 IIC_OutByteCheckAck(iIndex,0x**); //Master發(fā)地址幀 //slaver發(fā)ACK握手信號(hào)0(bit) IIC_InBlockByAck(iIndex,1, pt_inbuffer++); //slaver發(fā)高四位;Master將數(shù)據(jù)收入inbuffer[0],master產(chǎn)生ACK, IIC_IssueStop(iIndex); //master發(fā)停止位


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

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