EXAM.C里很多地方都用到了I2C接口的命令流:mCH341A_CMD_I2C_STM_OUT
这个命令流在CH341DLL.H中的注释是:I2C接口的命令流:输出数据,位5-位0为长度,后续字节为数据,0长度则只发送一个字节并返回应答。
我自己编写了一个简单的往24c02里写数据的函数如下: 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; // 双字节地址 mBuffer[ 5 ] = 0x00; mBuffer[ 6 ] = 0x11; // 数据 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 ); } 该函数可以从EEPROM的起始位置写入数据 11223344。中间从 mBuffer[ 3 ]~ mBuffer[ 9 ] 的地方共有7个数据,而经过测试,只有用mCH341A_CMD_I2C_STM_OUT|6 才能正常写入,如果用mCH341A_CMD_I2C_STM_OUT|7 是不行的。 可是在EXAM.C中,好象凡是发送N个数据的地方,都是用的mCH341A_CMD_I2C_STM_OUT| N,那么到底 mCH341A_CMD_I2C_STM_OUT的长度是怎么定义的呢?