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.

MSP430 ADC12 AND UART

Other Parts Discussed in Thread: MSP430F5438A

Hi to all,

    I am new for msp430 microcontroller, and i have studied the register configuration for both uart and adc12. Based on that i have done a program for that and it is not working properly. Please verify my code and give me some solution.

    I have one more doubt, I want to use DMA to transferring data fastly, and give me the idea how to configure DMA in the below program, whether i have to use uart trigger or ADC12 trigger for DMA. Thank you

#include "msp430f5438A.h"
#include <stdio.h>
void ADC_init(void);

char string[256];
unsigned int i = 0;
unsigned int ANALOG_SIG = 0;

void main(void)
{
WDTCTL = WDTPW + WDTHOLD;

P5SEL |= BIT6 + BIT7;

ADC_init();

while(1)

UCA1CTL1 |= UCSWRST; // ENABLE RESET
UCA1CTL1 |= UCSSEL_2; // CLOCK SELECTION SMCLK
UCA1BR0 = 9; // 1MHZ = 115200
UCA1BR1 = 0; // 1MHZ = 115200
UCA1MCTL |= UCBRS_1 + UCBRF_0;
UCA1CTL1 &= ~UCSWRST; // RELEASE RESET

sprintf(string,"\t%d",ANALOG_SIG);
while(buffer[i])
{
while(!(UCA1IFG&UCTXIFG)); // USART0 TX buffer ready?
UCA1TXBUF = string[i++];
}

__bis_SR_register(LPM0_bits + GIE);
}

void ADC_init(void)
{

P6SEL |= 0x80; // Enable A/D channel A7
PBDIR |= 0xFFFF;

REFCTL0 = REFMSTR + REFON + REFVSEL_2 + REFTCOFF;
// REF MASTER ENABLE + REF ON + 2.5V + TEMP.SENS OFF

ADC12CTL0 = ADC12ON+ADC12SHT0_1 + ADC12MSC;
// ADC12_A CORE ON + 8 ADC12CLK CYCLE FOR SAMPLING + MULTIPLE SAMPLE AND CONVERSION

ADC12CTL1 = ADC12CSTARTADD_7 + ADC12SHP + ADC12SHS_0 + ADC12DIV_0 + ADC12SSEL_3 + ADC12CONSEQ_2;
// CONV. START ADDR + SAMPLING TIMER TRIGGER + SAMPLE AND HOLD SELECT ADC12SC
// CLK DIVIDE_1 + ADC12OSC CLK + REPEAT SINGLE CH MODE

ADC12CTL2 = ADC12RES_0;
// 12-BIT RESOLUTION

ADC12MCTL7 = ADC12SREF_1 + ADC12INCH_7;
// VR+ = 2.5V; VR- = AVSS + CHANNEL 7 SELECT

ADC12CTL0 |= ADC12ENC; // CONVERSION ENABLE
ADC12CTL0 |= ADC12SC; // CONVERSION START
ADC12IE |= ADC12IE7; // For debugger
}


#pragma vector=ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
ANALOG_SIG = ADC12MEM7;

__bic_SR_register_on_exit(LPM0_bits); // INTERRUPT ENABLE
}

  • hi PRASANTH S,

    Could you give some more details about the issues when you run the code?

    BTW, I found the code you shared is not the entire source code which I can't find any definition about the buffer[i] and there is a "while(1)" without ";" which should not pass the compiling process. Could you share the entire source code?

**Attention** This is a public forum