This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

A more comprehensive I2C API?

I have been porting a piece of code that talks to several I2C peripherals to Linux on an OMAP L137.  I'm using the community Linux, and I want to work from user mode.  I've been using the i2c_smbus functions, and I've got things generally working.  But I notice some things that are less than ideal.

1)  There appears to be no function that puts out one address and then reads multiple bytes of data:  ie:

    addr (r), data, data, data ...

Instead they implement 

    addr(r), command, data, data ...

2)  The functions that put out multiple bytes of data all want to have a "command" byte up front. 

   addr(w), command, data, data

That would be OK, but looking on a scope, I think I see that the command byte goes out twice!

So far, everything seems to be working using single byte read and write in loops. But that's not ideally efficient.  

Does this look familiar to anyone?  I wouldn't mind contributing to driver updates of some sort to improve this.

  • Not quite sure if you are asking about kernel space or user space access to I2C. The user space interface via /dev/i2c-* behaves differently than you described. Its model hides the device address and does not assume a command byte. Everything is data. Repeated starts are not supported through read()/write() but are supported via ioctl(). The /dev/i2c interface has been around for quite a while. It should be the same from 2.6.18 to 2.6.37.

  • I found that the i2c_smbus_access() function could do what I need.  I have to use the I2C_SMBUS_I2C_BLOCK_BROKEN command:

            retval = i2c_smbus_access(I2C_fd, I2C_SMBUS_WRITE, cByte, I2C_SMBUS_I2C_BLOCK_BROKEN, &smData);
    Then the cByte command is the first byte written after the address, and smData.block[0] is the count, which is NOT written out.