Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:22 21 Nov 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 : “Inverted” serial comms suggestion

Author Message
Mark
Regular Member

Joined: 26/11/2022
Location: United States
Posts: 85
Posted: 05:37am 10 Feb 2023
Copy link to clipboard 
Print this post

Normal Pico serial UART comms have a high  when idle and go low for the data bits. Many external devices expect the opposite, low when idle, high for data bits.  When opening a COM port in Micropython, you can specify “inverted” to handle this, but I don’t see this in PicoMite BASIC. Fortunately, it’s relatively easy to do, it just requires a setting a bit in the each of the two GPIO pins’ control register. As a work-around, I am currently using POKE’s to update the control registers.

Would it be worth adding an “inverted” option to the serial port OPEN command?
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 496
Posted: 08:49am 10 Feb 2023
Copy link to clipboard 
Print this post

  Mark said   As a work-around, I am currently using POKE’s to update the control registers.


Hello Mark,

that is very interesting. Are you so kind and name the POKE command to set the registers in Picomite? Thanks in advance.

Greetings
Matthias

Edited 2023-02-10 18:50 by homa
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 8304
Posted: 09:12am 10 Feb 2023
Copy link to clipboard 
Print this post

MMBasic has it right - conventional UART behavior is to idle high. Anything that uses idle low is actually non-standard. :) The option of being able to invert the signals from a UART isn't so that it can drive devices of the opposite polarity, it's to make things easier when connecting it to a line driver. i.e. a high from the UART turns on a transistor which gives a stronger active low signal onto the (conventional) signal line allowing for longer distances. The correct way to solve this is to put an inverter at the *receiver* end.
Mick

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

Joined: 11/12/2012
Location: United Kingdom
Posts: 10632
Posted: 09:49am 10 Feb 2023
Copy link to clipboard 
Print this post

This is standard MM2 functionality. I didn't include it because the sdk doesn't have a function to support it and I hadn't looked at the register definitions. Given that it works I'll include it in the next beta. As per the MM2 you will just need to include 'inv' in the parameters for the open
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2171
Posted: 10:29am 10 Feb 2023
Copy link to clipboard 
Print this post

  Mark said  Normal Pico serial UART comms have a high  when idle and go low for the data bits. Many external devices expect the opposite, low when idle, high for data bits.  


traditionally, this has always been the way. It was down to the interface hardware to do the "inverting" with +/-12v, -12V being a one bit.

As an aside; This lead to a method to scavenge -12V for the interface in systems that might only have been +5v, say: Because the Tx out from any device is usually left in a "marking" state when idle, one could attach a diode + capacitor to the RX pin (i.e. from the external device) and create a reservoir of -12V to use in the actual data comms back from the Tx device. Done that a few times.
 
Mark
Regular Member

Joined: 26/11/2022
Location: United States
Posts: 85
Posted: 11:07am 10 Feb 2023
Copy link to clipboard 
Print this post

Here is the code I used to invert the serial comms for GP4 (Tx) and GP5 (Rx), standard pins for UART1 on the Pico. For details on control register addresses for other pins and the various bits in them, see section 2.19 (pages 243 and 247) in the RP2040 datasheet from the Raspberry Pi website.


 SetPin gp5,gp4,com2
 Open "com2:38400" As #2
 ctrl% = &H40014000 + &H24 'GP4 ctrl
 Poke word ctrl%, Peek(word ctrl%) Or (1 << 8)
 ctrl% = &H40014000 + &H2c 'GP5 ctrl
 Poke word ctrl%, Peek(word ctrl%) Or (1 << 16)


Mark
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10632
Posted: 12:28pm 10 Feb 2023
Copy link to clipboard 
Print this post

Try this and let me know if OK and I'll post a proper update


PicoMite.zip

As per your example use:

Open "com2:38400, inv" As #2

Edited 2023-02-10 22:29 by matherp
 
Mark
Regular Member

Joined: 26/11/2022
Location: United States
Posts: 85
Posted: 01:54pm 10 Feb 2023
Copy link to clipboard 
Print this post

I loaded the version from the link. option list reports version 5.07.07b16, but when I try do open "com2:38400, inv" I get an error: INV not supported.

Thanks,
Mark
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10632
Posted: 02:15pm 10 Feb 2023
Copy link to clipboard 
Print this post

Sorry wrong file


PicoMite.zip
 
Mark
Regular Member

Joined: 26/11/2022
Location: United States
Posts: 85
Posted: 02:29pm 10 Feb 2023
Copy link to clipboard 
Print this post

With my testing, consisting of one program   the ",inv" works

Thanks,
Mark
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3481
Posted: 02:40pm 10 Feb 2023
Copy link to clipboard 
Print this post

I have to say, this thread illustrates one of the incredible aspects of MMBasic: A feature is requested along with a way to achieve it, and within hours it is incorporated into the firmware.

For what other high level language is this kind of response seen?
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2171
Posted: 03:10pm 10 Feb 2023
Copy link to clipboard 
Print this post

+1
 
Pluto
Guru

Joined: 09/06/2017
Location: Finland
Posts: 398
Posted: 03:11pm 10 Feb 2023
Copy link to clipboard 
Print this post

+1
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 496
Posted: 04:16pm 10 Feb 2023
Copy link to clipboard 
Print this post

+1
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 496
Posted: 04:17pm 10 Feb 2023
Copy link to clipboard 
Print this post

  Mark said  Here is the code I used to invert the serial comms for GP4 (Tx) and GP5 (Rx), standard pins for UART1 on the Pico. For details on control register addresses for other pins and the various bits in them, see section 2.19 (pages 243 and 247) in the RP2040 datasheet from the Raspberry Pi website.


 SetPin gp5,gp4,com2
 Open "com2:38400" As #2
 ctrl% = &H40014000 + &H24 'GP4 ctrl
 Poke word ctrl%, Peek(word ctrl%) Or (1 << 8)
 ctrl% = &H40014000 + &H2c 'GP5 ctrl
 Poke word ctrl%, Peek(word ctrl%) Or (1 << 16)


Mark


Thank you!  
Matthias
 
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