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/CC1352R: UART2_write not waiting for transmission in blocking mode

Part Number: CC1352R

Tool/software: Code Composer Studio, sdk 4_30_00_54

Hello!

I use the UART2 module to work on the RS485 interface. As a RS485 driver, I use the TD331S485H-E microcircuit. The microcircuit has a control pin - CON (in the program it is CONFIG_GPIO_485_DIR), if it is 1, then RX works, if it is 0, then TX.


The program code is as follows:
// ...........
/ * Create a UART in CALLBACK read mode * /
UART2_Params_init (& uartParams);
uartParams.readMode = UART2_Mode_CALLBACK;
uartParams.readCallback = callbackFxnR;
uartParams.baudRate = 115200;

uart = UART2_open (CONFIG_UART2_0, & uartParams);

if (uart == NULL) {
/ * UART2_open () failed * /
while (1);
}
// ...............
/ * Loop forever echoing * /
while (1) {
numBytesRead = 0;

/ * Pass NULL for bytesRead since it's not used in this example * /
GPIO_write (CONFIG_GPIO_485_DIR, 1);
status = UART2_read (uart, & input [0], 10, NULL);
if (status! = UART2_STATUS_SUCCESS) {
/ * UART2_read () failed * /
while (1);
}

/ * Do not write until read callback executes * /
sem_wait (& sem);

if (numBytesRead> 0) {
// ... filling the 255 byte input buffer with data

GPIO_write(CONFIG_GPIO_485_DIR, 0);

status = UART2_write (uart, & input [0], 255, & numBytesWritten);

if (status! = UART2_STATUS_SUCCESS) {
/ * UART2_write () failed * /
while (1);
}
}
}

/ *
* ======== callbackFxnR ========
* /
void callbackFxnR (UART2_Handle handle, void * buffer, size_t count,
void * userArg, int_fast16_t status)
{
if (status! = UART2_STATUS_SUCCESS) {
/ * RX error occured in UART2_read () * /
while (1);
}

numBytesRead = count;
sem_post (& sem);
}

Reading from UART works in callback mode, writing in blocking mode.
The problem is as follows: after executing UART2_write, the program goes to the beginning of the while (1) loop and the CON input switches to receive data with the command "GPIO_write (CONFIG_GPIO_485_DIR, 1)" and we see that the UART actually transmitted about 191 bytes of data instead of 255. It turns out, that the exit from the function is performed before all data has been transferred. If after executing UART2_write you put a delay, for example sleep (2), then all data will be transferred. From this I conclude that the return from UART2_write is performed before all data is transferred.

How to solve this problem?

P.S. If you use writing in callback mode, the result is the same - the callback is executed before all the data has been transferred.

Thanks!

  • Hi Alex

    I am not familiar with the HW (TD331S485H-E) you are using so not sure how that will affect things.

    I would recommend that you start by checking that you can send and receive what you want to a serial session (e.g. PuTTY, etc.).

    I modified the UART2_Echo example in the SDK to transmit 250 bytes for every bytes received, and that worked fine.

    BR

    Siri

  • Hi 

    Siri,

    I think I understand what is the reason. The exit from the UART2_write function is performed before the end of the DMA transfer work. How did I determine this? I put a breakpoint right after UART2_write, and in putty I see that not all data has been transferred. If you take one more step in debugging, then in putty we see all the data. How can you track when a DMA has completed work?

    Thanks!

  • Hi Alex

    There seem to be a problem related to the driver releasing the write semaphore based on when the DMA TX operations is done, but before the before the EoT interrupt has fired.

    This has been reported as a bug to the driver team.

    AS a temp. workaround you can try to add a Task_sleep after your UART2_write

    BR

    Siri