WRTnode add i2c support

From WRTnode Wiki Site
Jump to: navigation, search
This page contains changes which are not marked for translation.

Other languages:
English 100% • ‎中文(中国大陆)‎ 100%

Because the i2c driver is not stable, so we recommend use gpio simulation i2c
1:Edit file WRTNODE.dts (located in target/linux/ramips/dts/) and add following code:

$vim WRTNODE.dts  
palmbus@10000000 {
 ... ... 
 i2c@900 {
            compatible = "ralink,mt7620n-i2c", "ralink,rt2880-i2c";
            reg = <0x900 0x100>;
            resets = <&rstctrl 16>;
            reset-names = "i2c";
            #address-cells = <1>;
            #size-cells = <0>;
            pinctrl-names = "default";
            pinctrl-0 = <&i2c_pins>;
            status = "okay";
        };
   ... ...
};

2:Edit WRTNODE.dts by removing "i2c" ralink.group:
Original code:

pinctrl {
     state_default: pinctrl0 {
                   default {
                       ralink,group = "ephy", "wled", "pa", "i2c", "wdt", "uartf" ,"spi refclk";
                       ralink,function = "gpio";
                   };
             };
   };

After modifying the code:

pinctrl {
     state_default: pinctrl0 {
                   default {
                       ralink,group = "ephy", "wled", "pa", "wdt", "uartf" ,"spi refclk";
                       ralink,function = "gpio";
                   };
               };
     i2c_pins: i2c {
                    i2c {
                        ralink,group = "i2c";
                       ralink,function = "i2c";
                     };
                 };
    };

3: I2C configuration

$make menuconfig

I2c8.png

I2c9.png

Rei2c10.png

4: Compile

$make

5: Refresh Firmware
Load the new firmware in WRTnode and perform the following operations on WRTnode:

$cd /lib/modules/$(kernel-version)
$insmod i2c-dev.ko
$cd /dev
$ls 

I2c6.png

Now you should see the i2c-0

$ls -all i2c-0

I2c7.png

Now I2C was added succesfully to the WRTnode board.
6: Install i2c-tools(i2cdetect,i2cdump,i2cget,i2cset)

$opkg update
$opkg install i2c-tools

Assuming connect the slave device mpu6050.
For example: Read the value of the register

$i2cget -y 0 0x68 0x6b

For example: Write the value of the register

$i2cset -y 0 0x68 0x6b 0x80

0:/dev/i2c-0
0x68: slave device address
0x6b: register
0x80: the value written to the register 0x6b
dev is the abbreviation of device. /dev directory is very important for all users because this directory contains the external devices used in all Linux systems. It is actually the link to the port of the external devices. Therefore accessing these devices it is a very simple task similar to accessing a file or a directory.