I2C传输大小问题

来源:互联网 发布:淘宝购买账号安全吗 编辑:程序博客网 时间:2024/06/08 03:46

一次 I2C transfer有两种模式:单开始信号和重复开始信号。

每个硬件平台不同,I2C 控制器限制了一次 I2C transfer的大小。例如MTK平台:最大不能超过8字节。

在调试每一个I2C device时候,需要根据I2C device datasheet的要求:如果必须在一次transfer内传输一个块数据(大于8字节)的话,则只能使用I2C DMA传输。但是有些硬件平台支持:一次I2C transfer传输更多的数据,例如255字节等。这样就不需要DMA传输了。

把一个255字节块数据分割成8字节块数据传输是有问题的。因为每一个8字节块都需要i2c_msg来传输。但是构造i2c_msg对象时需要设置设备地址,读写模式等。所以分割后的8字节块数据是有问题的。


函数解释:

i2c_transfer();

执行一个或多个i2c msgs。在触发STOP信号之前,执行多个i2c msgs,每一个i2c msg以START信号开始。


i2c_msgs

 * Except when I2C "protocol mangling" is used, all I2C adapters implement
 * the standard rules for I2C transactions.  Each transaction begins with a
 * START.  That is followed by the slave address, and a bit encoding read
 * versus write.  Then follow all the data bytes, possibly including a byte
 * with SMBus PEC.  The transfer terminates with a NAK, or when all those
 * bytes have been transferred and ACKed.  If this is the last message in a
 * group, it is followed by a STOP.  Otherwise it is followed by the next
 * @i2c_msg transaction segment, beginning with a (repeated) START.





0 0
原创粉丝点击