cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with frame reception in UART DMA

laesser
Associate II

Hello,

 

I am using the dma to receive data into the uart using the functions:

 

HAL_UARTEx_ReceiveToIdle_DMA(&huart2, UART_p.UART_Data, UART_DATA_LENGTH));

 

with UART_DATA_LENGTH = 200.

 

void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size);

 

DMA is configured in normal mode.

Everything works fine with frames < 100 characters but if I receive a frame > 100 characters then
the Size variable is equal to 100 while I have 130 characters. This then poses a problem for me when processing this frame in JSON.

Strange thing UART_Data is cut in two when I view it in debug mode.

laesser_1-1721909996286.png

Thanks for your help.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
laesser
Associate II

Ok it seems that the problem came from teraterm, with another hyperterminal the frame is transmitted correctly.

Thanks for your help.

View solution in original post

4 REPLIES 4
TDK
Guru

HAL_UARTEx_RxEventCallback is called under 3 conditions:

  • When the half-transfer complete interrupt happens
  • When the full transfer complete interrupt happens
  • When the idle interrupt happens.

It will be called multiple times if your message is more than half the buffer length. The first time, with the first half of the buffer and the second time when idle happens with the remaining 30 characters.

If that doesn't work for you, consider increasing your buffer so all messages are captured in the first half of the buffer.

If you feel a post has answered your question, please click "Accept as Solution".

Thanks for you answer, to avoid the half transfer IT I use this 

__HAL_DMA_DISABLE_IT(huart2.hdmarx, DMA_IT_HT); // Disable Half Transfer interrupt

So I shouldn't have this problem, does it?

Update: I increase my buffer size to 400 and I still only receive 100 characters.

Disabling the interrupt will likely prevent the functions from working as intended. If you want to use HAL, you have to follow the usage rules.

If you're only receiving 100 characters, perhaps there the line goes idle there. Show it on a scope to confirm. Could also be a code bug, but the only interrupt that can happen at 100 characters if your buffer is 400 is idle.

If you feel a post has answered your question, please click "Accept as Solution".
laesser
Associate II

Ok it seems that the problem came from teraterm, with another hyperterminal the frame is transmitted correctly.

Thanks for your help.