- /*
- * adc_test.c
- *
- * Copyright (C) 2007 Mengrz
- */
- #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\n", 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\n"
- "trigger => %d\n"
- "trigger_time => %d\n"
- "resolution => %d\n"
- "startup_time => %d\n"
- "sample_time => %d\n"
- "adc_clock => %d\n",
- 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\n", ret);
- ret = 0;
- //while (1)
- // //ioctl(fd, ADCCTL_GETCNT, &ret);
- //printf("count: %d\n", ret);
- // while (1) {
- ioctl(fd, ADCCTL_GETDATA, &data);
- printf("AD_VAL: %d\n", data);
- tdata=(float)data;
- tdata=tdata/1024*a;
- printf("the voltage is %fV\n",tdata);
- // ret--;
- // usleep(200000);
- // }
- }
- close(fd);
- return 0;
- }
sam9260 adc 测试
最新推荐文章于 2019-07-16 10:31:40 发布