用于i2c设备的linux驱动程序 - 两个字节读取

时间:2011-05-19 05:23:24

标签: c linux i2c

我正在尝试为I2C设备编写Linux驱动程序,这似乎与典型设备略有不同。具体来说,我需要连续读取两个字节而不在其间发送停止位,如下所示:

[S] [Slave Addr | 0] [A] [Reg Addr 1] [A] [Sr] [Slave Addr | 1] [Data Byte 1] [NA]  
[Sr][Slave Addr | 0] [A] [Reg Addr 2] [A] [Sr] [Slave Addr | 1] [Data Byte 2] [NA] [P]

我已经看过几种方法,包括i2c_transfer(),i2c_master_send()和i2c_master_recv(),但我不确定他们是否会支持这些。有没有办法直接使用这些不是非常痛苦的功能?到目前为止我发现的文档在这个问题上并不完全清楚。

编辑#1:添加符号键以使其可读。感谢http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/i2c/i2c-protocol

 Key to symbols
==============

S     (1 bit) : Start bit
P     (1 bit) : Stop bit
Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA (1 bit) : Accept and reverse accept bit. 
Addr  (7 bits): I2C 7 bit address. Note that this can be expanded as usual to 
                get a 10 bit I2C address.
Comm  (8 bits): Command byte, a data byte which often selects a register on
                the device.
Data  (8 bits): A plain data byte. Sometimes, I write DataLow, DataHigh
            for 16 bit data.
Count (8 bits): A data byte containing the length of a block operation.
[..]: Data sent by I2C device, as opposed to data sent by the host adapter.

1 个答案:

答案 0 :(得分:0)

在相同的读/写操作中,字节之间不发送停止位。 i2c_master_recv可能就是你所需要的。