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

802 Views Asked by At

I am trying to read out an i2c ambient light sensor BH1750 from C in userspace. I am using a BeagleBone pocket with Linux.

The Datasheet says, that after a measurement operation the result needs to be read with the following i2c sequence: S Adr Rd (A) (Data) A (Data) NA P.

The issue I ran into: All examples/commands I have found either are only reading 1 byte or are requiring a register address to read more.

The closest I found was the following command: i2c_master_recv(). However my interpretation of the documentation is that this command is used in kernel-device-drivers.

How can I issue such a I2C-Read-Sequence from Userspace?

1

There are 1 best solutions below

3
On BEST ANSWER

I was able to solve it using this comment from 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

Here is a Logicanalyzer-Trace of the resulting I2C communication:

trace