cancel
Showing results for 
Search instead for 
Did you mean: 

First byte of USART data received through DMA is not the right one

Hugues Libotte
Associate III

Hello.

I am using the STM32F030 for a sensor with a RS485 interface.

In my tests, I am sending a 8-bits message (constant value) to the STM32 in a loop. When I look at the data received, the last byte is at the first place, always. There is never any other or additional shift.

I can understand it is byte remaining from the previous comm and missed out from the previous reading but why is it so stable (always one byte and always the correct one).

Any idea about the reason of this ? And more usefull, do you have any method to clear the DMA buffer before starting reading ? Would you recommand the use of a circular buffer for the DMA ?

On one side (transmitter)

message_TX[0] = 0x02; ...; message_TX[6]= 0xDE ; message_TX[7] = 0xAC;

HAL_UART_Transmit_DMA(&huart1, (uint8_t*)message_TX, 8);

On the other side (receiver)

HAL_UART_Receive_DMA(&huart1, (uint8_t *)message_RX , 8);

And I get the following data in message_RX[0] = 0xAC (always) and message_RX[7] =0xDE (always)

Any suggestion for me ?

 

10 REPLIES 10

Are the transmitted data echoed? What happens if you make a large Rx buffer (at least sum of both Tx and Rx message) and start Rx DMA *before* Tx?

JW