EXAM.C里很多地方都用到了I2C接口的命令流:mCH341A_CMD_I2C_STM_OUT
這個(gè)命令流在CH341DLL.H中的注釋是:I2C接口的命令流:輸出數(shù)據(jù),位5-位0為長(zhǎng)度,后續(xù)字節(jié)為數(shù)據(jù),0長(zhǎng)度則只發(fā)送一個(gè)字節(jié)并返回應(yīng)答。
我自己編寫了一個(gè)簡(jiǎn)單的往24c02里寫數(shù)據(jù)的函數(shù)如下: BOOL WriteEEPROM( ULONG iIndex) { UCHAR mBuffer[ mCH341_PACKET_LENGTH ]; ULONG mLength; mBuffer[ 0 ] = mCH341A_CMD_I2C_STREAM; mBuffer[ 1 ] = mCH341A_CMD_I2C_STM_STA; mBuffer[ 2 ] = (UCHAR)(mCH341A_CMD_I2C_STM_OUT| 6);
mBuffer[ 3 ] = 0xa0; //控制碼
mBuffer[ 4 ] = 0x00; // 雙字節(jié)地址 mBuffer[ 5 ] = 0x00; mBuffer[ 6 ] = 0x11; // 數(shù)據(jù) mBuffer[ 7 ] = 0x22; mBuffer[ 8 ] = 0x33; mBuffer[ 9 ] = 0x44;
mBuffer[ 10 ] = mCH341A_CMD_I2C_STM_STO; mBuffer[ 11 ] = mCH341A_CMD_I2C_STM_END; mLength = 11; CH341WriteData( iIndex, mBuffer, &mLength ); } 該函數(shù)可以從EEPROM的起始位置寫入數(shù)據(jù) 11223344。中間從 mBuffer[ 3 ]~ mBuffer[ 9 ] 的地方共有7個(gè)數(shù)據(jù),而經(jīng)過(guò)測(cè)試,只有用mCH341A_CMD_I2C_STM_OUT|6 才能正常寫入,如果用mCH341A_CMD_I2C_STM_OUT|7 是不行的。 可是在EXAM.C中,好象凡是發(fā)送N個(gè)數(shù)據(jù)的地方,都是用的mCH341A_CMD_I2C_STM_OUT| N,那么到底 mCH341A_CMD_I2C_STM_OUT的長(zhǎng)度是怎么定義的呢?