Hi,
Is there any example for using gpio pins as I2C on BBB?
Thank you
Hi,
Is there any example for using gpio pins as I2C on BBB?
Thank you
HI @samy0392, while there is a “Bindings for GPIO bitbanged I2C”:
I’d really look first to the existing i2c pins, on the Header. Is there any reason you can’t use them?
i2c1: P9_17, P9_18
i2c2: P9_19, P9_20
Regards,
Hi Robert,
Thanks for the quick response. Its a custom board and some pins are being used for other purposes. Is there a device tree example that I can follow?
Thank you
a quick grep of the linux tree found this example:
i2c_gpio: i2c-gpio {
compatible = "i2c-gpio";
#address-cells = <1>;
#size-cells = <0>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c_gpio>;
gpios = <
&gpio5 1 GPIO_ACTIVE_HIGH /* SDA */
&gpio5 0 GPIO_ACTIVE_HIGH /* SCL */
>;
clock-frequency = <400000>;
status = "okay";
ds1339: rtc@68 {
compatible = "dallas,ds1339";
reg = <0x68>;
status = "disabled";
};
};
Yes, it’s imx6, but most should be transferable to AM335x.
Regards,
I am trying to connect Si5351 clock generator from Adafruit with BBB.
I am following /KERNEL/Documentation/devicetree/bindings/clock/silabs,si5351.txt and implemented it and created a new device tree overlay but I keep getting errors on bootup that it can’t read si5351 register.
Here is my dts overlay:
/dts-v1/;
/plugin/;
#include <dt-bindings/board/am335x-bbw-bbb-base.h>
#include <dt-bindings/pinctrl/am33xx.h>
/{
compatible = "ti,beaglebone", "ti,beaglebone-black", "ti,beaglebone-green";
part-number = "BB-GPIO-I2C";
version = "00A0";
fragment@0 {
target = <&am33xx_pinmux>;
__overlay__ {
bb_i2cx_pins: pinmux_bb_i2cx_pins {
pinctrl-single,pins = <
AM33XX_IOPAD(0x868, PIN_INPUT_PULLUP | MUX_MODE7) /* gpmc_a10.gpio1_26 SDA */
AM33XX_IOPAD(0x86c, PIN_OUTPUT_PULLUP | MUX_MODE7) /* gpmc_a11.gpio1_27, INPUT SCL */
>;
};
};
};
fragment@1 {
target-path="/";
__overlay__ {
ref25: ref25M {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <25000000>;
};
i2c@0 {
compatible = "i2c-gpio";
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&bb_i2cx_pins>;
gpios = <&gpio1 26 1 // sda
&gpio1 27 1 // scl
>;
i2c-gpio,sda-open-drain;
i2c-gpio,scl-open-drain;
i2c-gpio,delay-us = <2>; // ~100 kHz
#address-cells = <1>;
#size-cells = <0>;
/* Si5351a msop10 i2c clock generator */
si5351a: clock-generator@60 {
compatible = "silabs,si5351a-msop";
reg = <0x60>;
#address-cells = <1>;
#size-cells = <0>;
#clock-cells = <1>;
/* connect xtal input to 25MHz reference */
clocks = <&ref25>;
clock-names = "xtal";
/* connect xtal input as source of pll0 and pll1 */
silabs,pll-source = <0 0>, <1 0>;
/*
* overwrite clkout0 configuration with:
* - 8mA output drive strength
* - pll0 as clock source of multisynth0
* - multisynth0 as clock source of output divider
* - multisynth0 can change pll0
* - set initial clock frequency of 8KHz
*/
clkout0 {
reg = <0>;
silabs,drive-strength = <8>;
silabs,multisynth-source = <0>;
silabs,clock-source = <0>;
silabs,pll-master;
clock-frequency = <74250000>;
};
/*
* overwrite clkout1 configuration with:
* - 4mA output drive strength
* - pll1 as clock source of multisynth1
* - multisynth1 as clock source of output divider
* - multisynth1 can change pll1
* - set initial clock frequency of 1.024MHz
*/
clkout1 {
reg = <1>;
silabs,drive-strength = <4>;
silabs,multisynth-source = <1>;
silabs,clock-source = <0>;
pll-master;
};
/*
* overwrite clkout2 configuration with:
* - xtal as clock source of output divider
*/
clkout2 {
reg = <2>;
silabs,clock-source = <2>;
};
};
};
};
};
};
So, i2c already exists… rename as i2c-gpio
fragment@1 {
target-path="/";
__overlay__ {
ref25: ref25M {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <25000000>;
};
i2c-gpio {
compatible = "i2c-gpio";
status = "okay";
then please run: i2cdetect -l
Regards,
I can see i2c-gpio by running i2cdetect -l
i2c-3 i2c i2c-gpio I2C adapter
i2c-1 i2c OMAP I2C adapter I2C adapter
i2c-2 i2c OMAP I2C adapter I2C adapter
i2c-0 i2c OMAP I2C adapter I2C adapter
I can also see device on i2c-3 register 60 by using i2cdetect -y 3:
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: -- -- -- -- -- -- -- --
But during boot-up I see following errors:
[ 2.238622] si5351 3-0060: unable to read from reg10
[ 2.244281] si5351 3-0060: unable to read from reg2c
[ 2.249665] si5351 3-0060: unable to read from reg11
[ 2.255317] si5351 3-0060: unable to read from reg34
[ 2.260725] si5351 3-0060: unable to read from reg12
[ 2.266381] si5351 3-0060: unable to read from reg3c
[ 2.271770] si5351 3-0060: unable to read from reg10
[ 2.277096] si5351 3-0060: unable to read from reg2c
[ 2.282172] si5351 3-0060: Cannot set rate : -22
[ 2.287153] si5351 3-0060: unable to read from reg11
[ 2.292474] si5351 3-0060: unable to read from reg34
[ 2.297866] si5351 3-0060: unable to read from reg12
[ 2.303200] si5351 3-0060: unable to read from reg3c
[ 2.308358] i2c-gpio i2c-gpio: using pins 58 (SDA) and 59 (SCL)
Thank you
Hi @samy0392, i don’t know, probably best to stick a digital analyser on the pins and scope the i2c connection… It looks like it was detected, but unable to make any register read/writes to the device…
Regards,