Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5779

General • Getting Out Of A UART Framing Error

$
0
0
I have a setup where a Pico monitors a hardware device. The hardware device emits a string on its UART with a timestamp and status like this:

2024-12-12T14:03: Status=GOOD
or
2024-12-12T14:04: Status=ERROR

A Pico is connected to the device's UART which continuously scans the UART stream for the ERROR string. If the ERROR string is detected the Pico signals another device to handle it.

All of this is working perfectly however there is one snag...

At any given point in time the hardware device can be reset. This causes the Pico to experience framing errors and it fails detecting future errors in the UART stream.

I cannot make any changes to the hardware device itself. I can only make changes to the Pico firmware.

In order to replicate this I made a simple python program which writes data to an FTDI UART device and the Pico parsing it.

The Pico code consists of a small menu which can dump the status of of the RSR register and the last bytes received.

The code for reading the UART looks like this:

Code:

while (1){        if (uart_is_readable_within_us(uart1, 200))        {            uart_read_blocking(uart1, &data, 1);            ... pattern match code ..        }        else        {            if (uart_get_hw(uart1)->rsr)            {                hw_clear_bits(&uart_get_hw(uart1)->rsr, UART_UARTRSR_BITS);            }        }}
The detection code runs in core1 while the menu runs in core0.
To simulate the framing error I disconnect and reconnect the RX line.
When I detect the framing error I reset the RSR register but this does not seem to have any effect.

Are there any other registers/settings in the UART module I need to modify in order to get out of this framing error ?

In the error situation the stream is still active but it looks like there is a difference in expected baud rate and actual.

Does anyone have any suggestions to how I might get out of this framing error and reset the stream correctly ?

Statistics: Posted by skullhornet — Fri Dec 13, 2024 9:38 am



Viewing all articles
Browse latest Browse all 5779

Trending Articles