LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   Adding I2C devices for embedded 4.9.89 linux (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/adding-i2c-devices-for-embedded-4-9-89-linux-4175659026/)

StevenJC 08-12-2019 12:10 PM

Adding I2C devices for embedded 4.9.89 linux
 
Having trouble talking to new devices. From user space:
Code:

const char *i2cDevice1 = "/dev/i2c-1";
 int i2cAddr = 0x59;
 int fdI2c1 = open(i2cDevice1, O_RDWR); /* this works */
 if (ioctl(fdI2c1, I2C_SLAVE, i2cAddr) < 0) {
    printf("I2C Error 2. Bye.\n");
    return 0;
 }                                      /* this works */
 if (write(fdI2c1, buf, 2) != 2) {
    printf("I2C Error 3. Bye.\n");
    return 0;
  }                                    /* this FAILS */

Tried simply tweaking the Device Tree Source (.dts file) in linux-4.9.89/arch/arm/boot/dts by adding max3107 block below:
Code:

&i2c2 {
        clock-frequency = <400000>;
        max3107@58 {
                      compatible = "maxim, 3107";
                      reg = <0x58>;
                  };
};

and rebuilt kernel and dtb. This did not seem to do anything since I still get the same error from my code and the i2cdetect utility still doesn't see a device 0x59.

Code:

# i2cdetect -y -r 1
    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Suggestions?


All times are GMT -5. The time now is 10:33 AM.