Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:08 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : pico - three serial ports?

Author Message
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 471
Posted: 04:56pm 10 Jan 2023
Copy link to clipboard 
Print this post

Hello,
I have a project with three serial ports. Unfortunately the pico offers only two com ports. Is there a possibility to add a third "virtual" com port? Especially since this would only need 19200baud. I would like to have the comfort of the normal baiscommands like input and print (AS #fnbr).

Alternatively I found BITBANG SERIALTX and BITBANG SERIALRX in the manual, but here the use for a "normal" UART participant is not quite clear to me?

Matthias
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 02:06am 11 Jan 2023
Copy link to clipboard 
Print this post

The RP2040 chip only has two UARTS it it natively, and they are both accessible via various sets of pins.  The only way to add additional serial ports, is with the use of the BITBANG commands.  They pretty much do exactly the same thing, so just use them.

The advantage of the BITBANG serial ports, is that you can use the command to send and receive on any pins you like, which means you could have five or six serial ports if you wanted, by simply changing the pin reference on the BITBANG command.
Smoke makes things work. When the smoke gets out, it stops!
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 08:58am 11 Jan 2023
Copy link to clipboard 
Print this post

  Grogster said  The RP2040 chip only has two UARTS it it natively, and they are both accessible via various sets of pins.  The only way to add additional serial ports, is with the use of the BITBANG commands.  They pretty much do exactly the same thing, so just use them.

The advantage of the BITBANG serial ports, is that you can use the command to send and receive on any pins you like, which means you could have five or six serial ports if you wanted, by simply changing the pin reference on the BITBANG command.


But isn't there the caveat that; if you are expecting a RX, the program has to sit and wait for it (no buffer)?

Or maybe I'm out-of-date  

Craig
Edited 2023-01-11 18:58 by Tinine
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 09:14am 11 Jan 2023
Copy link to clipboard 
Print this post

Could be done using a PIO (as Arduino & upython have) but non-trivial to do.

John
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 09:22am 11 Jan 2023
Copy link to clipboard 
Print this post

  Tinine said  But isn't there the caveat that; if you are expecting a RX, the program has to sit and wait for it (no buffer)?

Or maybe I'm out-of-date  

Craig


No, you're not.  

The RX does have a timeout among other features - see the manual.
So, you CAN start the BITBANG SERIALRX, and time-out after a certain time, then it will return with whatever it happened to receive.  That allows you to look for a serial message within a certain timeframe, but you DO need to expect it to be there - within reason.

Having said that, the native UART's are much better at that, but once you have used the two UART's, then.....C'est La Vie.
Smoke makes things work. When the smoke gets out, it stops!
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 09:24am 11 Jan 2023
Copy link to clipboard 
Print this post

Any possibility to use the console port?

Craig
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 09:28am 11 Jan 2023
Copy link to clipboard 
Print this post

I haven't studied this because I need to be somewhere but

Craig
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7938
Posted: 09:30am 11 Jan 2023
Copy link to clipboard 
Print this post

The RP2040 Data Sheet has an example of using a PIO to create a custom serial port (not a UART as such as it depends on a CPU to buffer any data). It doesn't matter what you do though, MMBasic itself only has commands for COM1 and COM2 and you can't add new commands for COM3.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5091
Posted: 10:34am 11 Jan 2023
Copy link to clipboard 
Print this post

Hi homa,

You can use the RP2040 PIO to perform as a rudimentary UART. Where one state machine is the RX part, another state machine is the TX part. But it may not perform sufficiently in MMBasic since it uses the PIO FIFO's to communicate, and there is no other serial data buffer. The FIFO's are 4 characters deep (with configuration changes maximum 8 characters deep).

So you can not simply send and receive strings. It will require specific MMBasic routines to make that work, sending individual characters SW timed, or short string sections. Or you use this 3'rd UART for short messages only.

In case you use PIO for the 3'rd UART, you get a 4'th UART for free.


Another option is to share 1 UART for 2 serial busses (switch RX and TX lines between 2 peripherals). This will only work when the application can separate the 2 peripherals in a time sharing profile.


Regards,

Volhout
Edited 2023-01-11 20:36 by Volhout
PicomiteVGA PETSCII ROBOTS
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 10:53am 11 Jan 2023
Copy link to clipboard 
Print this post

Maybe just use 2 Picos?

They're cheap :)

John
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 471
Posted: 12:33pm 11 Jan 2023
Copy link to clipboard 
Print this post

i remember that the old tft-maximite only had two software uarts instead of the hardware uarts. the board routing showed that the hardware uarts were otherwise occupied. Therefore, only 19200baud were possible (so I think I remember).
I had the hope that it would be possible to add more "software" Comports to the Pico.
But I will first test the BITBANG commands ... maybe that's enough for me.

@Volhout (and Mixtel90): The idea with the PIOs must still mature, I'm just trying to work through your great course and understand :-)
@JohnS: I've thought about that too, but somehow it doesn't feel good, it needs to go better.
@Tinine: good link, looks interesting!

Has also everything no hurry, is just a nice hobby!
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 01:00pm 11 Jan 2023
Copy link to clipboard 
Print this post

  Quote  I had the hope that it would be possible to add more "software" Comports to the Pico.


It is (bloody difficult though due to lack of timers on the RP2040) if anyone wants to do it - not me - sorry
Edited 2023-01-11 23:21 by matherp
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 05:00pm 11 Jan 2023
Copy link to clipboard 
Print this post

  homa said  
@Tinine: good link, looks interesting!

Has also everything no hurry, is just a nice hobby!


I posted without even reading it. Thought it was some purpose made SPI to UART but I now see it has a micro.

If that's the case, the P1 Propeller would be my choice. One UART to many UARTS. Could be up and running in a heartbeat because the UARTS are soft (with buffers) and one can have as many as the number of pins would allow. Program in FlexBasic to keep it civilised.


Craig
 
IanRogers

Senior Member

Joined: 09/12/2022
Location: United Kingdom
Posts: 151
Posted: 06:13pm 11 Jan 2023
Copy link to clipboard 
Print this post

I did an interrupt driven software serial port

It's possible on the pico as each pin can have an interrupt attached to it.

In the interrupt ( after detecting a start bit ) read a complete byte and store in a user buffer..  It worked for me.
I'd give my left arm to be ambidextrous
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025