EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

MSP430 ADC & UART

Started by Taimoor November 17, 2005
Dear all,

I am completely new to the use of MSP430 family micro-controllers 
but I need to develop an application that utilizes the MSP430(F449) 
ADC and UART. I have 4 analogue inputs that need to be converted and 
then sent over the USART over RS-232. I am using IAR Embedded 
workbench. From the examples that I could get from the TI web-site, 
I am able to do 'something'. i.e. I can utilize the UART but I am 
not sure about the ADC. I apply a constant voltage to a pin and then 
run the debugger, still I get different values on ADC12MEMx. Is this 
inherent to ADC in MSP430 or some problem in the code? The code im 
using is at the end of mail. Please help!!

Regards,
Taimoor



#include  <msp430x44x.h>

void main(void)
{
  WDTCTL = WDTPW+WDTHOLD;               
  P6SEL = 0xFF;                         
  ADC12CTL0 = ADC12ON+MSC+SHT0_2; // Turn on ADC12, set sampling time
  ADC12CTL1 = SHP+CONSEQ_1; // Use sampling timer, single sequence
  ADC12MCTL4 = INCH_0;   // ref+=AVcc, channel = A4        
  ADC12MCTL5 = INCH_1;           
  ADC12MCTL6 = INCH_2;           
  ADC12MCTL7 = INCH_3+EOS;       
  ADC12IE = 0x08;                
  P2SEL = 0x30;                  

  ME1 |= UTXE0 + URXE0;          
  UCTL0 |= CHAR; 
  UTCTL0 |= SSEL0;
  UBR00 = 0x03;
  UBR10 = 0x00;
  UMCTL0 = 0x4A;                            // Modulation
  UCTL0 &= ~SWRST;                          // Initialize USART 
state machine
  IE1 |= URXIE0 + UTXIE0;                   // Enable USART0 RX/TX 
interrupt
  IFG1 &= ~UTXIFG0;                         // Clear inital flag on 
POR
  // UART Initialized
  ADC12CTL0 |= ENC;                         // Enable conversions
  _EINT();                                  // Enable interrupts

  while(1)
  {
    ADC12CTL0 |= ADC12SC;                   // Start conversion
    _BIS_SR(LPM0_bits);                     // Enter LPM0
  }
}

#pragma vectorC_VECTOR
__interrupt void ADC12ISR (void)
{
  results[0] = ADC12MEM4;                   // Move results, IFG is 
cleared
  TXBUF0 = ADC12MEM4;
  results[1] = ADC12MEM5;                   // Move results, IFG is 
cleared
  TXBUF0 = ADC12MEM5;
  results[2] = ADC12MEM6;                   // Move results, IFG is 
cleared
  TXBUF0 = ADC12MEM6;
  results[3] = ADC12MEM7;                   // Move results, IFG is 
cleared
  TXBUF0 = ADC12MEM7;
  TXBUF0 = 0x0A;
  _BIC_SR_IRQ(LPM0_bits);                   // Clear LPM0
  _NOP();                                   // SET BREAKPOINT HERE
}








Beginning Microcontrollers with the MSP430


The 2024 Embedded Online Conference