2024-10-25 07:29 AM
Hello,
Using HAL_UART_Receive_DMA() function and expecting an N length message, so have set the buffer length and transfer size to N.
The communicating equipment sometimes adds an extra character / or drops a character which is taking my DMA out of synchronisation.
Once out of synchronisation it is then staying like this until a reset occurs.
I can capture that it is out of sync and log a data error. When this occurs I would like to restart the DMA so that the data is resynchronised.
Example of the problem below:
Normal Operation Receive Bytes: 1, 2, 3, 4, ... N
When out of Sync every receive now looks like: 2, 3, 4, ... N, 1
What functions are in the HAL that allow me to resynchronise the DMA in the best way?
Thanks in advance.
PS - Have moved away from using DMA to IDLE as the connecting equipment sometimes drips feeds bytes in a disorderly fashion.
2024-11-18 04:17 AM
May be you should analyze the buffer to check for some marker such as \r\n or STX character, subtract from the total bytes to receive, and call dma for the balance bytes. Then again start for the full bytes in the next cycle.