使用AIN5进行ADC采样(禁止触摸屏) 驱动程序: ADC寄存器定义: #define S3C2410_ADC_BASE S3C2410_PA_ADC #define S3C2410_ADCREG(x) ((x) + S3C24XX_PA_ADC) #define S3C2410_ADCCON S3C2410_ADCREG(0x00) #define S3C2410_ADCTSC S3C2410_ADCREG(0x04) #define S3C2410_ADCDLY S3C2410_ADCREG(0x08) #define S3C2410_ADCDAT0 S3C2410_ADCREG(0x0C) #define S3C2410_ADCDAT1 S3C2410_ADCREG(0x10) #define S3C2410_ADCPDN S3C2410_ADCREG(0x14) #define ADCCON (0x00) #define ADCTSC (0x04) #define ADCDLY (0x08) #define ADCDAT0 (0x0C) #define ADCDAT1 (0x10) #define ADCPDN (0x14) ADC的默认时钟尽管是开的,但是为了保险,还是再使能一下: temp = __raw_readl(S3C2410_CLKCON)|(1<<15); //printk("CLKCON = 0x%x\n", temp); temp &= ~(S3C2410_CLKCON_IDLE|S3C2410_CLKCON_POWER); __raw_writel(temp, S3C2410_CLKCON); //printk("CLKCON = 0x%x\n", temp); ADC初始化: S3C2440的移植代码中没有ADC的寄存器详细定义,为了方便,直接使用动态IO映射,使用ioremap函数进行操作: void __iomem *base = ioremap(S3C2410_ADC_BASE, 0x14); 设置ADC的ADCCON寄存器,设置AD转换参数: temp = (1<<14)|((200 - 1) << 6)|(5 << 3)|(0 << 2)|(1 << 1)|(0 << 0); __raw_writel(temp, base + ADCCON); temp = (0 << 8)|(0 << 7)|(1 << 6)|(0 << 5)|(1 << 4)|(1 << 3)|(0 << 2)|(0 << 0); __raw_writel(temp, base + ADCTSC); __raw_writel(1, base + ADCDLY); 读取ADC: unsigned int temp, val; void __iomem *base = ioremap(S3C2410_ADC_BASE, 0x14); temp = __raw_readl(base + ADCCON) | (1<<1); __raw_writel(temp, base + ADCCON ); val = __raw_readl(base + ADCDAT0); while(!(__raw_readl(base + ADCCON) & (1 << 15))); 测试程序:int main(int argc, char *argv[]) { int fd; unsigned char val; fd=open(DEV_NAME, O_RDWR); if(fd<0) { perror("can not open device"); exit(1); } while(1) { read(fd, &val, 1); printf("adc val = 0x%x\n", val); usleep(300000); } out: close(fd); return 0; } |