Electrical – How to ‘wire’ RS485 modules

rs485wiring

(Question is completely revised after comments from AndyAka)

I want to connect about 15 devices (max) via RS485. However, unlike a normal RS485 cable where stubs/devices are tapped from, I want to connect all stubs together directly via DB9 connectors, so there is no (RS485) cable between the DB9 connectors. Of course internally inside each stub the two DB9 connectors needs to be connected. The distance between the DB9 connectors within each enclosure is max 3 inches. I want preferably high speed (about 1 mbps or faster).

How should I do the wiring of the 'RS485' line(s) within each enclosure (between each 2 DB9 connectors inside an enclosure serving as RS485 'main line')?
Should this be twisted paired cable (CAT5?) or can I get away with normal breadboard wire (since the length is not long, max 45", probably smaller).

schematic

simulate this circuit – Schematic created using CircuitLab

This means there will be no visible wires), all wires inside the enclosure, and the terminator are similar as used for DMX (except using DB9 connectors).

Best Answer

Note that if you daisy chain your devices they are not technically "stubs", they are just segments of the same bus.

You don't need any wires in your enclosures. Run two traces in parallel from input to output connector with a stop in between at transceiver pins. Use online impedance calculator like this one for example.

UPDATE

Since you revised the question and mentioned that you want to use wires instead of PCB traces, the answer would be to use short pieces of twisted wire inside, as I already suggested in comments. However the following line in revised question is confusing (and seems not only to me):

main line I mean what normally is a cable that runs along all stubs. I searched for examples, but I can only find RS485 lines where the stubs are 'tapped' from the RS485 (main) line. But mine is only the wires between each two DB9 connectors inside an enclosure

There is a reason you often see connections in the middle shown as "taps" in various RS-485 documents, like in the pictures below. enter image description here

Although electrically this is identical to the schematics in the question, it is done to emphasize actual physical layout. The goal is to minimize stub length, as shown in the middle picture.

If the "main line" between input and output connector is made with PCB traces they should be run straight trough corresponding pins of the transceiver. If the connection is done with twisted pairs they should be joined as a tap as close to transceiver pins as possible. Below are examples for both PCB traces and wire tap.

enter image description here


Now, after all this said, RS-485 is not very well suitable for this application (as in updated question). There is minimum node spacing defined by combined node capacitance per line segment. See #10 in this design guide. By piling up directly connected modules you might quickly exceed this capacitance.

FWIW, I never faced this problem, but on the other hand I haven't seen the designs like this either. Interesting that these questions one, two are still without definite answers.

There are alternatives worth considering. At your distances single-ended UART should work without any problems whatsoever. There was a discussion on similar solution recently. In that case the OP wanted uni-directional bus. If you want bi-directional single-master communication you can design your own protocol to make sure slave nodes will not transmit simultaneously. If you want bi-directional multi-master configuration you can use a simple transistor circuit to convert pull-pull UART output into open-drain, then wire bus with pull-ups, I2C-like.

UPDATE 2

If you want to try SPI then you have to control 15 (per your question) SS lines. This, of course, removes the need in software addressing and collision prevention.

Note, that you don't actually need 15 GPIO pins for this. If you put all your slave modules into same enclosure then a single 74HCT154 demultiplexer and 4 GPIO is all you need.

However if you want the flexibility of modular design then you can route 4 address lines through DB9 connectors and add simple 4-bit address decoder circuits to your modules with DIP switches to set individual addresses. Here is an example of a decoder with two cheap logic chips and 4 positions SPDT switch.

enter image description here