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: Using UART to display ADC values

Part Number: MSP430F5529

Please from the code below, I intend to use the UART to display ADC values, but I'm confused at the UART part of the code.

#include "driverlib.h"

volatile uint16_t results[4];

#define BAUD_RATE                               9600
#define RECEIVE_DATA_COUNT                      0x02
#define USCI_A_UART_MULTIPROCESSOR_MODE_ADDRESS        0xAA

uint8_t receivedData = 0x00;
uint8_t receiveDataCount = 0x00;

void main (void)
{
    //Stop Watchdog Timer
    WDT_A_hold(WDT_A_BASE);

    //Enable A/D channel inputs
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 +
        GPIO_PIN3
        );

    //P3.4,5 = USCI_A0 TXD/RXD
    GPIO_setAsPeripheralModuleFunctionInputPin(
        GPIO_PORT_P3,
        GPIO_PIN4 + GPIO_PIN5
        );

    //Initialize the ADC12_A Module
    ADC12_A_init(ADC12_A_BASE,
        ADC12_A_SAMPLEHOLDSOURCE_SC,
        ADC12_A_CLOCKSOURCE_ADC12OSC,
        ADC12_A_CLOCKDIVIDER_6);

    ADC12_A_enable(ADC12_A_BASE);

    ADC12_A_setupSamplingTimer(ADC12_A_BASE,
        ADC12_A_CYCLEHOLD_16_CYCLES,
        ADC12_A_CYCLEHOLD_4_CYCLES,
        ADC12_A_MULTIPLESAMPLESENABLE);

    //Configure Memory Buffers
    ADC12_A_configureMemoryParam param0 = {0};
    param0.memoryBufferControlIndex = ADC12_A_MEMORY_0;
    param0.inputSourceSelect = ADC12_A_INPUT_A0;
    param0.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
    param0.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
    param0.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
    ADC12_A_configureMemory(ADC12_A_BASE ,&param0);

    //Configure memory buffer 1
    ADC12_A_configureMemoryParam param1 = {0};
    param1.memoryBufferControlIndex = ADC12_A_MEMORY_1;
    param1.inputSourceSelect = ADC12_A_INPUT_A1;
    param1.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
    param1.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
    param1.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
    ADC12_A_configureMemory(ADC12_A_BASE ,&param1);


    //Configure memory buffer 2
    ADC12_A_configureMemoryParam param2 = {0};
    param2.memoryBufferControlIndex = ADC12_A_MEMORY_2;
    param2.inputSourceSelect = ADC12_A_INPUT_A2;
    param2.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
    param2.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
    param2.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
    ADC12_A_configureMemory(ADC12_A_BASE ,&param2);


    //Configure memory buffer 3
    ADC12_A_configureMemoryParam param3 = {0};
    param3.memoryBufferControlIndex = ADC12_A_MEMORY_3;
    param3.inputSourceSelect = ADC12_A_INPUT_A3;
    param3.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
    param3.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
    param3.endOfSequence = ADC12_A_ENDOFSEQUENCE;
    ADC12_A_configureMemory(ADC12_A_BASE ,&param3);

    //Enable memory buffer 3 interrupt
    ADC12_A_clearInterrupt(ADC12_A_BASE,
        ADC12IE3);
    ADC12_A_enableInterrupt(ADC12_A_BASE,
        ADC12IE3);

    while (1)
    {
        //Enable/Start first sampling and conversion cycle
        ADC12_A_startConversion(ADC12_A_BASE,
            ADC12_A_MEMORY_0,
            ADC12_A_SEQOFCHANNELS);

// UART CONFIGURATIONS STARTS  --------------------------------------
        //Initialize USCI UART
        //Baudrate = 9600, clock freq = 1.048MHz
        //UCBRx = 109, UCBRFx = 0, UCBRSx = 2, UCOS16 = 0
        USCI_A_UART_initParam param = {0};
        param.selectClockSource = USCI_A_UART_CLOCKSOURCE_ACLK;
        param.clockPrescalar = 109;
        param.firstModReg = 0;
        param.secondModReg = 2;
        param.parity = USCI_A_UART_NO_PARITY;
        param.msborLsbFirst = USCI_A_UART_MSB_FIRST;
        param.numberofStopBits = USCI_A_UART_ONE_STOP_BIT;
        param.uartMode = USCI_A_UART_ADDRESS_BIT_MULTI_PROCESSOR_MODE;
        param.overSampling = USCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION;
        if ( STATUS_FAIL == USCI_A_UART_init(USCI_A0_BASE, &param)){
            return;
        }

        //Enable UART module for operation
        USCI_A_UART_enable(USCI_A0_BASE);

        //Set USCI UART in sleep mode
        USCI_A_UART_setDormant(USCI_A0_BASE);

        //Enable Receive Interrupt
        USCI_A_UART_clearInterrupt(USCI_A0_BASE,
            USCI_A_UART_RECEIVE_INTERRUPT
            );
        USCI_A_UART_enableInterrupt(USCI_A0_BASE,
            USCI_A_UART_RECEIVE_INTERRUPT
            );

 // UART CONFIGURATIONS ENDS  ------------------------------


        //Enter LPM3, interrupts enabled
        __bis_SR_register(LPM3_bits + GIE);

        //Enter LPM4, Enable interrupts
        __bis_SR_register(LPM4_bits + GIE);

        //For debugger
        __no_operation();
    }
}

//ADC INTERRUPT CONFIGURATION

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC12_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(ADC12_VECTOR)))
#endif
void ADC12ISR (void)
{
    switch (__even_in_range(ADC12IV,34)){
        case  0: break;   //Vector  0:  No interrupt
        case  2: break;   //Vector  2:  ADC overflow
        case  4: break;   //Vector  4:  ADC timing overflow
        case  6: break;   //Vector  6:  ADC12IFG0
        case  8: break;   //Vector  8:  ADC12IFG1
        case 10: break;   //Vector 10:  ADC12IFG2
        case 12:          //Vector 12:  ADC12IFG3
            //Move results, IFG is cleared
            results[0] =
                ADC12_A_getResults(ADC12_A_BASE,
                    ADC12_A_MEMORY_0);
            //Move results, IFG is cleared
            results[1] =
                ADC12_A_getResults(ADC12_A_BASE,
                    ADC12_A_MEMORY_1);
            //Move results, IFG is cleared
            results[2] =
                ADC12_A_getResults(ADC12_A_BASE,
                    ADC12_A_MEMORY_2);
            //Move results, IFG is cleared
            results[3] =
                ADC12_A_getResults(ADC12_A_BASE,
                    ADC12_A_MEMORY_3);

            //Exit active CPU, SET BREAKPOINT HERE
            __bic_SR_register_on_exit(LPM4_bits);
        case 14: break;   //Vector 14:  ADC12IFG4
        case 16: break;   //Vector 16:  ADC12IFG5
        case 18: break;   //Vector 18:  ADC12IFG6
        case 20: break;   //Vector 20:  ADC12IFG7
        case 22: break;   //Vector 22:  ADC12IFG8
        case 24: break;   //Vector 24:  ADC12IFG9
        case 26: break;   //Vector 26:  ADC12IFG10
        case 28: break;   //Vector 28:  ADC12IFG11
        case 30: break;   //Vector 30:  ADC12IFG12
        case 32: break;   //Vector 32:  ADC12IFG13
        case 34: break;   //Vector 34:  ADC12IFG14
        default: break;
    }
}



//UART INTERRUPT CONFIGURATION

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(USCI_A0_VECTOR)))
#endif
void USCI_A0_ISR (void)
{
    switch (__even_in_range(UCA0IV,4)){
        //Vector 2 - RXIFG
        case 2:

            //Receive the data
            receivedData = USCI_A_UART_receiveData(USCI_A0_BASE);

            if (receiveDataCount){
                receiveDataCount--;
                //If RECEIVE_DATA_COUNT number of data received go into dormant mode
                if (0x00 == receiveDataCount){
                    USCI_A_UART_setDormant(USCI_A0_BASE);
                }
            } else   {
                //If address received, wake up from dormant mode for more data
                if (USCI_A_UART_MULTIPROCESSOR_MODE_ADDRESS == receivedData){
                    USCI_A_UART_resetDormant(USCI_A0_BASE);
                    receiveDataCount = RECEIVE_DATA_COUNT;
                }
            }
            //Send data back "echo"
            USCI_A_UART_transmitData(USCI_A0_BASE,
            receivedData
            );

            break;
        default: break;
    }
}


**Attention** This is a public forum