Skip to content

Serial1.available() reporting bytes available when none are available #1021

@chrisckc

Description

@chrisckc

I created quick a test harness to verify UART communications between 2 Pico's:
https://github.com/chrisckc/TestHarness-UART
It is based on the SPI master-slave example from the Pico examples repo.
The 2 Pico's are wired together on a breadboard with grounds, VBUS and VSYS connected together.
Pin 1 (GP0, UART0_TX) is connected to Pin2 (GP1, UART0_RX) on the other pico and vice versa.

The sending pico waits for one second after the receiving pico is initialised, ie. until it is ready by repeatedly checking Serial1.available(). After this one second wait time, the sending Pico sends data to the receiving pico, the first is a single byte indicating the length of the next set of data which is a 255 byte buffer of incrementing test data bytes starting 0x01, then 0x02, up to 0xFF.

The receiving Pico then sends back an inverted version of the buffer back to the sending Pico.

What I am seeing on both ends is that Serial1.available() is reporting that a byte is available before anything has actually arrived, this happens once at the start and results in errors reported because the subsequent calls to Serial1.read() and Serial1.readBytes(buf, length) return zero's.

When the Pico actually receives UART data it works correctly, it reports 1 byte (the first transmission informing the length of the next set of data) and is also able to correctly read the next 255 bytes using Serial1.readBytes(buf, length).

The scope traces below demonstrate the issue:
The yellow trace is DEBUG_PIN2 in the test code for the receiving Pico, green is DEBUG_PIN3 on the receiving Pico.
Blue is the RX line on the receiving pico, purple is the TX line on the receiving Pico.
ScreenImg-50

The yellow low pulse marks Serial1.available() reporting a value > 0, but as can be seen there was data on the RX line.
The receiver then sends data back to the sender as seen by the purple trace.

Zooming out further shows from the moment of powering on the 2 Pico's, there are no extraneous pulses on the RX line.
ScreenImg-51

In fact you don't even need to connect up the scope to verify this, if I disconnect the TX and RX pins by pulling out the wires, I still see the issue.

Here is the test setup, the same as used for the previous issue I logged for i2c communications here and SPI over on the Pico-SDK repo. The longer white and green wires are connecting together the TX and RX pins of UART0, other wires were used for testing the other stuff.
20221202_133551

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions