1

I need to connect a half duplex part (1 wire) and another full duplex part (2 wire) to the MCU's UART (only one available), the half duplex part (1 wire) will have a baud rate of 9600bps. The MCU is an ATMega128. The slaves will be controlled by the Master (MCU) and one of them will be selected at a time. What can be done to connect the two slaves to the MCU's same UART? Can anyone suggest any wiring diagram? (Maybe using a buffer, do not have any other GPIO's available for a MUX.) I do not have any GPIO left to implement any SW UART. I cannot even have a MUX.

EDIT: Another UART is connected to a bluetooth module which is not accessed at the same time. The UART I want to Multiplex has the two mentioned slaves connected to it, so the TX on the slaves need to be multiplexed (keeping in mind that one of the slave is one wired, half duplex)

sami234
  • 19
  • 2
  • Provide some more information : type of MCU that you are using, if you need to access both UARTs at the same time, etc. Sometimes the MCU allows you to put the same internal UART on several ports according its configuration that you can change at run time. You could also implement a SW Uart. You could even use your MCU to multiplex (only the wire that has to be shared): you could copy the input by software to an output that you connect to the UART input (if the input must be multiplexed). Indicate if you are multiplexing RX or TX on the slaves. – le_top Apr 26 '20 at 22:34
  • @MarcusMüller : Yes, you are right. It is full duplex. – sami234 Apr 27 '20 at 13:18
  • @le_top: Both the slaves need to be connected to the same UART. The MCU is an ATMega128. The slaves will be controlled by the Master (MCU)and one of them will be selected at a time. One is half duplex and another one is full duplex. I do not have any other GPIOs available even to implement a SW UART. That is why the question was, how can the two slaves be connected to the same UART and be controlled by the MCU. – sami234 Apr 27 '20 at 13:33
  • @sami234 then please edit your question and fix it... also, all the information that you're giving in the comments here should really be part of your question! – Marcus Müller Apr 27 '20 at 14:25
  • @sami234 Read my comment carefully - you did not provide all information I mentioned - as Marcus says, you should edit your question with the extra information. – le_top Apr 28 '20 at 16:00
  • @le_top edited the question. – sami234 Apr 29 '20 at 09:45
  • @sami234 Do mention the speed of the second UART. Is it also 9600? You're not allowed to add a multiplexer, but can you add transistors/resistors? If you can add transistors, you could convert the TX outputs to open-drain outputs sharing the same signal line. As they are not communicating at the same time that should be ok. – le_top Apr 29 '20 at 15:21
  • @le_top The second UART which is connected to the BLE Module is using baud rate 230400. I can add transistors, resistors, buffers etc. – sami234 Apr 30 '20 at 15:29

2 Answers2

0

That is why the question was, how can the two slaves be connected to the same UART and be controlled by the MCU.

By buying a MCU with at least two UARTs.

You can either use your MCU to do the following

                                ---- Slave 1
                               /
ATMega128 ---> additional MCU <
                               \
                                ---- Slave 2

i.e. the additional MCU gets a command from your Atmega to switch the output, e.g. using an external switch, or, by assigning the UART to other pins.

Or, really, you can ditch the totally overpriced, underpowered ATMega128 and simply use a microcontroller that has enough UARTs on its own. There's very many cheaper microcontrollers. A lot of these are mature ARM Cortex-M0 processors, which, I'm taking a guess here, will even be easier for you to write code for (being way faster, and having much better C and C++ (and generally, any systems language) compilers).

Marcus Müller
  • 88,280
  • 5
  • 131
  • 237
0

As the TX signals do not interfere with each other in the time domain, you can join them together by converting them to open drain outputs connected to the same signal line (TX_OUT).

In the schematic below, TX1 and TX2 represent the outputs of your "slaves", TX_OUT is the output for your microcontroller. The following components are tehre for simulation only: V1 and V2 are permanent sources, SW1 ensures only one of them is active on TX1 or TX2 at the time, R1 and R2 pull the signal low when the switch is open, V3_3 is the power source. M1, M2 and R4 need to be added to your circuit.

You can simulate this circuit.

M1 and M2 should be "Logic N-Channel" Mosfets. The BS170 is not the best choice, it was available in the schematic editing tool and the simulation works with it. BSH112 is likely a better choice.

The TX_OUT signal is inverted with regards to TX1. That should not be an issue if you configure your microcontroller properly.

Further your microcontroller needs to be set to the correct baud rate when it switches. Some microcontroller can autodetect the baud rate, but I haven't experimented with this feature so I do not know how good that works for the needs of switching between a 9600 baud signal and a 230400 baud signal.

schematic

simulate this circuit – Schematic created using CircuitLab

le_top
  • 3,111
  • 11
  • 22