AnsweredAssumed Answered

使用LPC1752的ADC第5通道,读取寄存器DR5的值都一直为0xFFF

Question asked by felix zhang on Sep 7, 2017
Latest reply on Sep 10, 2017 by Kerry Zhou

使用LPC1752的ADC第5通道,按照下面两种方式读取寄存器DR5的值都一直为0xFFF。 请问是哪里出错了呢?谢谢 软件ADC初始化配置 Chip_IOCON_PinMux(LPC_IOCON, 1, 31, IOCON_MODE_INACT, IOCON_FUNC3);//AD0.5 /*电池电压检测 */ // LPC_IOCON->PINSEL[3] |= (3ul<<30); // LPC_IOCON->PINMODE[3] |= (2ul<<30); LPC_SYSCTL->PCONP |= (1ul<<12); //功率使能 LPC_ADC->CR |= (1ul<<5); //选择5通道 LPC_ADC->CR |= (11ul<<8); //DIV = 11 ADCclk = 6MHz/(11+1) = 500KHz LPC_ADC->CR |= (1ul<<21); //ADC处于正常工作模式 读取方式1: #define BURST_EN() LPC_ADC->CR |= (1ul<<16) //硬件转换 #define BURST_DIS() LPC_ADC->CR &= ~(1ul<<16) uint32_t ADCBURSTRead(uint8_t channelnum) { uint32 clear,rt; clear = clear; clear = LPC_ADC->DR[channelnum]; //转换前清除完成标志 读取清除 LPC_ADC->INTEN = 0; BURST_EN(); while(!(LPC_ADC->STAT&(1ul<<channelnum))); 等待转换完成="" rt="(LPC_ADC-">DR[channelnum]>>4)&0x0FFF; BURST_DIS(); return rt; } 读取方式2: uint32_t ADC0Read( uint8_t channelNum ) { int32_t counter; uint32_t regVal, ADC_Data; counter = 0xFFFF; LPC_ADC->CR &= 0xFFFFFF00; LPC_ADC->CR |= (1 << 24) | (1 << channelNum); /* switch channel,start A/D convert */ while ( counter-- ) /* wait until end of A/D convert */ { regVal = LPC_ADC->DR[channelNum]; /* read result of A/D conversion */ if ( regVal & 0x80000000 ) { break; } } LPC_ADC->CR &= 0xF8FFFFFF; /* stop ADC now */ if ( (regVal & 0x40000000)||(counter<10) ) /* save data when it's not overrun, otherwise, return zero */ { return ( 0 ); } ADC_Data = ( regVal >> 4 ) & 0xFFF; return ( ADC_Data ); /* return A/D conversion value */ } 硬件原理图:

Attachments

Outcomes