bbb i2c (rtc and eeprom) - victronenergy/venus GitHub Wiki

On the ve-cape, there are two i2c devices:

  • Used RTC: NXP PCF8523T @ 0x68
  • Used EEPROM: CAT24C256WI-GT3 (the typically used cape eeprom) @ 0x57

They are connected to i2c-1. Which can also be referred to as i2c2 depending on the first i2c channel number... u-boot starts at 1, kernel overlay starts at 0. The used bus is the second one.

NOTE! The used IC on REV2 PCB 6/10 is the PCF85263A RTC chip (@ 0x51), which is wrong. Some of the cape protos have been modified, see bbb ve cape revisions.

boot log

With a cape connected, boot log looks like this:

...
[    0.330903] omap_i2c 44e0b000.i2c: could not find pctldev for node /ocp/l4_wkup@44c00000/scm@210000/pinmux@800/pinmux_i2c0_pins, deferring probe
[    0.331004] omap_i2c 4802a000.i2c: could not find pctldev for node /ocp/l4_wkup@44c00000/scm@210000/pinmux@800/pinmux_i2c1_pins, deferring probe
...
[    1.455782] i2c /dev entries driver
[    1.459530] Driver for 1-wire Dallas network protocol.
...
[    1.716314] omap_i2c 44e0b000.i2c: bus 0 rev0.11 at 400 kHz
...
[    1.768518] rtc-pcf8523 1-0068: rtc core: registered rtc-pcf8523 as rtc0
[    1.776177] at24 1-0057: 32768 byte 24c256 EEPROM, writable, 1 bytes/write
[    1.783441] omap_i2c 4802a000.i2c: bus 1 rev0.11 at 400 kHz
...
[    1.897552] rtc-pcf8523 1-0068: setting system clock to 2016-09-15 07:31:50 UTC (1473924710)
...

i2c-tools

For debugging enable i2c-tools package in the build to allow scanning of i2c buses.

There are two places where the pinmux for the chip need to be initialised

  1. u-boot
  2. kernel device tree

u-boot

Configuring of the i2c channel is done in the board.h file.

The following patch needs to be applied:

--- git/board/ti/beagle/beagle_orig.h	2016-05-27 11:32:32.857965031 -0700
+++ git/board/ti/beagle/beagle.h	2016-05-24 14:18:57.223463477 -0700
@@ -246,8 +246,8 @@
 	MUX_VAL(CP(HSUSB0_DATA7),	(IEN  | PTD | DIS | M0)) /*HSUSB0_DATA7*/\
 	MUX_VAL(CP(I2C1_SCL),		(IEN  | PTU | EN  | M0)) /*I2C1_SCL*/\
 	MUX_VAL(CP(I2C1_SDA),		(IEN  | PTU | EN  | M0)) /*I2C1_SDA*/\
-	MUX_VAL(CP(I2C2_SCL),		(IEN  | PTU | EN  | M0)) /*I2C2_SCL*/\
-	MUX_VAL(CP(I2C2_SDA),		(IEN  | PTU | EN  | M0)) /*I2C2_SDA*/\
+	MUX_VAL(CP(I2C2_SCL),		(IEN  | PTU | EN  | M2)) /*I2C2_SCL*/\
+	MUX_VAL(CP(I2C2_SDA),		(IEN  | PTU | EN  | M2)) /*I2C2_SDA*/\
 	MUX_VAL(CP(I2C3_SCL),		(IEN  | PTU | EN  | M0)) /*I2C3_SCL*/\
 	MUX_VAL(CP(I2C3_SDA),		(IEN  | PTU | EN  | M0)) /*I2C3_SDA*/\
 	MUX_VAL(CP(I2C4_SCL),		(IEN  | PTU | EN  | M0)) /*I2C4_SCL*/\

kernel config

The PCF8523 needs enabling in the kernel config, this can be done by using the method appropriate for the build system used to run the kernel menuconfig. The CONFIG_RTC_DRV_PCF8523 option needs enabling to facilitate the correct driver to be built.

kernel device tree

Enable desired i2c channel in dts overlay: The kernel uses a device tree binary blob to configure the desired i/o and makes it easier to make configuration changes during development. For the AM335x the dts files are stored in arch/arm/boot/dts folder.

bbb-venus.dts needs patching with:

--- arch/arm/boot/dts/bbb-venus_orig.dts	2016-05-27 11:38:34.848079637 -0700
+++ arch/arm/boot/dts/bbb-venus.dts	2016-05-27 05:05:48.113294888 -0700
@@ -22,6 +22,16 @@
 	compatible = "ti,am335x-bone-black", "ti,am33xx";
 };
 
+&am33xx_pinmux {
+	pinctrl-names = "default";
+
+	i2c1_pins: pinmux_i2c1_pins {
+		pinctrl-single,pins = <
+			0x158 (PIN_INPUT | MUX_MODE2)	/* spi0_d1.i2c1_sda */
+			0x15C (PIN_INPUT | MUX_MODE2)	/* spi0_cs0.i2c1_scl */
+		>;
+	};
+};
 &ldo3_reg {
 	regulator-min-microvolt = <1800000>;
 	regulator-max-microvolt = <1800000>;
@@ -47,3 +57,15 @@
 		ti,adc-channels = <0 1 2 3 4 5 6>;
 	};
 };
+
+&i2c1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&i2c1_pins>;
+	status = "okay";
+	clock-frequency = <400000>;
+
+  	rtc2: pcf8523@68 {
+ 		compatible = "nxp,pcf8523";
+ 		reg = <0x68>;
+ 	};
+};

testing the i2c bus

Once the system is up it is possible to use the i2c-tools to scan desired i2c busses:

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

Here you can see that id 0x68 has been identified. That is the i2c bus ID of the rtc chip. The UU indicates that the device is unavailable from userland, typically because a kernel driver has the address in use. In this case the rtc driver.

working with the eeprom

Reading the contents from address 0x00 to 0xff

root@beaglebone:~# i2cdump -r 0x00-0xff 1 0x57 c
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-1, address 0x57, mode byte consecutive read
Probe range limited to 0x00-0xff.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
10: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
20: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
30: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
40: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
50: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
60: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
70: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
90: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
⚠️ **GitHub.com Fallback** ⚠️