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!