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.

Using I2C

Hi,

I'm finding accessing I2C from user space on the EVM365 thoroughly confounding. I've been reading .../Documentation/i2c and that hasn't been much help.

To begin with the constant to set SLAVE_ADDRESS via ioctl()  is defined in <linux/i2c.h> rather than <i2c-dev.h>. I thought the former was to be used by kernel drivers.

Looking through <linux/i2c.h> I can see the smbus calls that I would like to use but they take a structure not a file descriptor as their first argument.

What I would like to do is read from a register-based device. For instance I'd like to read a 16-bit value at register 0x00 (version).

Since I was able to open the i2c-0 device and it appeared to set the slave address I then tried (guessing) to read three bytes and set the first byte as the register address of interest. Not surprisingly, this did not work. Can someone point me to some good examples?

Thanks,

Ken

  • I used the attached program on DM6446, it should work for DM365 (provided appropriate i2c and device are used) but I have not given it a try.

    i2ctest.zip
  • Thanks Juan. I didn't think to call write() to set the target subaddress and then read to acquire the bytes. Seems to work just fine on the EVM365. Works for devices that behave like EEPROMs anyway which is what I care about.

    I copied your "i2c-dev.h" header locally. Do you have any idea why the EVM365 system version of this header does not include the definition for I2C_SLAVE (for ioctl())? There is a comment that says some of the ioctl() commands are defined in "i2c.h" but it does not seem like the correct location.

    .../linux/include/i2c-dev.h:

    #ifndef _LINUX_I2C_DEV_H
    #define _LINUX_I2C_DEV_H

    #include <linux/types.h>
    #include <linux/compiler.h>

    /* Some IOCTL commands are defined in <linux/i2c.h> */
    /* Note: 10-bit addresses are NOT supported! */

    /* This is the structure as used in the I2C_SMBUS ioctl call */
    struct i2c_smbus_ioctl_data {
        __u8 read_write;
        __u8 command;
        __u32 size;
        union i2c_smbus_data __user *data;
    };

    /* This is the structure as used in the I2C_RDWR ioctl call */
    struct i2c_rdwr_ioctl_data {
        struct i2c_msg __user *msgs;    /* pointers to i2c_msgs */
        __u32 nmsgs;            /* number of i2c_msgs */
    };

    #define  I2C_RDRW_IOCTL_MAX_MSGS    42

    #endif /* _LINUX_I2C_DEV_H */

    Ken

  • Both of these header files (i2c-dev.h and i2c.h) are part of the standard Linux Kernel.  I am not sure why they decided to move the definitions around (verified I2C_SLAVE has been moved to i2c.h), but I believe this is likely a difference between MV4 and MV5 as neither of these two files is specific to DM365.  If you are going to work with MV5 kernel moving forward, I would probrably use the header files included in this version of the kernel.