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.

MSP430G2 ADC to UART help needed!

Other Parts Discussed in Thread: MSP430G2553

Hello!

I am trying to sample a signal through channel P1.4 on my msp430g2553 and then show it on hyper terminal on my pc.

This is the code i have so far. 

Nothing is showing on my screen so i would appreciate any help i can get on this!

I am a beginner so this stuff is quite new to me.

Thank you so much!!!

#include <msp430g2553.h>

volatile int sampling;
unsigned int buffer[1];
#define Green_LED BIT6
unsigned int TXByte; // Value sent over UART
unsigned int hex;
unsigned int low;
unsigned int middle;
unsigned int high;
unsigned int nibble;

void clockConfig()
{
// configure the CPU clock (MCLK)
// to run from DCO @ 16MHz and SMCLK = DCO / 4
BCSCTL1 = CALBC1_16MHZ; // Set DCO
DCOCTL = CALDCO_16MHZ;
BCSCTL2= DIVS_2 + DIVM_0; // divider=4 for SMCLK and 1 for MCLK
}

void adcConfig()
{

//ADC10SSEL_0 : ADC10OSC
// ADC10DIV_0 : ADC10 Clock Divider Select 0. Roughly 5MHz
// INCH_4 : highest channel we are going to sample
// CONSEQ_2 : repeat single channel
ADC10CTL1 = ADC10SSEL_0 + ADC10DIV_0 + INCH_4 + CONSEQ_2; //
// SREF_1 : VR+ = VREF+ and VR- = AVSS
// ADC10SHT_0 : Sample & Hold = 4 x ADC10CLKs
// REF2_5V : ADC10 Ref 0:1.5V / 1:2.5V;
ADC10CTL0 = SREF_1 + REF2_5V + REFON + ADC10SHT_0 + MSC + ADC10ON + ADC10IE;
ADC10AE0 |= BIT4; // P1.4 adc option for channel 4
ADC10DTC1 = 0x01; // number of channels to be sampled
__delay_cycles(1000); // Wait for ADC Ref to settle
}

// temporary interrupt routine to check that the ADC sequence is complete
unsigned int write(unsigned int nibble)
{
if(nibble <= 9)
UCA0TXBUF = (nibble + '0');
else
UCA0TXBUF = ((nibble-10) + 'A');

}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
sampling = 0;
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
hex = (unsigned int)&buffer ;
low = hex &0x0F;
middle = (hex &0xF0)>>4;
high = (hex &0xF0)>>4;
write(high);
write(middle);
write(low);
write(10);
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;//stop WDT
clockConfig();
adcConfig();

// UART START
BCSCTL1 = CALBC1_16MHZ; // Set DCO
DCOCTL = CALDCO_16MHZ;
BCSCTL2= DIVS_2 + DIVM_0; // divider=4 for SMCLK and 1 for MCLK
// set the pin mode 3 for pins 1 & 2 of port 1 (Uart mode)
P1SEL |= BIT1 + BIT2; // low bit = 1 for pin 1 and 2
P1SEL2 |= BIT1 + BIT2; // high bit = 1 for pin 1 and 2
// configure the UART
UCA0CTL0 = 0; //UART mode, No parity, LSB first, 8 data, 1 stop
UCA0CTL1 = UCSSEL_2; //use SCLK
// P1DIR |= (Green_LED); //Define GPIOs as outputs else GPIOs are inputs
UCA0BR0 = 0x1A;; //lower byte of UCBR0. 26dec
//(4MHz / 9600 baud) see table 15-5
UCA0BR1 = 0x0; //upper byte of UCBR0.set to 0
UCA0MCTL = UCBRF_1 + UCBRS_0 + UCOS16; //sets UCBRFx to 1,
// UCBRSx tto 0 , UCOS16=1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI **
UC0IE |= UCA0RXIE; // Enable USCI_A1 RX interrupt
_EINT(); // global enable interrupts

while (1)
{
ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & BUSY); // Wait if ADC10 core is active
sampling = 1;
ADC10SA = (unsigned int)&buffer; // Data buffer start
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // Enable interrupts
while(sampling>0); // wait until the sampling sequence is complete

}
}

// END UART

#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
UCA0TXBUF=UCA0RXBUF; // echo TX = RX
}

**Attention** This is a public forum