cancel
Showing results for 
Search instead for 
Did you mean: 

UART - reading data from UART1 and sending it via UART2.

Frank Knarf
Associate II

Hi, I have some problem with UART. I configured two uarts (UART1 and UART2) both of them are working in DMA mode. I want to send data from PC to mcu-UART1 and after receiving it the same data should be sent to UART2. I prepared test env and almost all looks fine but when I'm sending data for example "0123456789", then on second terminal I'm receiving "02468". I mean each second char does anyone have idea what I'm doing wrong ?

Interrupt:

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){

HAL_UART_Transmit_DMA(&huart2, &RxBuff, 1);

HAL_UART_Receive_DMA(&huart1, &RxBuff, 1);

}

2 REPLIES 2
S.Ma
Principal

If you use DMA to transfer byte by byte, you will actually be using lots of bus cycles just to configure the DMA registers...

Have a look at my shared code for FIFO/LIFO. If you use them between serial peripherals in FIFO mode and use the FIFO callbacks to enable / disable UART interrupts (when there is nothing to feed), you'll get the job done in sequence and include timing fluctuations.

Using DMA for a single byte is probably overkill.

Using the same buffer for both the receive and transmit also seems chronically prone to issues.

If either function returned an error or failed, you wouldn't know.

Have two buffers, preferable with some depth, and manage the Rx and Tx independently.

Make sure the functions don't block, I'd look but the entire UART HAL implementation is a goat rodeo.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..