lpc2388 ADC 2,3 not working

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

lpc2388 ADC 2,3 not working

192 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by m2babaey on Sat Jul 06 05:41:14 MST 2013
Hi
I have written some code for reading ADC on LPC2388
The code is working for ADC0 and ADC1 but the result is always zero for ADC2 and ADC3
Here is my code:
void InitADC()
{
  PCONP   |= 1<<12; //set ADC power clock
  //ADC0-3 enabled
  PINSEL1 |= 0x55 << 14 ;       //0b01010101
  PINSEL1 &= ~(0xAA<<14);       //0b10101010
  AD0CR= 0x00200500  ; 
}

void ADC_stopCnv (void) {
  AD0CR &= ~0x01000000;                          /* stop conversion  */
}

void read_adc()
{
  unsigned char adc_input;

  for (adc_input=0; adc_input<4; adc_input++)
  {
    AD0CR &= 0xFFFFFF00;   
    AD0CR|=adc_input;   
    
    delay_us(10); 
    ADC_stopCnv();   
    AD0CR |= (1<<24); //start     
    delay_us(10);       
    //x2=AD0GDR;     
    while (!(AD0GDR & (1UL<<31)));                
    //AnalogValues[adc_input] = (AD0GDR>>6 & 0x3FF);                     //this line wasn't working properly so I used AD0DRx
    ADC_stopCnv(); 
    
    //send data to RS232 port
    if(adc_input==0)
    {
      AnalogValues[adc_input]=AD0DR0>>6;
      sendchar(0);
      sendchar(AnalogValues[adc_input]>>8);
      sendchar(AnalogValues[adc_input]);
      delay_ms(400); 
    }
    else if(adc_input==1)
    {
      AnalogValues[adc_input]=AD0DR1>>6;
      sendchar(1);
      sendchar(AnalogValues[adc_input]>>8);
      sendchar(AnalogValues[adc_input]);
      delay_ms(400); 
    }
    else if(adc_input==2)
    {
      AnalogValues[adc_input]=AD0DR2>>6;
      sendchar(2);
      sendchar(AnalogValues[adc_input]>>8);
      sendchar(AnalogValues[adc_input]);
      delay_ms(400); 
    }
    else if(adc_input==3)
    {
      AnalogValues[adc_input]=AD0DR3>>6;
      sendchar(3);
      sendchar(AnalogValues[adc_input]>>8);
      sendchar(AnalogValues[adc_input]);
      delay_ms(400); 
    }      
  }

}
Could anyone help me why ADC2-3 are not working? as you see PINSEL1 is OK and pins are connected in PCB
0 项奖励
回复
0 回复数