0
\$\begingroup\$

I'm working on a device that is connected to 2 serial ports (both TX and RX).The first serial port is connected to a CP2104 USB chip, the second serial port is left open with TX,RX,GND,3V pins.

I want to be able to switch between these 2 ports with some kind of analog switch/multiplexer and a mechanical switch but I cannot find a way to implement it. To summarize, the user would select between USB serial or header pin serial. Pseudo-schematic:

This is the circuit i want to implement

The MCU is an ESP8266, which has only one serial port. Whenever I send data via its serial header pins it doesnt receive anything because it is already connected to the CP2104 serial port, and I dont wat to use softwareserial since it is not reliable for WiFi applications.

I did some search and found these analog switches but don't know how to make a circuit with a mechanical switch so that I can change from one serial port to another. Any help or advice is appreciated

=========== EDIT 1 ============

I found a MUX/DEMUX analog switch used for switching between 2 USB(D+,D-) ports. I made a prototype circuit of what I'm trying to achieve with the mechanical slide switch. What do you think?

enter image description here

=========== EDIT 2 ============ Asked another question related to this topic: Is this analog switch good for UART lines?

\$\endgroup\$
14
  • 2
    \$\begingroup\$ Analog switches are indeed sometimes used for this. Or use digital muxes or buffers with enable, and respect the direction... If you're using an actual mechanical switch you may not have too much difficulty finding one with two circuits which would solve the problem entirely, typically you don't need to (and should not!) break the ground. \$\endgroup\$ – Chris Stratton Aug 9 '20 at 1:45
  • 2
    \$\begingroup\$ If / When you create a schematic in CircuitLab please save it directly to the page, as we can copy and edit it to show a solution without having to create it from scratch. Or give us the URL to the schematic so we can copy it. As it is right now we have to create a schematic for you from scratch, which takes time as these are custom symbols you created. \$\endgroup\$ – user105652 Aug 9 '20 at 2:08
  • 2
    \$\begingroup\$ why do you need a mux and a mechanical switch? ... it is unclear how the two relate to each other \$\endgroup\$ – jsotola Aug 9 '20 at 3:33
  • \$\begingroup\$ @jsotola The mechanical slide switch would be used to select between USB and header pins since it has only two positions. I don't want to drive the UART lines via the mechanical switch because of the low resistance which may cause corrupted data. I'd rather drive the UART via a MUX or some sort of analog switch which is driven by a digital signal or vcc \$\endgroup\$ – Amin Mansouri Aug 9 '20 at 15:23
  • \$\begingroup\$ @ChrisStratton Yes I also thought about using only a mechanical switch (DPDT) but I'm concerned about the low resistance connections it may cause on the UART lines (garbage data?) when switching \$\endgroup\$ – Amin Mansouri Aug 9 '20 at 15:26
4
\$\begingroup\$

just use a DPDT switch

enter image description here

[edit] Choosing the right kind of switch is important.

As the signal is a low voltage and low current you want a type of switch where the contacts are self cleaning, like a rotary or slide switch.

\$\endgroup\$
11
  • 1
    \$\begingroup\$ Often there is not enough current in data lines to make switch or relay contacts behave as low resistance connections. A mux is much more dependable. \$\endgroup\$ – user105652 Aug 9 '20 at 6:03
  • 2
    \$\begingroup\$ Contact bounce is not an issue if you switch when there is no transmission ongoing. Even if transmission is ongoing, it will get corrupted even without contact bounce. Back in the days when RS232 serial ports were more common, external boxes existed to select which one of multiple RS232 devices was connected to the computer. They used a mechanical switch, so this is true and tried way to switch. In some other cases, yes, it may not be a good idea to route data via mechanical switches. \$\endgroup\$ – Justme Aug 9 '20 at 6:41
  • 3
    \$\begingroup\$ yeah, choosing the right kind of switch is important. \$\endgroup\$ – Jasen Aug 9 '20 at 6:44
  • \$\begingroup\$ Use the smallest switch and gnd path path possible with logic level control to switch. <1cm loop path for sig + gnd due to inductance \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Aug 9 '20 at 15:53
  • \$\begingroup\$ @Jasen I think I found the perfect chip for this: analog mux/demux \$\endgroup\$ – Amin Mansouri Aug 9 '20 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.