-
sam9260 adc 测试
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/unistd.h>
- #include <sys/stat.h>
- #include <linux/fcntl.h>
- #include <linux/ioctl.h>
-
- #include "adc.h"
-
- int main(int argc, char *argv[])
- {
- if (argc < 2) {
- printf("Useage: %s dev
", argv[0]);
- exit(0);
- }
-
- struct adc_mode mode = {
- .trigger = ADC_TRIGGER_SOFT,
- .trigger_time = 1000,
- .resolution = 0,
- .sleep_mode = 1,
- .startup_time = 5,
- .sample_time = 8,
- .adc_clock = 8,
- };
-
- int fd = open(argv[1], O_RDWR);
- if (fd == -1){
- perror("open:");
- exit(-1);
- }
-
- int data;
- int ret;
- float tdata=0,a=3.3;
- if (ioctl(fd, ADCCTL_SETMODE, &mode))
- perror("ioctl:ADCCTL_SETMODE");
-
- memset(&mode, 0, sizeof(struct adc_mode));
- ioctl(fd, ADCCTL_GETMODE, &mode);
- printf("adc_mode: f => v
"
- "trigger => %d
"
- "trigger_time => %d
"
- "resolution => %d
"
- "startup_time => %d
"
- "sample_time => %d
"
- "adc_clock => %d
",
- mode.trigger, mode.trigger_time,
- mode.resolution, mode.startup_time,
- mode.sample_time, mode.adc_clock);
-
- while(1)
- {
- usleep(3000000);
- ioctl(fd, ADCCTL_START);
- ioctl(fd, ADCCTL_GETSTATUS, &ret);
- printf("status: 0x%08x
", ret);
- ret = 0;
-
-
-
- ioctl(fd, ADCCTL_GETDATA, &data);
- printf("AD_VAL: %d
", data);
- tdata=(float)data;
- tdata=tdata/1024*a;
- printf("the voltage is %fV
",tdata);
-
- }
-
- close(fd);
-
- return 0;
-
- }
-
相关阅读:
ubuntu安装与卸载java
linux ubuntu 用户名,主机名,密码修改,增加用户,删除用户
linux中sudo fdisk -l报错:GPT PMBR size mismatch will be corrected by write错误
VM VirtualBox虚拟机vdi扩大磁盘空间容量
WinSCP传输文件到虚拟机linux报错:SSH2_MSG_CHANNEL_FAILURE for nonexistent channel 0
parallel python多进程集群模式
zookeeper报错:ERROR [main:QuorumPeerMain@86]
hive启动报错:Exception in thread "main" java.lang.RuntimeException: com.ctc.wstx.exc.WstxParsingException: Illegal character entity: expansion character (code 0x8 at
3.数据链路层
2.物理层
-
原文地址:https://www.cnblogs.com/zym0805/p/5863737.html
Copyright © 2020-2023
润新知