![]() |
Forum Index : Microcontroller and PC projects : pico - three serial ports?
Author | Message | ||||
homa![]() Guru ![]() Joined: 05/11/2021 Location: GermanyPosts: 471 |
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 ZealandPosts: 9610 |
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 KingdomPosts: 1646 |
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 KingdomPosts: 4044 |
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 ZealandPosts: 9610 |
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 KingdomPosts: 1646 |
Any possibility to use the console port? Craig |
||||
Tinine Guru ![]() Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
I haven't studied this because I need to be somewhere but Craig |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7938 |
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: NetherlandsPosts: 5091 |
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 KingdomPosts: 4044 |
Maybe just use 2 Picos? They're cheap :) John |
||||
homa![]() Guru ![]() Joined: 05/11/2021 Location: GermanyPosts: 471 |
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 KingdomPosts: 10315 |
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 KingdomPosts: 1646 |
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 KingdomPosts: 151 |
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 |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |