|
Forum Index : Microcontroller and PC projects : “Inverted” serial comms suggestion
| Author | Message | ||||
| Mark Regular Member Joined: 26/11/2022 Location: United StatesPosts: 85 |
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: GermanyPosts: 496 |
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 KingdomPosts: 8304 |
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 KingdomPosts: 10632 |
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 KingdomPosts: 2171 |
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 StatesPosts: 85 |
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 KingdomPosts: 10632 |
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 StatesPosts: 85 |
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 KingdomPosts: 10632 |
Sorry wrong file PicoMite.zip |
||||
| Mark Regular Member Joined: 26/11/2022 Location: United StatesPosts: 85 |
With my testing, consisting of one program the ",inv" worksThanks, Mark |
||||
| lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3481 |
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 KingdomPosts: 2171 |
+1 |
||||
| Pluto Guru Joined: 09/06/2017 Location: FinlandPosts: 398 |
+1 |
||||
| homa Guru Joined: 05/11/2021 Location: GermanyPosts: 496 |
+1 |
||||
| homa Guru Joined: 05/11/2021 Location: GermanyPosts: 496 |
Thank you! Matthias |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |