在写使用spi过程中,需要用到GPIO3.21这个引脚的高电平输出信号。
在超级终端里面的输入方法:
复制代码
1
2
3
# cd /sys/class/gpio
/sys/class/gpio# echo 117 >export
/sys/class/gpio# echo out >gpio117/direction
这个固然可以实现引脚电平的输出,在使用中,还可以用文件操作方式使得电平升高。如下:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include stdlib.h
#include stdio.h
#include string.h
#include unistd.h
#include fcntl.h
//芯片复位引脚:GPIO3.21
#define SYSFS_GPIO_EXPORT "/sys/class/gpio/export"
#define SYSFS_GPIO_RST_PIN_VAL "117"
#define SYSFS_GPIO_RST_DIR "/sys/class/gpio/gpio117/direction"
#define SYSFS_GPIO_RST_DIR_VAL "OUT"
#define SYSFS_GPIO_RST_VAL "/sys/class/gpio/gpio117/value"
#define SYSFS_GPIO_RST_VAL_H "1"
#define SYSFS_GPIO_RST_VAL_L "0"
int main()
{
int fd;
//打开端口/sys/class/gpio# echo 117 > export
fd = open(SYSFS_GPIO_EXPORT, O_WRONLY);
if(fd == -1)
{
printf("ERR: Radio hard reset pin open error.n");
return EXIT_FAILURE;
}
write(fd, SYSFS_GPIO_RST_PIN_VAL ,sizeof(SYSFS_GPIO_RST_PIN_VAL));
close(fd);
//设置端口方向/sys/class/gpio/gpio117# echo out > direction
fd = open(SYSFS_GPIO_RST_DIR, O_WRONLY);
if(fd == -1)
{
printf("ERR: Radio hard reset pin direction open error.n");
return EXIT_FAILURE;
}
write(fd, SYSFS_GPIO_RST_DIR_VAL, sizeof(SYSFS_GPIO_RST_DIR_VAL));
close(fd);
fd = open(SYSFS_GPIO_RST_VAL, O_RDWR);
if(fd == -1)
{
printf("ERR: Radio hard reset pin value open error.n");
return EXIT_FAILURE;
}
//输出高电平
write(fd, SYSFS_GPIO_RST_VAL_H, sizeof(SYSFS_GPIO_RST_VAL_H));
while(1)
{
}
close(fd);
printf("INFO: Radio hard reset pin value open error.n");
return 0;
}
最后
以上就是高兴蜡烛最近收集整理的关于linux下用文件控制gpio的输出电平的全部内容,更多相关linux下用文件控制gpio内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复