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.

MSP430F5529: Initializing ADC12_A for Single-Channel Single-Conversion Mode

Part Number: MSP430F5529

Hello, 

so I just want to read a value of a voltage on pin P6.5(A5) in a while loop with delay. 

My clock is initialized as 20MHz for MCLK, 10 MHz for SMCLK, and 32k for ACLK and they are all tested (I actually completed a graphical LCD driver based on SPI based on this clock which guarantees it is working properly)

that's the code : 

void ADC_init(void)
{
    P6SEL|=0x20;   //P6.5 is not GPIO
    P8DIR&=~0x20; //P6.5 is output

    ADC12CTL0&=~0x0002; //ADC12_A disable conversion ADC12ENC
    ADC12CTL0&=~0x0010; //ADC12_A is off    ADC12ON

    ADC12CTL0|=0x0400; //sample-and-hold time = 64 ADC12CLK cycles

    //The sampling timer requires a rising edge of the SHI signal to trigger each sample-and-convert.

    REFCTL0&=~0x0080; //REFMSTR=0, Reference system controlled by legacy control bits inside the ADC12_A module when available
    ADC12CTL0|=0x0020; //ADC12_A reference generator on. In devices with the REF module, this bit is only valid if the REFMSTR bit of the REF module is set to 0
    ADC12CTL0|=0x0040; //ADC12_A is the reference generator voltage and = 2.5V,this bit is only valid if the REFMSTR bit of the REF module is set to 0

    //ADC12SC start sample and conversion

     ADC12CTL1|=0x5000;  //conversion start address is ADC12MEM5

    //ADC12_A sample-and-hold source select is ADC12SC bit

    //ADC12_A sample-and-hold pulse-mode select : SAMPCON signal is sourced from the sample-input signal

    ADC12CTL1|=0x00E0;  //ADC12_A clock divider by 8
    ADC12CTL1|=0x0180;  //ADC12_A clock source is SMCLK

    //Single-channel, single-conversion

    ADC12CTL2|=0x0100; //ADC12_A predivider. This bit predivides the selected ADC12_A clock source Predivide by 4
    ADC12CTL2|=0x0080; //Temperature sensor off

    ADC12MCTL5|=0x0010; ADC12MCTL5&=~0x0060; //VR+ = VREF+ and VR- = AVSS
    ADC12MCTL5|=0x0005; ADC12MCTL5&=~0x0009;//channel select is A5

    __delay_cycles(100000);
}
unsigned short ADC_READ(void)
{
    unsigned short value=0;


    ADC12CTL0|=0x0010; //ADC12_A is On ADC12ON
    ADC12CTL0|=0x0001; //start sample and conversion ADC12SC
    ADC12CTL0|=0x0002; //ADC12_A enable conversion ADC12ENC

    //__delay_cycles(2000);

    while( (ADC12CTL1&0x0001) == 1 );
    value = ADC12MEM5;

    return value;

}

and that's in the main function 

 while(1)
	 {

	     volatile unsigned short value_of_adc= ADC_READ();
	     __delay_cycles(2000000);


	 }

I'm not getting real value, actually I'm getting a ZERO!

I don't care if we change reference to VCC, but I just wanted it to be connected to the ADC module 2.5 v reference.

Where is my problem?

**Attention** This is a public forum