XC2440开发板提供了adc的测试程序,内核配置时已经加入了adc的驱动,下面测试一下看看效果
1:通过ftp工具将 adc_test执行文件传到开发板上 var/ftp/pub目录下
2:chmod a+x adc_test 改变文件权限
3:./adc_test 1 说明:./adc_test 是运行程序 1是运行程序的参数,这里表示对adc通道1操作
- /**************************************************************************
- XC2440 hwmon-adc driver test
- device node is "/sys/class/hwmon/hwmon0/device/adcN_raw"
- www.xcembed.com 2011.05
- ***************************************************************************/
- /***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/fcntl.h>
- int main(int argc, char *argv[])
- {
- int fd = -1, ret;
- int adc_ch, value;
- char buffer[5];
- char dev_name[50];
-
- if ( argc < 2 )
- {
- printf("usage adc_test chanel(0~7)\n");
- exit(1);
- }
- else
- {
- adc_ch = atoi(argv[1]);
- }
-
- if ( (adc_ch >= 0) && (adc_ch <= 7) )
- {
- sprintf(dev_name, "/sys/class/hwmon/hwmon0/device/adc%d_raw\0", adc_ch);
- //printf("dev name %s\n", dev_name);
-
- if ((fd = open(dev_name, O_RDONLY)) < 0)
- {
- perror("open error");
- exit(1);
- }
- }
- else
- {
- printf("adc_ch is (0~7)\n");
- exit(1);
- }
-
- ret = read(fd, buffer, 4);
- if (ret < 0)
- {
- perror("read error");
- exit(1);
- }
-
- value = atoi(buffer);
- printf("ADC %d current value is %d\n", adc_ch, value);
-
- close(fd);
- return 0;
- }
makefile内容:
CROSS=arm-linux-
all: adc_test
adc_test:adc_test.c
$(CROSS)gcc -o adc_test adc_test.c
$(CROSS)strip adc_test
clean:
@rm -f adc_test *.o *~
阅读(644) | 评论(0) | 转发(0) |