Menu

Enabling I2C2 on the BeagleBone Black

Connecting the Wii nunchuck to the BeagleBone Black is a little more complicated that connecting it to the BeagleBone White.

The wiring is the same but the header pins P9.19 and P9.20 must be appropriately muxed using a Device Tree Overlay.

First, create the file "/lib/firmware/BB-I2C2-00A0.dts" with the following content (credit goes to Stephen Wolfe):

/dts-v1/;
/plugin/;

/ {
       compatible = "ti,beaglebone", "ti,beaglebone-black";

        /* identification */
        part-number = "BB-I2C2";
        version = "00A0";

        /* state the resources this cape uses */
        exclusive-use =
                /* the pin header uses */
                "P9.20",        /* i2c2_sda */
                "P9.19",        /* i2c2_scl */
                /* the hardware ip uses */
                "i2c2";

        fragment@0 {
                target = <&am33xx_pinmux>;
                __overlay__ {
                        bb_i2c2_pins: pinmux_bb_i2c2_pins {
                                pinctrl-single,pins = <
                                        0x178 0x73    // spi0_d1.i2c2_sda,  SLEWCTRL_SLOW | IMPUT_PULLUP | MODE3
                                        0x17c 0x73    // spi0_cs0.i2c2_scl, SLEWCTRL_SLOW | INPUT_PULLUP | MODE3
                                >;
                        };
                };
        };

        fragment@1 {
                target = <&i2c2>;    /* i2c2 is numbered correctly */
                __overlay__ {
                        status = "okay";
                        pinctrl-names = "default";
                        pinctrl-0 = <&bb_i2c2_pins>;

                        /* this is the configuration part */
                        clock-frequency = <100000>;

                        #address-cells = <1>;
                        #size-cells = <0>;
                };
        };
};

Then compile the overlay using the following command:

#  dtc -O dtb -o /lib/firmware/BB-I2C2-00A0.dtbo -b 0 -@ /lib/firmware/BB-I2C2-00A0.dts

Next, export the overlay:

# cd /sys/devices/bone_capemgr.*
# echo "BB-I2C2" >slots

The new overlay should now be available:

# cat slots
 0: 54:PF---
 1: 55:PF---
 2: 56:PF---
 3: 57:PF---
 4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
 5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
 9: ff:P-O-L Override Board Name,00A0,Override Manuf,BB-I2C2

The I2C2 interface can then be accessed as before via the "/dev/i2c-1" device file, using the same connections and software as in the BeagleBone White.

Note that the Device Tree overlay is only in place until it is removed or the BBB is shutdown. It will have to be re-exported next time the BeagleBone Black is rebooted. If you wish to have this overlay automatically exported at boot time, see the instructions at the bottom of this page.

Posted by Janick Bergeron 2014-05-28

Log in to post a comment.