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.

ADC10 Multiple conversion

Other Parts Discussed in Thread: MSP430G2553

Hi, i am trying to have to adc conversion but it seems not to work. Below is my code:

#include "msp430g2553.h"


#define LED0 BIT0 //RED LED
#define LED1 BIT6 //GREEN LED


unsigned int res[2]; //for holding the conversion results


void main (void)
{

//reading voltage
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL1 = INCH_1 + ADC10DIV_0 + CONSEQ_3 + SHS_0; //A1/A0, multi channel repeated conversion
ADC10CTL0 = ADC10SHT_2 + MSC+ REFON + ADC10ON + ADC10IE; //2.5 reference voltage
ADC10AE0 = BIT1 + BIT0; // PIN A1 AND A0 ADC option select
ADC10DTC1 = 0x2; // 2 conversions
P1DIR &= ~(LED0 + LED1); // Set P1.0 output

for (;;)
{
ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & BUSY); // Wait if ADC10 core is active
ADC10SA = (int)res; // Data buffer start
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion ready
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
if(res[0]<512){
P1OUT &= ~(LED0 + LED1);
P1OUT |= LED0; // LED0 is on
}
elseif(res[1]<512){
P1OUT &= ~(LED0 + LED1);
P1OUT |= LED1; // LED1 is on
}
}

}

#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
//code from reading from res and sending it to AP
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}

I am a newbie to this, can anyone help me out? Thanks

  • P1DIR &= ~(LED0 + LED1); // Set P1.0 output                             =>             P1DIR &= 0x1011 1110b

    this will set P1.0 & P1.6 as input rather than output.

    Also you are using p1.0 for both analog input as well as led output which is not correct.


**Attention** This is a public forum