CM3计算板I/O编程

1、CM3计算板的IO资源

CM3支持的I/O管脚数为54个,每个管脚包括一个或多个复用功能,分别位于ALT0~ALT5,如下表:

2、设备树启用IO外设的方式

通过在/boot/config.txt 文件中描述IO行为,可以在系统启动时,初始化IO外设的初始状态,例如,配置为输入输出、上下拉状态以及复选功能。

The gpio directive allows GPIO pins to be set to specific modes and values at boot time in a way that would previously have needed a custom dt-blob.bin file. Each line applies the same settings (or at least makes the same changes) to a set of pins, either a single pin (3), a range of pins (3-4), or a comma-separated list of either (3-4,6,8). The pin set is followed by an = and one or more comma-separated attributes from this list:

  • ip - Input
  • op - Output
  • a0-a5 - Alt0-Alt5
  • dh - Driving high (for outputs)
  • dl - Driving low (for outputs)
  • pu - Pull up
  • pd - Pull down
  • pn/np - No pull

例如:

# 选择 复用功能2 Alt2 GPIO0~GPIO27
gpio=0-27=a2

# 设置GPIO12 输出拉高
gpio=12=op,dh

# 设置GPIO18 20 为输入上拉
gpio=18,20=pu

# 设置GPIO17~GPIO21 为输入
gpio=17-21=ip

3、使用wiringPi C库对IO编程

  • 安装最新wiringPi,安装方法见:安装wiringPi  
  • 使用gpio readall 查看是否读取到CM3的所有IO。
  • 编程示例:CM3 GPIO27交替拉高拉低。
  • 编译: gcc -c testGPIO3.c -o run -l wiringPi
  • 执行:./run
#include <wiringPi.h>

#define TEST_PIN    27

int main(void)
{
    
    wiringPiSetup();
    pinMode(TEST_PIN, OUTPUT);
    
    while(1){

        digitalWrite(TEST_PIN, HIGH);
        delay(1000);

        digitalWrite(TEST_PIN, LOW);
        delay(1000);
        
    }

    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值