lpcware

LPC1115 freezes while reading ADC

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by audriusmerfeldas on Mon Oct 19 14:45:46 MST 2015
My LPC1115 freezes at the line:
"while ((LPC_ADC->DR[1] < 0x7FFFFFFF));   //wait for "done" bit to be set" or sometimes on:
"while ((LPC_ADC->DR[2] < 0x7FFFFFFF));   //wait for "done" bit to be set".

Any advices?

Please find the code bellow:

//SET UP THE ADC
  LPC_SYSCON->PDRUNCFG        &= ~(0x1<<4);  //power the ADC
  LPC_SYSCON->SYSAHBCLKCTRL   |= (1<<13);    //enable clock for ADC
  LPC_IOCON->R_PIO0_11        &= 0xFFFFFF78; //clear FUNC field for pin 32, set to analog input
  LPC_IOCON->R_PIO1_0         &= ~(0x97);    //clear FUNC field for pin 33, set to analog input
  LPC_IOCON->R_PIO1_1         &= ~(0x97);    //clear FUNC field for pin 34, set to analog input
  LPC_IOCON->R_PIO0_11        |= (1<<1);     //set to ADC mode for pin 32
  LPC_IOCON->R_PIO1_0        |= (1<<1);     //set to ADC mode for pin 33
  LPC_IOCON->R_PIO1_1        |= (1<<1);     //set to ADC mode for pin 34
  LPC_IOCON->R_PIO0_11         &= ~(0x10);    //turn off pull up
  LPC_IOCON->R_PIO1_0          &= ~(0x10);    //turn off pull up
  LPC_IOCON->R_PIO1_1          &= ~(0x10);    //turn off pull up

  while (1)                                   // Loop forever
  {
      LPC_ADC->CR     = 0x0B01;      //select ADC channel AD0 (pin 32), set up clock
      LPC_ADC->CR     |= (1<<24);    //start conversion by setting "Start Conversion Now" bit
      while ((LPC_ADC->DR[0] < 0x7FFFFFFF));   //wait for "done" bit to be set
      x=(LPC_ADC->DR[0]);

      LPC_ADC->CR     = 0x0B02;      //select ADC channel AD1 (pin 33), set up clock
      LPC_ADC->CR     |= (1<<24);    //start conversion by setting "Start Conversion Now" bit
      while ((LPC_ADC->DR[1] < 0x7FFFFFFF));   //wait for "done" bit to be set
      y=(LPC_ADC->DR[1]);

      LPC_ADC->CR     = 0x0B04;      //select ADC channel AD2 (pin 34), set up clock
      LPC_ADC->CR     |= (1<<24);    //start conversion by setting "Start Conversion Now" bit
      while ((LPC_ADC->DR[2] < 0x7FFFFFFF));   //wait for "done" bit to be set
      z=(LPC_ADC->DR[2]);

Outcomes