5
\$\begingroup\$

I am trying to read voltage values on two channels on eZ430-RF2500T, and transfer the result to the AP connected to a PC. Although I can successfully read from single channel, I am unable to do so using two channels.

Here is my code:

int * readPtr = (int *)0x200;
ADC10CTL1 = INCH_2 + CONSEQ_1;
ADC10CTL0 = REF2_5V + SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;
for (countDown = 240; countDown > 0; countDown--); //delay to allow references to settle

ADC10AE0 |= 0x06; //110

ADC10DTC1 = 0x02;                         // 2 conversions
ADC10SA = 0x200;                        // Data buffer start, same as readPtr above

ADC10CTL0 |= ENC + ADC10SC; //Sampling and conversion start
while(!(ADC10CTL0 & ADC10IFG)); // wait till the block conversion is complete
ADC10CTL0 &= ~ADC10IFG; //reset ADC10IFG
//code for reading from readPtr

Please note that no interrupts are being used; results are read after the ADC10IFG bit is set.

I am not getting ANY results with this code. The 'reading from readPtr' part is never reached.

However, if I set ADC10DTC1 to 0x01, I can read from the highest ordered pin. I.e. given that ADC10DTC1 is 0x01, I can read from A2 if INCH_2 is selected, and from A1 if INCH_1 is selected.

I am unable to get conversions for both A2 and A1, though.

Any help will be greatly appreciated.

Thanks!

EDIT: I am now trying to make this interrupt based. Not sure how to code it, though.

\$\endgroup\$
9
  • 1
    \$\begingroup\$ Can you provide a minimal example that shows the problem? \$\endgroup\$ Apr 29, 2011 at 21:10
  • \$\begingroup\$ Sorry for the earlier clutter. I have cut down the code pasted in question, and have also updated the question itself. Could you please have a look now? \$\endgroup\$
    – Chaitanya
    May 4, 2011 at 21:09
  • \$\begingroup\$ You're enabling interrupts in ADC10CTL0, yet you mention interrupts are not used. Is that intentional? \$\endgroup\$ May 4, 2011 at 23:31
  • \$\begingroup\$ @AustinPhillips, I think he is enabling setting of the flag, he is however not enabling the global flag for interrupts. This can be a dangerous practice as if global flag is set by another module it will result in the interrupt being serviced. If this happened and the code is not there it will cause your code to fail. \$\endgroup\$
    – Kortuk
    May 5, 2011 at 0:08
  • 1
    \$\begingroup\$ Could you help me in making this interrupt based? If there's an interrupt on DTC transfer complete, and if I read data in ISR, this could work. But I am a bit shaky when it comes to interrupts. \$\endgroup\$
    – Chaitanya
    May 5, 2011 at 14:12

1 Answer 1

3
\$\begingroup\$

I now have this working. ADC10 part is now similar to TI's samples.

This is the code that can read successfully from 4 pins simultaneously:

unsigned int res[5]; //for holding the conversion results
void main (void)
{ 

  //code for connecting to AP

  //reading voltage
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  ADC10CTL1 = INCH_4 + CONSEQ_1;            // A4/A3/A2/A1/A0, once multi channel
  ADC10CTL0 = REF2_5V + ADC10SHT_2 + MSC+ REFON + ADC10ON + ADC10IE; //2.5 reference voltage
  ADC10AE0 = 0x1F;                          // P2.0,1,2,3,4 ADC option select
  ADC10DTC1 = 0x5;                         // 5 conversions
  P1DIR |= 0x01;                            // Set P1.0 output

  for (;;)
  {
    P1OUT |= 0x01;                          // Set P1.0 LED on
    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
    P1OUT &= ~0x01;                         // Clear P1.0 LED off
  }

}

#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)
}

Thanks for the help!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.