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.

ADC12 always busy



I need to configure REFON, REF2_5V(for DAC) and all ADC12 bits.

Initialization procedure:

#define BIT10 0x400
#define BIT11 0x800
#define BIT12 0x1000
#define BIT13 0x2000
#define BIT14 0x4000
#define BIT15 0x8000

void init_ADC(void)
{
    ADC12CTL0&=~ENC;
 
    ADC12IE=0x0;
    if((ADC12CTL0&ENC)==1)
    {
    ADC12CTL0&=~ADC12ON;
    ADC12CTL0|=REF2_5V;
    ADC12CTL0|=REFON;
   
    ADC12CTL0&=~BIT7;

    ADC12CTL1&=~ADC12BUSY;
    if((ADC12CTL1&(!ADC12BUSY))==1)
    {
       
        ADC12CTL1&=~BIT7;
        ADC12CTL1&=~BIT6;
        ADC12CTL1&=~BIT5;
       
        ADC12CTL1&=~BIT11;
        ADC12CTL1&=~BIT10;
       
        ADC12CTL1&=~BIT8;
      
        ADC12CTL1&=~BIT9;
       
        ADC12CTL1&=~BIT15;
        ADC12CTL1&=~BIT14;
        ADC12CTL1&=~BIT13;
        ADC12CTL1&=~BIT12;
       
        ADC12CTL1&=~BIT2;
        ADC12CTL1&=~BIT1;
    }
   
    ADC12MCTL0&=~BIT6;
    ADC12MCTL0&=~BIT5;
    ADC12MCTL0|=BIT4;
   
    ADC12MCTL0&=~BIT3;
    ADC12MCTL0&=~BIT2;
    ADC12MCTL0&=~BIT1;
    ADC12MCTL0&=~BIT0;
  
    ADC12MCTL0|=BIT7;
   
    P6SEL|=0x01;
   
    ADC12CTL0 = ADC12ON;
    }
}

Sampling function:

unsigned int sampling_ADC(void)
{
  ADC12CTL0 |= ADC12SC+ ENC;   // Sampling open
  ADC12CTL0 &= ~ADC12SC;        // Sampling closed, start conversion
  while ((ADC12CTL1 & ADC12BUSY) == 1);   // ADC12BUSY?
 
  return(ADC12MEM0);    // return the value read from ADC P6.7
}

Then I call it in main:

while( 1 ) {
        
    int o= sampling_ADC();
    }

ADC12BUS always 1. Whats wrong ?

  • Are you sure this line is ok?

        if((ADC12CTL1&(!ADC12BUSY))==1)

    To be honest, init_ADC() is so messy that I can't read it. Hopefully someone else will be more patient or you fix your code using common practice of ADC12 init. Check source code examples, see how things can be done "other way".

  • Ivan Ivanov5 said:
    #define BIT10 0x400

    Those BIT definitions are already part of the default header files. No need to redo them

    Ivan Ivanov5 said:
       ADC12CTL1&=~BIT7;

    Why don't you use the predefined 'telling' symbols? With some syntactic rules, all bits have a define that matches the name of the bit in the register descriptions. Like REFON, REF2_5V etc, which you already use. So why all these BIT assignments?

    What MSP do you use? Most 5x family devices have a separate REF module that is active by default and overrides the reference-related bits in the ADC12 control registers. You can either use the configuration there or disable the REF module.

    Ivan Ivanov5 said:
        ADC12CTL1&=~ADC12BUSY;

    ADC12BUSY is read-only. You can't tell the ADC that it isn't busy anymore :) It will keep telling you that it is.

    I don't see you setting the ADC12SHP bit. This means when you set ADC12SC, the ADC starts sampling and continues to charge the sampling capacitor until you manually clear the ADC12SC bit to start the conversion.

**Attention** This is a public forum