Multiple UART connections with PI Pico different pins

Pi Pico allows to assign different pins for UART0 and UART1.
I have a project where PICO would be communicating with several serial devices (more than 2), but where it is not so important if a data packet is lost.

Question: If I wire different devices to different pins GP0, GP12, GP16 for transmitting, would something like this work:

Serial1.setTX(0u);
Serial1.begin(38400);
transmit
Serial1.end()

Serial1.setTX(12u);
Serial1.begin(9600);
transmit
Serial1.end()

Not sure if Serial.end waits for the data in buffer to be sent, or one has to time Serial.end (), i.e. calculate how long it takes to send the data and then execute Serial.end?

The same thing can be done for RX? Obviously understaning that some data packets will be lost.

Welcome back.

Please do not post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum.

Topic moved.

If I understand your question correctly, this statement might help. It is for Micropython but should apply for C++ as well.

It is possible to call init() multiple times on the same object in order to reconfigure UART on the fly. That allows using single UART peripheral to serve different devices attached to different GPIO pins. Only one device can be served at a time in that case. Also do not call deinit() as it will prevent calling init() again.

you could use Serial::flush() which Waits for the transmission of outgoing serial data to complete.

Serial1.begin(38400);
transmit
Serial1.flush();
Serial1.end()

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.