[求助]关于mCH341A_CMD_I2C_STM_OUT这一控制命令

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的长度是怎么定义的呢?

问题已经解决了,是我自己的程序有问题,应该是发N个字节就用mCH341A_CMD_I2C_STM_OUT| N


顶!!


发N个字节就用mCH341A_CMD_I2C_STM_OUT| N,在你的程序中不是7个字节吗? 怎么要用mCH341A_CMD_I2C_STM_OUT| 6才可以呢?? 奇怪啊!! 你能说说是怎么解决的吗??


应该是mCH341A_CMD_I2C_STM_OUT|7才对啊!! 怎么会一定要mCH341A_CMD_I2C_STM_OUT|6才可以正确执行呢!!?? 你是怎么作的??


原来的程序有错误,所以用mCH341A_CMD_I2C_STM_OUT|6才能通过.


楼主程序中mLength = 11;应该是12而不是11, 如果是普通的EEPROM,建议用现成的Read/WriteEEPROM效率高


对啊!mLength = 12 还有什么错误会导致只能用mCH341A_CMD_I2C_STM_OUT|6,而不是mCH341A_CMD_I2C_STM_OUT|7呢? 实在想不出还有什么错误了!!呵呵


只有登录才能回复,可以选择微信账号登录