iMX283 学习笔记----1. GPIO2_4(P2.4) 操作
2017-03-05 22:20
330 查看
在数据手册上一直找不到可以控制 P2.4 的寄存器的内存地址,只能在linux开发只能上看到如下的代码
这样子很难在代码中使用,经过不端尝试,又问了无数遍的度娘,终于找到了导出GPIO的方法:
导出之后就是设置输入还是输出了
当然也是可以通过IO 操作。
最后设置GPIO的值,还是先写一下 开发指南代码
如此,就能愉悦的 控制 连接在 GPIO 上的led 灯 打开和熄灭了
// 导出GPIO root@EasyARM-iMX283 /sys/class/gpio# echo 68 >export
这样子很难在代码中使用,经过不端尝试,又问了无数遍的度娘,终于找到了导出GPIO的方法:
// 导出GPIO char buffer[10000000]; int len; int fd; fd = open("/sys/class/gpio/export", O_WRONLY); if (fd < 0) { printf("Failed!\n"); return(-1); } len = snprintf(buffer, 10000000, "%d", 68); if (write(fd, buffer, len) < 0) { printf("Fail to export gpio!"); return -1; } close(fd);以上代码就导出了 P2.4.
导出之后就是设置输入还是输出了
// 开发指南代码 root@EasyARM-iMX283 /sys/devices/virtual/gpio/gpio68# echo out >direction #设置为输出
当然也是可以通过IO 操作。
char path[10000000]; int fd; snprintf(path, 10000000, "/sys/class/gpio/gpio%d/direction", 68); fd = open(path, O_WRONLY); if (fd < 0) { printf("failed !\n"); return -1; } if (write(fd, "out", 3) < 0) { // 设置为输出 printf( "failed to set direction!\n"); return -1; } close(fd);
最后设置GPIO的值,还是先写一下 开发指南代码
root@EasyARM-iMX283 /sys/devices/virtual/gpio/gpio68# echo 0 >value #输出低电平root@EasyARM-iMX283 /sys/devices/virtual/gpio/gpio68# echo 1 >value #输出高电平以下是IO操作方法:
char path[10000000]; int fd; snprintf(path, 10000000, "/sys/class/gpio/gpio%d/value", 68); fd = open(path, O_WRONLY); if (fd < 0) { printf("failed!\n"); return -1; } if (write(fd, 1, 1) < 0) { printf("failed to write value!\n"); return -1; } close(fd);
如此,就能愉悦的 控制 连接在 GPIO 上的led 灯 打开和熄灭了
相关文章推荐
- 学习笔记之TMS320C6748的GPIO操作
- K60学习笔记三:GPIO口的底层驱动操作带API接口
- [转载]STM32学习笔记——控制GPIO输出点亮LED灯(直接操作存储器)
- STM32学习笔记——控制GPIO输出点亮LED灯(直接操作存储器)
- STM8L学习笔记-GPIO端口操作(一)
- 树莓派学习笔记——Shell脚本操作GPIO
- NodeMCU--学习笔记(二)GPIO操作
- ajax 学习笔记之三 级联的操作
- 菜鸟学习笔记-----linux下的串口操作 嘿嘿
- Win32学习笔记——鼠标操作
- [MDX学习笔记之五]优化Set操作——SUM中的CrossJoin
- Oracle SQL Plus 的基本操作 - Oracle 学习笔记 1
- C/C++学习笔记2 - cin深入分析(上) - cin输入操作处理(原创)
- [学习笔记]Java 中对文件的读写操作之比较
- LINQ学习笔记三-----基本查询操作
- C#学习笔记一(字符串操作)
- 连接操作 - Oracle 学习笔记 3
- Win32学习笔记——键盘操作
- linux下c语言学习笔记——操作mysql
- 2008年7月21日学习笔记----(管理续)操作与配置cisco设备