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.

MSP432P401R: UART TransmitData Function Hangs while Looping Through Data to Send

Part Number: MSP432P401R

Hello All,

I have been working on a program that will allow me to send data at the start of the application and then only listen afterwards. At the moment, I have Rx and Tx shorted together to form a loopback on the MSP432 Launchpad. I am testing the program and it seems that I am receiving two bytes of the sent message and then the following function

void UART_transmitData(uint32_t moduleInstance, uint_fast8_t transmitData)
{
    /* If interrupts are not used, poll for flags */
    if (!BITBAND_PERI(EUSCI_A_CMSIS(moduleInstance)->rIE.r, UCTXIE_OFS))
        while (!BITBAND_PERI(EUSCI_A_CMSIS(moduleInstance)->rIFG.r, UCTXIFG_OFS))
            ;

    EUSCI_A_CMSIS(moduleInstance)->rTXBUF.r = transmitData;
}

hangs on the

while (!BITBAND_PERI(EUSCI_A_CMSIS(moduleInstance)->rIFG.r, UCTXIFG_OFS))

line. I suspect its because the transmit interrupt flag is not being thrown for some reason. Here is the remainder of my code:

/******************************************************************************
 * MSP432 UART - Arduino with 12MHz BRCLK
 *
 * Description: This program communicates with the Talos's Arduino platform.
 * SMCLK/DCO is used as a clock source and the device is put in LPM0
 * The auto-clock enable feature is used by the eUSCI and SMCLK is turned off
 * when the UART is idle and turned on when a receive edge is detected.
 * Note that level shifter hardware is needed to shift between RS232 and MSP
 * voltage levels.
 *
 *               MSP432P401
 *             -----------------
 *            |                 |
 *            |                 |
 *            |                 |
 *       RST -|     P1.3/UCA0TXD|----> Arduino Rx
 *            |                 |
 *            |                 |
 *            |     P1.2/UCA0RXD|<---- Arduino Tx
 *            |                 |
 *
 *******************************************************************************/
/* DriverLib Includes */
#include <driverlib.h>

/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>

/*
 * Functions that control what happens when bytes are transmitted and received
 */
void receiveOperation();
void transmitOperation(char* txData);

/*
 * Functions needed for the receive function
 */
volatile char receiveBuffer[100];
volatile i = 0;

//![Simple UART Config]
/* UART Configuration Parameter. These are the configuration parameters to
 * make the eUSCI A UART module to operate with a 9600 baud rate. These
 * values were calculated using the online calculator that TI provides
 * at:
 *software-dl.ti.com/.../index.html
 */
const eUSCI_UART_Config uartConfig =
{
        EUSCI_A_UART_CLOCKSOURCE_SMCLK,          // SMCLK Clock Source
        78,                                     // BRDIV = 78
        2,                                       // UCxBRF = 2
        0,                                       // UCxBRS = 0
        EUSCI_A_UART_NO_PARITY,                  // No Parity
        EUSCI_A_UART_LSB_FIRST,                  // LSB First
        EUSCI_A_UART_ONE_STOP_BIT,               // One stop bit
        EUSCI_A_UART_MODE,                       // UART mode
        EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION,  // Oversampling
};
//![Simple UART Config]

int main(void)
{
    /* Halting WDT  */
    MAP_WDT_A_holdTimer();

    /* Selecting P1.2 and P1.3 in UART mode */
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
            GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);

    /* Setting DCO to 12MHz */
    CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12);

    //![Simple UART Example]
    /* Configuring UART Module */
    MAP_UART_initModule(EUSCI_A0_BASE, &uartConfig);

    /* Enable UART module */
    MAP_UART_enableModule(EUSCI_A0_BASE);

    /* Enabling interrupts */
    MAP_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);
    MAP_Interrupt_enableInterrupt(INT_EUSCIA0);
    MAP_Interrupt_enableSleepOnIsrExit();
    MAP_Interrupt_enableMaster();
    //![Simple UART Example]

    /*
     * 174 150 45 174 100 30 174 150 35 221
     * [START_BYTE] [ENABLE/DISABLE] [PIN SELECTION] [START_BYTE] [ENABLE/DISABLE] [PIN SELECTION] [START_BYTE] [ENABLE/DISABLE] [PIN SELECTION] [TERMINATION]
    */
    char* txData = "17415045174100301741503517410040221"; // Data to send to Arduino to enable specific pins

    transmitOperation(txData); // Transmit txData to Arduino PCB
    while(1)
    {
        MAP_PCM_gotoLPM0();
    }
}

/* EUSCI A0 UART ISR - Echoes data back to PC host */
void EUSCIA0_IRQHandler(void)
{
    uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A0_BASE); // Get interrupt value of Emulated Serial A0 Base Address

    if(status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG) // Check to see if interrupt variable triggered and if receive flag was thrown
    {
        receiveBuffer[i] = MAP_UART_receiveData(EUSCI_A0_BASE); // Check for data in the UART Rx Register
        if((receiveBuffer[i]=='1') && (receiveBuffer[i-1]=='2') && (receiveBuffer[i-2]=='2')) // Check to see if the last values are the terminating byte
        {
           receiveOperation(); // Print Acknowledgments
           i = 0; // Reset increment i
        }
        else // Otherwise
        {
          i++; // Increment i
        }
    }
}

/*
 * Receive Operation. Checks acknowledgments by comparing the send data to the receive acknowledgment
 */
void receiveOperation()
{
    char* string= ""; // Create a character string

    string = receiveBuffer; // Set that equal to the receive buffer of UART

    if(string[0] == '3' && string[1] == '0' && string[2] == '0') // Check for acknowledgment
    {
        printf("Acknowledgment Received: %s \n",string); // Print the Acknowledgment
    }
}

/*
 * Transmit the data stored in the txData character array
 */
void transmitOperation(char* txData)
{
    int j = 0; // Create a new increment variable

    while(txData[j]) // While j does not reach the end of txData
    {
        MAP_UART_transmitData(EUSCI_A0_BASE, txData[j]); // Transmit a byte of data from txData
        j++; // Increment a pointer within txData
    }
}

Thank you for your time!