Missing bytes over UART, any way to recover?

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
albinhj
Posts: 6
Joined: Mon Jun 26, 2023 10:53 am
Been thanked: 3 times

Missing bytes over UART, any way to recover?

Postby albinhj » Fri Jul 28, 2023 9:55 am

Hi,

STM32L4.

I'm using UART for time critical communication, where I at a regular interval send three bytes from one controller to another. There is a short pause between every transmission, where the data is being processed, before the next transmission is expected again.

I start the reception like this:

Code: Select all

uartStartReceive(&UARTD4, 3, _rxbuf);

Then I have a receive callback, that processes this data, and then calls that same command again.

This works, mostly. But I also have some noise on my communication line (sometimes NOISE_ERROR gets triggered on the error callback), which I suspect causes my problems. What I'm seeing is that my reception gets unsynchronized.

For example:
I expect: 0xAA 0xBB 0xCC
I get: 0xAA 0xBB 0xAA, then 0xCC 0xAA 0xBB, for example..

It's seems to me like one of the bytes gets missed in one instance, and then I get out of synch, always reading three bytes but from different "packages" or something.

What I want is to receive three consecutive bytes. Is there a way to use the HAL driver to achieve this? Can an error be set by the driver? Or can I check somehow if this was the case?

User avatar
Giovanni
Site Admin
Posts: 14458
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Missing bytes over UART, any way to recover?

Postby Giovanni » Fri Jul 28, 2023 10:21 am

Hi,

You need to manage timeouts in your protocol, errors happen.

A possible approach is to start a timer together with the receive operation and stop the receive if the timer is triggered.

Giovanni

albinhj
Posts: 6
Joined: Mon Jun 26, 2023 10:53 am
Been thanked: 3 times

Re: Missing bytes over UART, any way to recover?

Postby albinhj » Thu Aug 03, 2023 3:39 pm

Hi,

Small update. After some experimentation, I've found a way using the IDLE line detection to help me work around the problem.

Best regards


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 5 guests