RS485 / USB / RS232 on 1 UART

Hi,

My problem is as follows, i have an usb, an RS232 transmitter and an RS485 which need to be connected to a single UART.

I have read this :

Arduino can Tx to multiple Rx at the same time.
For Arduino to successfully Rx, only one device can Tx at a time.

So 3 options are available to me according to my research:

  • Use 1 UART to X UART converter,
  • Use a multiplexer system to select the right RX pin
  • Use an other microcontroller with a program that take receive data and send to my main microcontroller
    Anyone have an idea ?
    Thanks !

There are numerous multiplexers available, DG408 and DG409 being two examples, one dual 4-channel, one is 8-channel
https://www.digikey.com/en/products/detail/vishay-siliconix/DG409DJ-E3/2621725

How many channels do you need, what voltage range do they need to work over?
RS232 for example can be a +12V/-12V signal. You may want to bring that down to 0V/5V level first with MAX232 or similar chip, and then switch those levels thru 5V multiplexers.
https://www.digikey.com/en/products/detail/texas-instruments/MAX232EIN/1511027

I have 3 transmitter:

FT232RL (for usb to uart)
MAX3232 (for RS232 to uart)
MAX485 (for RS485 to uart)
I want to switch the uart part of the transmitters to the arduino uart

I have the arduino's TX pin connected to all the transmitter pins, so everyone receives the message from the arduino.

But for the opposite, the reception to the arduino I would like to have a switch or other to select the right communicator, only I do not know how to say (if an RS232 cable is connected then we select this one)

I see a lot of problems, it is easy to just use a multiplexer and switch the 5V data to the Arduino and receive it with the appropriate interface chip. Sending the same thing to each unit is no problem but what if you get several responses, that can garbage the works. the 74HC153 would be a nice input multiplexer.

Just 3 you could use a 74HC125A, each gate has an enable pin, enable the one whose signal you want to receive.

gilshultz:
I see a lot of problems, it is easy to just use a multiplexer and switch the 5V data to the Arduino and receive it with the appropriate interface chip. Sending the same thing to each unit is no problem but what if you get several responses, that can garbage the works. the 74HC153 would be a nice input multiplexer.

I manage everything from A to Z, the responses, the submissions, ... So I know when I'm expecting a response, and when I'm not expecting it
the problem is that I am wondering how to manage the selection precisely.

Let me explain, if I use a multiplexer, I must know from whom I am receiving the data, in order to activate the connection with it accordingly.

Except with a second micro controller, I don't care about anything, I receive everything, I record and I transmit to the micro controller

I have found the SC16IS752 !

kealmlj:
I manage everything from A to Z, the responses, the submissions, ... So I know when I'm expecting a response, and when I'm not expecting it
the problem is that I am wondering how to manage the selection precisely.

Let me explain, if I use a multiplexer, I must know from whom I am receiving the data, in order to activate the connection with it accordingly.

Except with a second micro controller, I don't care about anything, I receive everything, I record and I transmit to the micro controller

while you have the right idea, the approach you are trying to take is not quite right IMHO,
consider the following:

  1. you send a message to ALL receivers as you have stated
  2. more than one receiver responds AT THE SAME TIME.
    How are you going to multiplex/buffer that??

A better approach IMO would be for example
a. send message to all
b. ping each receiver (define an address for each) in turn after receiving respective reply.
or alternatively
a. send a frame containing message + receiver addr
b. wait for reply then send new frame to next receiver

hope that helps...

hello everyone

I come back to this subject, after using the sc16is752 I don't find it perfect (it works but takes up a lot of space for nothing)

Is it possible to come back to my main subject, having an RS232 and RS485 on the same TX / RX of the arduino?

Could you draw, sketch out, what you're on about?

something like this...?

That's the hardware side at least; still need to multiplex that is your code!

hope that helps...

What will be the results of one chip pulling the TTL line low while the other is pulling the same line high?
Paul

I would say, and many will scoff and reject because it's not fancy, but some (small) relays could be used to switch in/out the 232 and 485 transceivers with. [Contacts one way and you're 232'ing, contacts the other way and you're 485'ing, and you could arrange it so things are open circuit before placing either "in use".]
Probably a little more circuitry than you're up for though.

not a bad idea actually! but I would use something like a CD74HCT125 (quad tri-state buffer ic) instead of relays :grinning:

Hi and thanks to all,

My problem is that I only have one TX / RX available and finally I will only leave the USB on it (because it is used to program the board)

So I only have I2C available and the rs232 and 485 modules to integrate ... I don't know what to do without the sc16is752

what bothers me is the electrical integration, I'm afraid it's not perfect, and i prefer to remove it

Ok... you are feeding us information but I feel we are not quite getting the right picture with regards to your issue...

OK, get that and understandable for the development phase of your project at least!

whether its RS 232 or 484, what baudrate(s) do you require?

depending on that using software serial would generally be a sensible choice. why are you bogged down on using the hardware serial?

If you give us a better understanding of what you are trying to achive, I'm sure someone is bound to propose a suitable solution.

We already have (replies #11, #13,#14) but you don't seem to explain why they are not suitable for you!!!

Hello,

Basically I have on a homemade board (PCB made with KICAD) 8 relays, A CAN / CAN FD module, an RS232 module, an RS485 module, a USB module, and a max17841B (SPI) module all connected to a atmega328pb.

The problem is that the USB takes the TX / RX and the can chip and the max17841b chip takes the SPI 1 and SPI 2

So I have to find out how to add the RS232 and the RS485 ... And for that I only found the SC16IS752 chip ... But I don't really like this chip because I am limited to a FIFO of 64 bytes in reception, except my data frame is based on modbus so in CAN FD it will be much larger! (header + data) ...

I'm completely stuck and I don't know how to get out of this! I search for other MCU like atmega2561 or 1284 but i don't find multiple SPI and TX on it

The only way is to connect all rs232 485 and usb on the same RX TX line on atmega328pb, with an CD74HCT125 and all enable is connected to a signal (+5V from rs232 or RS485 or USB) to activate the good line

do you REALLY need multiple SPI ports???

if you looked into how to use SPI, you will notice the generally MOSI, MISO and SCK are common between the spi peripherals with their repective SS pin connected to a seperate pin on the master unit.

IMO, get yourself a MEGA or even a DUE(this is a 3.3V board!), they got 4 hardware UART ports and probably better suited for your application.

Hope that helps...

Thanks for your reply

I only use one means of communication at a time so it suits me to have everything on the same tx / rx ... But I don't know how to do automatic selection

For the mega I don't see how to use multiple spi or UART... And the DUE i think it's more complicated...

EDIT : I just saw ! This is excellent, so basically that solves a lot of my problems, the SPI is common only the SS pin & INT pin changes, so in theory I can use the SPI line to program (ICSP), CAN, and my other module (I I just have to manage his SS pin well and for INT ?) ?

Then, for the TX / RX, in all cases I am blocked because on the pinouts of the card, the SPI0 is also the TX1 / RX1, so only the TX0 / RX0 are free, but as I said, that don't mind because only one way of com will work at a time, I just want to be able to select the right one ...

your proposed method is much more complicated to than u think compared to using a MEGA!

since you are communicating with your devices 'one at a time', IMO, its just a matter of selecting Serial, Serial1, Serial2..etc as and when required in your code.

your current idea does the switching via external hardware while with the mega this is just all contained within the micro controller!

in essence both will achieve the same thing except one is less complex

your methold = more hardware + more complex code

with MEGA = less hardware + simpler code

Get your fixation of using a single UART out of the way! :slight_smile: