This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C129ENCPDT: ADC is forever busy

Part Number: TM4C129ENCPDT

The program is forever in this loop [while(!ADCIntStatus(ADC0_BASE, 0, false)))]. The ADC_0 SS0 is not generating an interrupt even though it is enabled.

int main()
{
      uint32_t ui32Value; 
      SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); 
      while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0))
      {

      }
      ADCSequenceDisable(ADC0_BASE, 0);
      ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
      ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_TS);
      ADCSequenceEnable(ADC0_BASE, 0);
      while (1)
      {
            ADCProcessorTrigger(ADC0_BASE, 0);
            while(!ADCIntStatus(ADC0_BASE, 0, false))
            {

            }
            ADCSequenceDataGet(ADC0_BASE, 0, &ui32Value);
      }
}

Any idea where I have gone wrong?

Thanks,

Sagar

  • Hello Sagar,

    You do not have any code to initialize your GPIO. You need to do this as well, or else the ADC pin you select will not work.

    Also you need to do ADCIntClear(ADC0_BASE, 0); both at the end of the configuration (right before the while loop) as well as after the ADCIntStatus check clears.

    You are most of the way there, so review our single_ended.c example from TivaWare a bit more to see the last steps you need.

  • Hi Jacobi,
    I am feeding the output of internal temperature sensor to the ADC. So, I didn't have to configure the GPIO. I have added the ADCIntClear(ADC0_BASE, 0); lines, but I had no success. The program still stays in the interrupt polling loop. Here is my updated code.


    int main()
    {
            uint32_t ui32Value;
           SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
           while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0)){}
           ADCSequenceDisable(ADC0_BASE, 0);
           ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
           ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_TS);
           ADCSequenceEnable(ADC0_BASE, 0);
           ADCIntClear(ADC0_BASE, 0);
           while (1)
           {
                 ADCProcessorTrigger(ADC0_BASE, 0);
                while(!ADCIntStatus(ADC0_BASE, 0, false)){}
                ADCIntClear(ADC0_BASE, 0);
                ADCSequenceDataGet(ADC0_BASE, 0, &ui32Value);
           }
    }

  • Jacobi,

    I have also tried configuring the GPIO pin, but with no success. I think there is something fundamentally wrong with what I am doing, and I am not able to figure it out.

    int adc_data;
    int main()
    {
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    while (!(SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0))){}
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    while (!(SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD))){}
    GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_2);


    ADCSequenceDisable(ADC0_BASE, 0);
    ADCReferenceSet(ADC0_BASE, ADC_REF_INT);
    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH13);
    ADCSequenceEnable(ADC0_BASE, 0);
    ADCIntClear(ADC0_BASE, 0);
    while (1){
    ADCProcessorTrigger(ADC0_BASE, 0);
    while(!ADCIntStatus(ADC0_BASE, 0, false)){}
    ADCIntClear(ADC0_BASE, 0);
    ADCSequenceDataGet(ADC0_BASE, 0, &adc_data);
    }
    return 0;
    }
  • Dear Jacobi,

    Comparing my code with single_ended.c was a good idea.

    The line below is the difference between my code and single_ended.c.

    ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 20000000);

    I added this line to my code. Now, the ADC is showing up an interrupt, and the code started working as it is expected to be. However, I still have no clue how system clock is affecting the ADC's interrupt, especially when I am only using processor trigger to initiate the ADC sampling process.

    Sagar

  • Hello Sagar,

    Honestly I should have seen that missing myself. For any software you first must configure the system clocks before configuring any peripherals. You'll see for all our examples, system clock is configured at the start of a program.