I2C Issues

Moderator: nferre

spastor
Posts: 2
Joined: Mon Sep 23, 2019 12:59 pm

I2C Issues

Mon Dec 09, 2019 11:12 am

Hello colleagues:
I'm writing this post to share a problem I found and solved, in case it is helpful for others dealing with similar problem.
I have an ATSAMA5D27-SOM1-EK1 and I am evaluating a custom board that communicates through I2C with the following devices, all connected to the board's mikroBUS1/2 I2C bus (/dev/i2c-2 in linux):
  • 1 x INA226 (I2C Addr 0x40)
  • 1 x ADC TLA2024 (I2C Addr 0x48)
  • 2 x MCP23018 GPIO Expander.
Long story short: the MCP23018 worked fine at first attempt, while the INA226 and the ADC didn't. The i2cdetect tool and the i2cget were actually detecting the devices in the bus but the linux drivers failed to load with a -121 (Remote I/O error).

Code: Select all

root[AT]sama5d27-som1-ek-sd:~# dmesg | grep ads
[    1.505977] ads1015: probe of 2-0048 failed with error -121
root[AT]sama5d27-som1-ek-sd:~# dmesg | grep ina
[    1.268378] ina2xx 2-0040: error configuring the device: -121

Code: Select all

root[AT]sama5d27-som1-ek-sd:~# i2cdetect 2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2.
I will probe address range 0x03-0x77.
Continue? [Y/n]
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: UU UU -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: 40 -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
The tools detecting it and the GPIO expander working fine pointed more towards a software/configuration problem than a hardware one.

The fix was to add the following line into the I2C's device-tree declaration:

Code: Select all

i2c-sda-hold-time-ns = <350>
The description provided by the device-tree binding documentation does not tell very much, but further reading on the INA226's datasheet and some investigation (like this AN from Cypress) points that it does make sense for it to be the culprit.

My tests were done with the ATSAMA5D27-SOM1-EK1 board and a custom board to evaluate the aforementioned ICs. Software was the linux4sam-poky-sama5d27_som1_ek-graphics-6.2.img.bz2 (from linux4sam_6.2 tag) with of course my custom build of the kernel with the INA226 hwmon, ADS1015 (there is no native TLA2024 driver, but this is "compatible") and the MCP23018 drivers. And my custom device-tree with the modifications for adding the devices in the I2C and the i2c-sda-hold-time-ns = <350>; line.

File: linux-at91/arch/arm/boot/dts/at91-sama5d27_som1_ek.dts

Code: Select all

            flx1: flexcom[AT]f8038000 {
                atmel,flexcom-mode = <ATMEL_FLEXCOM_MODE_TWI>;
                status = "okay";

                i2c2: i2c[AT]600 {
                    compatible = "atmel,sama5d2-i2c";
                    reg = <0x600 0x200>;
                    interrupts = <20 IRQ_TYPE_LEVEL_HIGH 7>;
                    dmas = <0>, <0>;
                    dma-names = "tx", "rx";
                    #address-cells = <1>;
                    #size-cells = <0>;
                    clocks = <&flx1_clk>;
                    pinctrl-names = "default";
                    pinctrl-0 = <&pinctrl_mikrobus_i2c>;
                    atmel,fifo-size = <16>;
                    i2c-sda-hold-time-ns = <350>;
                    status = "okay";
                    
                    gpiom1: gpio[AT]20 {
                            compatible = "microchip,mcp23018";
                            gpio-controller;
                            #gpio-cells = <2>;
                            reg = <0x20>;
                    };
                    gpiom2: gpio[AT]21 {
                            compatible = "microchip,mcp23018";
                            gpio-controller;
                            #gpio-cells = <2>;
                            reg = <0x21>;
                            pinctrl-names = "default";
                            pinctrl-0 = <&pinctrl_mikrobus_i2c &gpio21pullups>;

                            gpio21pullups: pinmux {
                                pins =    "gpio0", "gpio1", "gpio2", "gpio3",
                                    "gpio4", "gpio5", "gpio6", "gpio7",
                                    "gpio8", "gpio9", "gpio10", "gpio11",
                                    "gpio12", "gpio13", "gpio14", "gpio15";
                                bias-pull-down;
                            };
                    };
                    ina226[AT]40 {
                        compatible = "ti,ina226";
                        reg = <0x40>;
                        shunt-resistor = <1000>;
                    };
                    
                    ads1015[AT]48 {
                        compatible = "ti,ads1015";
                        reg = <0x48>;
                        #address-cells = <1>;
                        #size-cells = <0>;

                        channel[AT]1 {
                            reg = <4>;
                            ti,gain = <3>;
                            ti,datarate = <5>;
                        };
                    };

                };
            };
I hope someone else finds this useful :)
nferre
Site Admin
Posts: 214
Joined: Wed Feb 14, 2007 11:17 am

Re: I2C Issues

Mon Dec 09, 2019 1:09 pm

Hi,

Note that we added very recently in both Mainline Linux and our linux-4.19-at91 branch, the support for analog and digital filters for this I2C controller. It can be handy for streamlining the communication with some of the I2C slaves out there.

You can find more information in the associated discussion on the mailing-list:
https://lore.kernel.org/linux-arm-kerne ... ochip.com/

Note that DT binding on our linux-4.19-at91 branch is slightly different than the one we agreed upon on Mainline.

Thanks you @spastor for having shared with us your finding, it's highly appreciated!
Nicolas

Return to “SAMA5-based”

Who is online

Users browsing this forum: No registered users and 3 guests