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 with ADC12MEM1

Hi,

I want to use P6.4 as one of the analog input and i need to take this signal from channel say channel 4,then i need to store it in ADC12MEM1.

So is my below code works for the same .

thank you.

#include <msp430.h>

int main(void)

{

 WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

 ADC12CTL0 = ADC12SHT02 + ADC12ON + ADC12MSC;         // Sampling time, ADC12 on

 ADC12CTL1 = ADC12SHP + ADC12CONSEQ_3;                     // Use sampling timer

 ADC12MCTL0 = ADC12INCH_0;                 // ref+=AVcc, channel = A0

 ADC12MCTL1 = ADC12INCH_4;                 // ref+=AVcc, channel = A1

 ADC12IE = 0x01;                           // Enable interrupt

 ADC12IE = BIT4;// Enable interrupt for channel 4

 ADC12CTL0 |= ADC12ENC;

 P6SEL |= 0x01;                            // P6.0 ADC option select

 P6SEL |= BIT4;// P6.4 ADC option select

 P6DIR |= BIT2 | BIT3 | BIT1;                     //for taking input for dc driver

 P4DIR |= BIT7; //for green led p4.7 output

 P1DIR |= 0x01;                            //for red led P1.0 output

 while (1)

 {

   ADC12CTL0 |= ADC12SC;                   // Start sampling/conversion

   __bis_SR_register(LPM0_bits + GIE);     // LPM0, ADC12_ISR will force exit

   __no_operation();                       // For debugger

 }

}

#pragma vector = ADC12_VECTOR

__interrupt void ADC12_ISR(void)

{

                                  // Vector  6:  ADC12IFG0

   if (ADC12MEM0 >= 0x7ff){                 // ADC12MEM = A0 > 0.5AVcc?

    if (ADC12MEM1 <= 0x0ff){

     P4OUT |= BIT7;                       // P1.0 = 0

         P1OUT &=~ BIT0;

         P6OUT &=~ BIT1;

         P6OUT &=~ BIT2;

         P6OUT &=~ BIT3;

    /* P1OUT |= BIT0;                        // P1.0 = 1

     P4OUT &=~ BIT7;

     P6OUT |= BIT1;

     P6OUT |= BIT2;

     P6OUT &=~ BIT3;*/

    }

   }

   else{

     P1OUT |= BIT0;                        // P1.0 = 1

         P4OUT &=~ BIT7;

         P6OUT |= BIT1;

         P6OUT |= BIT2;

         P6OUT &=~ BIT3;

     /*P4OUT |= BIT7;                       // P1.0 = 0

     P1OUT &=~ BIT0;

     P6OUT &=~ BIT1;

     P6OUT &=~ BIT2;

     P6OUT &=~ BIT3;*/

   }

   __bic_SR_register_on_exit(LPM0_bits);   // Exit active CPU

 }

**Attention** This is a public forum