您尚未登录。

楼主 #1 2019-11-16 18:18:24

psst
会员
注册时间: 2019-01-22
已发帖子: 91
积分: 31.5

v3s 怎么使用gpio模拟iic

请教各位高手。我想用drivers/i2c/busses/i2c-gpio.c 模拟iic,硬件iic口没有使用,io被占用了。要怎么玩?

menuconfig配置如下
  -*- I2C support                                                 
     Enable compatibility bits for old user-space               
  <*>   I2C device interface                                         
   <*>   I2C bus multiplexing support                               
              Multiplexer I2C Chip support  --->                       
   [**]   Autoselect pertinent helper modules                       
            I2C Hardware Bus support  --->     
      *** I2C system bus drivers (mostly embedded / system-on-chip)
  │ │    < > CBUS I2C driver                                             
  │ │    < > Synopsys DesignWare Platform                             
  │ │    < > EMMA Mobile series I2C adapter                         
  │ │    <*> GPIO-based bitbanging I2C                                   
  │ │    < > Marvell mv64xxx I2C Controller                       
  │ │    < > OpenCores I2C Controller                                 
  │ │    < > PCA9564/PCA9665 as platform device                       
  │ │    < > Rockchip RK3xxx I2C adapter                               
  │ │    < > Simtec Generic I2C interface         

dts如下

i2c0@0 {
        compatible = "i2c-gpio";
            gpios = <&pio 2 2 // sda
                     &pio 2 1 // scl
                >;
            i2c-gpio,sda-open-drain;
            i2c-gpio,scl-open-drain;
            i2c-gpio,delay-us = <2>;   
        #address-cells = <1>;
        #size-cells = <0>;
        status = "okay";
        //rv3029c2@56 {
            //compatible = "rv3029c2";
            //reg = <0x56>;
        //};

        };

启动后报错, OF: /soc/i2c0@0: could not get #gpio-cells for /soc/clock@01c20000
是不是gpio配置不对,
&pio 2 2 /* sda */
&pio 2 1这两个口是串口,没有使用,应该不会被占用,

设备树怎么写?请教大家了

最近编辑记录 psst (2019-11-16 18:19:36)

离线

#2 2019-11-16 18:29:38

kekemuyu
会员
注册时间: 2018-12-13
已发帖子: 849
积分: 710

Re: v3s 怎么使用gpio模拟iic

软件模拟也需要定时器吧,否则时序无法控制

离线

#3 2019-11-18 13:54:40

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,348
积分: 9202

Re: v3s 怎么使用gpio模拟iic

你的设备树配置有误, 来这里抄一个吧:

https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/allwinner/sun50i-a64-amarula-relic.dts

	i2c {
		compatible = "i2c-gpio";
		sda-gpios = <&pio 4 13 GPIO_ACTIVE_HIGH>;
		scl-gpios = <&pio 4 12 GPIO_ACTIVE_HIGH>;
		i2c-gpio,delay-us = <5>;
		#address-cells = <1>;
		#size-cells = <0>;
...




离线

#4 2020-07-24 12:59:07

liuy
会员
注册时间: 2020-06-24
已发帖子: 10
积分: 49

Re: v3s 怎么使用gpio模拟iic

我也在用模拟iic,请问启动了吗?

# dmesg | grep i2c
[    0.120130] i2c-gpio i2c-gpio: error trying to get descriptor: -2
[    0.981720] i2c /dev entries driver
[    6.656316] goodix-ts 1-005d: GTP i2c test failed time 1
[   11.086325] goodix-ts 1-005d: GTP i2c test failed time 2
[   15.516320] goodix-ts 1-005d: GTP i2c test failed time 3
[   15.544682] i2c-gpio i2c-gpio: using lines 3 (SDA) and 0 (SCL),-1


一直是这个错误

离线

#5 2020-08-02 20:03:27

lignin
会员
注册时间: 2020-03-21
已发帖子: 115
积分: 113.5

Re: v3s 怎么使用gpio模拟iic

在pinctrl里面要声明使用的引脚,然后在使用它gpio模拟iic的,应该是类似的
可以参考一下这个gpio模拟spi的例子

在根节点下加入
    spi2:spi2{
        compatible = "spi-gpio";
        #address-cells = <0x1>;
        #size-cells = <0>;
        //ranges;
        gpio-sck = <&pio 3 0 1>;
        gpio-miso = <&pio 3 1 1>;
        gpio-mosi = <&pio 3 2 1>;
        cs-gpios = <&pio 3 3 1>;
        num-chipselects = <1>;
       
        pinctrl-names = "default";//注意这两排
        pinctrl-0 = <&spi2_pins_a>;//
        spidev2 {     
             #address-cells = <1>;
            #size-cells = <0>;
            compatible = "rohm,dh2228fv";
            spi-max-frequency = <20000000>;
            reg = <0>;
           
        };

    };
   
     
在pinctrl里面加入
&pio{

    spi2_pins_a: spi2-pins-pc {
                pins = "PD0", "PD1", "PD2", "PD3";
                function = "gpio_out";
                                bias-pull-up;
            };       
};

最近编辑记录 lignin (2020-08-02 20:05:48)

离线

#6 2022-06-11 00:14:45

资本家大善人
会员
注册时间: 2021-03-26
已发帖子: 191
积分: 131.5

Re: v3s 怎么使用gpio模拟iic

就在两地方,毫无问题

 .config - Linux/arm 5.4.99 Kernel Configuration
 > Device Drivers > I2C support > I2C Hardware Bus support ────────────────────
  ┌─────────────────────── I2C Hardware Bus support ────────────────────────┐
  │  Arrow keys navigate the menu.  <Enter> selects submenus ---> (or empty │  
  │  submenus ----).  Highlighted letters are hotkeys.  Pressing <Y>        │  
  │  includes, <N> excludes, <M> modularizes features.  Press <Esc><Esc> to │  
  │  exit, <?> for Help, </> for Search.  Legend: [*] built-in  [ ]         │  
  │ ┌─────────────────────────────────────────────────────────────────────┐ │  
  │ │        *** I2C system bus drivers (mostly embedded / system-on-chip)│ │  
  │ │    < > CBUS I2C driver                                              │ │  
  │ │    < > Synopsys DesignWare Platform                                 │ │  
  │ │    < > EMMA Mobile series I2C adapter                               │ │  
  │ │    <*> GPIO-based bitbanging I2C
	i2c_gpio0: i2c-gpio-0 {
		compatible = "i2c-gpio";
		sda-gpios = <&pio 4 0 GPIO_ACTIVE_HIGH>;
		scl-gpios = <&pio 4 1 GPIO_ACTIVE_HIGH>;
		i2c-gpio,delay-us = <5>;
		#address-cells = <1>;
		#size-cells = <0>;
        ft6x06@38 {
                compatible = "focaltech,ft6236";
                reg = <0x38>;
                interrupt-parent = <&pio>;
                interrupts = <4 2 IRQ_TYPE_LEVEL_LOW>;
                reset-gpios = <&pio 4 3 GPIO_ACTIVE_LOW>;
                touchscreen-size-x = <240>;
                touchscreen-size-y = <240>;
          }; 

    };

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn