在不提供用户空间寄存器地址的情况下读取一个字(2 字节)

Read a word (2 byte) without providing a register address from userspace

我正在尝试从用户空间的 C 中读出一个 i2c 环境光传感器 BH1750。我正在使用带有 Linux.

的 BeagleBone 口袋

数据表说,在测量操作之后,需要使用以下 i2c 序列读取结果:S Adr Rd (A) (Data) A (Data) NA P

我 运行 的问题:所有 examples/commands 我发现要么只读取 1 个字节,要么需要寄存器地址才能读取更多。

我找到的最接近的是以下命令:i2c_master_recv()。 但是我对文档的解释是这个命令在内核设备驱动程序中使用。

如何从用户空间发出这样的 I2C 读取序列?

我能够使用 Ian Abbott 的评论解决它:

Assuming the I2C controller has been opened, and the I2C_SLAVE ioctl command has been used to set Adr, The read syscall with a length of 2 will perform the above I2C read transaction. – Ian Abbott Oct 4 at 13:45

这是生成的 I2C 通信的 Logicanalyzer-Trace: