• Register
    • Login
    • Search
    • Recent
    • Github
    • 百度网盘
    • Onedrive

    CoolPi 4B硬件扩展四:GPIO

    Hardware
    1
    1
    116
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      george last edited by george

      40PIN连接器除了debug串口和I2C6,其它都可以用作通用IO。所有的GPIO都支持中断、上下拉和驱动强度配置。

      GPIO列表

      PIN序号 GPIO编号 节点编号 默认状态 IO电平
      3 GPIO0_D5 29 UP TTL 3.3V
      5 GPIO0_D4 28 UP TTL 3.3V
      7 GPIO1_B7 47 UP TTL 3.3V
      11 GPIO4_A0 128 DOWN TTL 3.3V
      13 GPIO4_A1 129 DOWN TTL 3.3V
      15 GPIO4_A2 130 DOWN TTL 3.3V
      19 GPIO1_B2 42 DOWN TTL 3.3V
      21 GPIO1_B1 41 DOWN TTL 3.3V
      23 GPIO1_B3 43 DOWN TTL 3.3V
      29 GPIO4_A3 131 DOWN TTL 3.3V
      31 GPIO4_A4 132 DOWN TTL 3.3V
      33 GPIO4_A5 133 DOWN TTL 3.3V
      35 GPIO4_A6 134 DOWN TTL 3.3V
      37 GPIO4_A7 135 DOWN TTL 3.3V
      12 GPIO1_A7 39 UP TTL 3.3V
      16 GPIO1_A1 33 DOWN TTL 3.3V
      18 GPIO1_A0 30 DOWN TTL 3.3V
      22 GPIO1_B0 40 UP TTL 3.3V
      24 GPIO1_B4 44 UP TTL 3.3V
      26 GPIO1_B5 45 UP TTL 3.3V
      32 GPIO3_B1 105 UP TTL 3.3V
      36 GPIO4_B2 106 UP TTL 3.3V
      38 GPIO4_B3 107 UP TTL 3.3V
      40 GPIO3_C3 115 UP TTL 3.3V

      测试命令

      向内核申请GPIO,写入对应的GPIO值直接申请,比如申请控制GPIO4A0,则使用命令:

      echo 128 > /sys/class/gpio/export
      

      写入后,可以看到已经生成节点:

      /sys/class/gpio/gpio128/
      

      相应gpio节点下面的接口,比如GPIO4A0:

      root@ubuntu:~# ll /sys/class/gpio/gpio128/
      total 0
      drwxr-xr-x 3 root root    0 Nov 21 15:23 ./
      drwxr-xr-x 3 root root    0 Nov 21 15:23 ../
      -rw-r--r-- 1 root root 4096 Nov 21 15:24 active_low
      lrwxrwxrwx 1 root root    0 Nov 21 15:24 device -> ../../../gpiochip4/
      -rw-r--r-- 1 root root 4096 Nov 21 15:24 direction
      -rw-r--r-- 1 root root 4096 Nov 21 15:24 edge
      drwxr-xr-x 2 root root    0 Nov 21 15:24 power/
      lrwxrwxrwx 1 root root    0 Nov 21 15:24 subsystem -> ../../../../../../class/gpio/
      -rw-r--r-- 1 root root 4096 Nov 21 15:23 uevent
      -rw-r--r-- 1 root root 4096 Nov 21 15:24 value
      

      设置GPIO4A0为输出口

      root@ubuntu:/sys/class/gpio/gpio128# echo out >direction 
      root@ubuntu:/sys/class/gpio/gpio128# cat direction 
      out
      

      设置输出高电平

      root@ubuntu:/sys/class/gpio/gpio128# cat value 
      0
      root@ubuntu:/sys/class/gpio/gpio128# echo 1 >value 
      root@ubuntu:/sys/class/gpio/gpio128# cat value 
      1
      实际万用表测试PIN 11输出的电压为3.3V
      

      备注:

      • direction: 参数为“out”(输出)和“in”(输入),可读可写;

      • value: 参数为“0”(低电平)和“1”(高电平),可读可写;

      • edge:可以监听对应引脚的事件,需要把direction设置为输入
        参数为”none”(无中断触发), “rising”(上升沿触发), “falling”(下降沿触发), “both”(上升、下降都沿触发),用户层可以使用poll,设置events为POLLPRI | POLLERR等待事件触发,当对应的模式触发后,会返回事件的消息,此时需要读取value值,以表示改触发已经处理,否则会一直poll到原事件;

      • active_low:此值可以反转value中的值;

      1 Reply Last reply Reply Quote 1
      • Referenced by  大法师 大法师 
      • 1 / 1
      • First post
        Last post