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.

CCS/MSP432P401R: UART Write Multiple Times

Part Number: MSP432P401R


Tool/software: Code Composer Studio

Hello, 

I am using the UART.h driver and I want to be able to write individual commands one after another. For example... 

uint8_t stopText[13] = {0xA5, 0x5A, 0x0A, 0x82, 0x01, 0xF2, 0x53, 0x54, 0x4f,
                        0x50, 0x50, 0x45, 0x44};
uint8_t stopColor[8] = {0xA5, 0x5A, 0x05, 0x82, 0x40, 0x03, 0x88, 0x02};

UART_write(uart, stopText, sizeof(stopText));
UART_write(uart, stopColor, sizeof(stopColor));

When I have this set of commands, I run into an issue where the second UART_write is not written. 

My Uart initialization is run in a task and is as follows : 

void uartRxFxn(UArg a0, UArg a1){
    // Init UART
    UART_init();
    // Specify non-default parameters
    UART_Params_init(&uartParams);
    uartParams.baudRate      = 9600;
    uartParams.writeMode     = UART_MODE_CALLBACK;
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.writeCallback = writeCallback;
    uartParams.readMode      = UART_MODE_CALLBACK;
    uartParams.readDataMode  = UART_DATA_BINARY;
    uartParams.readCallback  = readCallback;
    uartParams.readReturnMode = UART_RETURN_FULL;

    // Open the UART and initiate the first read
    uart = UART_open(CONFIG_UART_0, &uartParams);
    UART_write(uart, tester, sizeof(tester));
    wantedRxBytes = 9;
    int rxBytes = UART_read(uart, rxBuf, wantedRxBytes);
}

Please help as it is very imporant that I do not have to create a long message for every single combination of commands I want to send. 

Cheers!

  • Adam Reid said:
    When I have this set of commands, I run into an issue where the second UART_write is not written. 

    My Uart initialization is run in a task and is as follows : 

    The UART initialisation uses UART_MODE_CALLBACK as the writeMode.

    The code shows two back-to-back calls to UART_write with no interaction with the callback function.

    The documentation for UART_write has:

    In UART_MODE_CALLBACK, UART_write() does not block task execution. Instead, a callback function specified by UART_Params::writeCallback is called when the transfer is finished.

    Without looking at the UART driver code, I am not sure what happens if UART_write is called in UART_MODE_CALLBACK when the preceding UART_write hasn't finished writing to the UART.

    If you change the writeMode to UART_MODE_BLOCKING, then a call to UART_write will block until all the data in the buffer has been written.

    Does your code need to use UART_MODE_CALLBACK for a specific reason?