1
\$\begingroup\$

I'm working on a project that involves multiplexing the UART interface so that a single device can talk to many. My original plan was to use transistors to direct which child device the parent is talking to.

Any number of transistors(I'm using 2N3904 NPN) are connected at their collector pin to the parent device's TX pin, the transistor's emitter pin obviously going to the RX pin of the child. Then a matching set of transistors in reverse, collector to the child's TX pin & emitter to the parent's RX. A final set are connected at their collector to a regular digital pin on the parent with the emitter leading to the reset pin of the child.

Now another regular digital pin of the parent is used to control which of any group of 3 transistors are called(an RX, TX, and Reset connected transistor all connected to the same child). This configuration resembles SPI but saves on two wires.

Fritzing Diagram

Legend:

Yellow - Parent RX

Green - Parent TX

Orange - Reset Control Pin

Purple - Device 1 selector pin

Cyan - Device 2 selector pin

Prior to setting up the above diagram I tested my code and could reliably send/receive information with one child and no transistors. Then just inserted the transistors between the devices. That went from working perfectly without the transistors to only working some of the time. I've also confirmed that that reset pin works as intended through the transistor.

The problem is with the serial communication. Sometimes the commands the parent sends to the child work, sometimes they don't. and the information returned from the child is quite frequently distorted.

Is it possible to achieve what I am attempting here? Do I just need to use a different type of transistor or is there something inherent to how they work that transistors will always interfere with a communication signal?

\$\endgroup\$
6
  • 5
    \$\begingroup\$ Please add a schematic. \$\endgroup\$
    – Codo
    Commented Nov 6, 2021 at 8:07
  • 4
    \$\begingroup\$ First of all, please join SE/EE so that you can edit your question. Then add a schematic (for simplicity, just two children) to let us see what exactly you did. \$\endgroup\$ Commented Nov 6, 2021 at 9:08
  • 3
    \$\begingroup\$ Additionally, please add some more context. Are the children allowed to keep running if the parent talks to another child? Is there some kind of addressing in the commands from the parent, so that not addressed children can ignore these commands if they receive them? Are you aware that the idle level of asynchronous serial communication if "high"? You might want to use a simple AND gate to collect all RX lines, given that children don't talk when not asked. \$\endgroup\$ Commented Nov 6, 2021 at 9:09
  • \$\begingroup\$ As requested I have updated the OP with the schematic I have been testing. There is a logic level converter for 100% accuracy with my setup. Technically the only pin that needs the voltage translation is the Pi RX pin but I've done it for all three just in case I miss wire it during prototyping. The plan is to replace that with a voltage divider circuit just for that RX pin if I can get a proof of concept working. \$\endgroup\$
    – AustinFoss
    Commented Nov 6, 2021 at 17:33
  • 4
    \$\begingroup\$ Where are the base resistors? Please add a schematic, this frizzy thing looks nice but is next to useless. \$\endgroup\$
    – Gil
    Commented Nov 7, 2021 at 3:00

1 Answer 1

1
\$\begingroup\$

There are a multitude of issues with your design/schematic:

  • Never tie power from each unit together, as each regulator can be off and will cause unnecessary current loops. To power your level-shifter, just choose one Nano 5V supply connected to HV, and the 3V3 from the RaspPi connected to LV. Do not connect the Nano 5V to the RaspPi 5V.
  • GND lines must all be connected together, which you have done.
  • The top right transistor is missing a wire connected to the collector pin.
  • The reset control to each Nano is tied to the RX function, but shouldn't.
  • PNP transistors are a type of Bipolar Junction Transistors (BJT) and are not the same as MOSFETS, but your design uses them in this mode. This is likely the source of your bad communications, when the BJT is turned off then there is nothing to drive the signal high on the collector, so the UART will interpret noise as data.

If you want to use transistors for the switching function, then try using N channel MOSFET instead. Better yet, use a 74HC125 chip which contains four tri-state logic gates, enough for two Nano units.

Here is one solution:

enter image description here

Note that the Nano selection function pins (GPIO23 and GPIO24) must be inverted logic, so program them for '1' to unselect the Nano, and '0' to select.

The 74HC125 is okay with 3.3V or 5V inputs, so there is really only the RXI input to the RaspPi that needs shifting from 5V to 3.3V for its protection. Selecting an alternative 3.3V Arduino to the 5V Nano would completely eliminate the need for the level shifter.

Those pull-up resistors are needed when none of the Nano's are selected, to keep the signal high and noise free.

\$\endgroup\$
6
  • \$\begingroup\$ This is awesome input! I'll look into the specifics of the diagram you've suggested and the MOSFET/Chip suggestion. For now I have two clarifications and one question. Clarification 1, regarding the Nano's reset function being tied to the RX function in the logic level shifter, this is just the way the default fritzing board is labelled, in reality each of those can just be generic digital lines and isn't actually tied to the RX on the Pi. Clarification #2, yes I have an error on the top right transistor, two lines are connected to the emitter. In reality it mirrors the other transistor. \$\endgroup\$
    – AustinFoss
    Commented Nov 7, 2021 at 18:42
  • \$\begingroup\$ Now my question is regarding the power delivery; I plan to actually power the the Pi via a bread board barrel jack, 5V40W, through the GPIO header. Reason being that each Nano can pull 1A@5V(5W), but the pi charger is only a 2.5A@5V(12.5W). It'll never get there, but then in theory I have enough power for 6 Nano's(5W each max) plus the pi zero. Additionally it is my understanding that when you power both Pi and any arduino by the 5V pin it bypasses the regulator and depends on the quality of the power supply to deliver the 5V. This way I have one PSU for the whole setup. \$\endgroup\$
    – AustinFoss
    Commented Nov 7, 2021 at 18:47
  • \$\begingroup\$ I don't know why you claim that 74HC125 is okay with 3.3V inputs while supply voltage is 5V, but datasheets says it isn't. Also the pull-up to 3.3V on a device which outputs 5V logic levels does not make a lot of sense. \$\endgroup\$
    – Justme
    Commented Nov 8, 2021 at 1:24
  • \$\begingroup\$ Justme - it does work. Datasheet says "Wide Supply Voltage Range from 2.0V to 6.0V" and also the Vih = 3.15V (which is barely, but it does work). You are correct, R1 should be pulled to 5V not 3.3V so the level shifter will output to proper range, good catch. \$\endgroup\$ Commented Nov 8, 2021 at 13:42
  • \$\begingroup\$ Just for clarification, mixed voltage operation on a logic gate chip does work as long as 1) the inputs do not exceed the chip VCC and 2) the Vih (and other threshold parameters) are satisfied. Operating the chip at the higher voltages (within the maximum) will affect the threshold parameters, so the datasheet provides a set for common VCC values. \$\endgroup\$ Commented Nov 8, 2021 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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