用LPC824的AD采集电压数据,采集出来的数值为0x0000,bang一下吗?

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

用LPC824的AD采集电压数据,采集出来的数值为0x0000,bang一下吗?

717 次查看
dovegeng
Contributor I
int main (void)
{
  volatile uint32_t data;
 unsigned char i;
 unsigned int addr_sum,temp;
 uint32_t current_clkdiv, val, temp_data, n;
    SystemInit();   /* ³õʼ»¯Ä¿±ê°å£¬ÇÐÎðɾ³ý       */
    GPIOInit();     /* GPIO³õʼ»¯                   */
    UARTInit();    /* UART³õʼ»¯                   */
  UART1Init();   /* UART³õʼ»¯                   */
 WDTInit();      /* WDT³õʼ»¯                    */
 SCTInit ();
 DIR_INIT();
 DIR_OFF();
 SetLedState(0,0,0,0);
 myDelay(1);
 initvalue();
 
 LPC_GPIO_PORT->SET0  = 0x00822000;     // P0.27, P0.16 to P0.13
// LPC_GPIO_PORT->SET0  |= 0x00822000; 
  LPC_GPIO_PORT->DIR0 &= 0xFF7DDFFF;     // P0.27, P0.16 to outpu
 
  
 LPC_SYSCON->PDRUNCFG &= ~(ADC_PD);
//  LPC_SYSCON->PRESETCTRL &= (ADC_RST_N);
//  LPC_SYSCON->PRESETCTRL |= ~(ADC_RST_N);
//  LPC_SYSCON->SYSAHBCLKCTRL |= (ADC | GPIO | SWM);
 LPC_SYSCON->SYSAHBCLKCTRL |= (ADC);
 
 
  LPC_SWM->PINENABLE0 &= ~(ADC_3|ADC_9|ADC_10); // Fixed pin analog functions enabled
//  LPC_SWM->PINENABLE0 &= ~(ADC_3);
// LPC_SWM->PINENABLE0 |= (ADC_1|ADC_2|ADC_4|ADC_5|ADC_6|ADC_7|ADC_8|ADC_11); // ??AD3-11AD????

  LPC_ADC->INTEN = (1<<SEQA_INTEN)  |
                   (1<<SEQB_INTEN)  |
                   (0<<OVR_INTEN)   |
                   (0<<ADCMPINTEN0) |
                   (0<<ADCMPINTEN1) |
                   (0<<ADCMPINTEN2) |
                   (0<<ADCMPINTEN3) |
                   (0<<ADCMPINTEN4) |
                   (0<<ADCMPINTEN5) |
                   (0<<ADCMPINTEN6) |
                   (0<<ADCMPINTEN7) |
                   (0<<ADCMPINTEN8) |
                   (0<<ADCMPINTEN9) |
                   (0<<ADCMPINTEN10)|
                   (0<<ADCMPINTEN11);
 
  LPC_ADC->TRM &= ~(1<<ADC_VRANGE); // '0' for high voltage
 
  current_clkdiv = (SystemCoreClock / 100000) - 1;
 LPC_ADC->CTRL = (1UL << ADC_CALMODE) | (current_clkdiv & 0xFF);
 while ((LPC_ADC->CTRL & (1UL << ADC_CALMODE)) != 0);

 
//  current_seqa_ctrl |= LOGIC_HIGH<<ADC_TRIGGER;    // Use for software-only triggering
//  current_seqb_ctrl |= LOGIC_HIGH<<ADC_TRIGGER;    // Use for software-only triggering

  // Enable ADC interrupts in the NVIC
  NVIC_EnableIRQ(ADC_SEQA_IRQn);
 
  while(1)
  {

  LPC_ADC->SEQA_CTRL = current_seqa_ctrl; 
 LPC_ADC->SEQA_CTRL &= ~(0xFFF);
 LPC_ADC->SEQA_CTRL |= (1UL << 9);
  
  //¿ªÆôAD
 LPC_ADC->SEQA_CTRL |= ((1UL << ADC_START) | (1UL << ADC_SEQ_ENA));
 do
 {
  data = LPC_ADC->SEQA_GDAT;  // ????
 } while ((data & (1UL << 31)) == 1); // ??????
   //¹Ø±Õ
 LPC_ADC->SEQA_CTRL &= ~(1UL << ADC_SEQ_ENA);
 
         DIR_ON();
       myDelay (500);
          LPC_USART0->TXDAT=((data >> 4) & 0xfff)>>8;
       while(!(LPC_USART0->STAT&0x08));
          LPC_USART0->TXDAT=((data >> 4) & 0xfff);
       while(!(LPC_USART0->STAT&0x08));
          DIR_OFF();
       
      }
    }
标记 (1)
0 项奖励
回复
1 回复

492 次查看
jeremyzhou
NXP Employee
NXP Employee

Hi dove geng,

Thank you for your interest in NXP Semiconductor products and 
for the opportunity to serve you.
Please checking the above code by referring to the attachment.
Have a great day,

TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复