ESP32 communication over RS485, bias resistors, pull-up/down resistors

Thread Starter

Kibirad

Joined Oct 18, 2021
24
Hi, I'm currently working on a project where I want to use communication over RS485 via MAX485. I've gone through a lot of the sources but some things are still unclear.

First I'll start with bias resistors. To my understanding, they are used as a failsafe when there is no communication over RS485 bus to hold the lines at a specified state and thereby avoid random start bits created by noise etc. Also, the chosen IC (MAX485) should have this failsafe inside but can you do any wrong by using external bias resistors? Then there is the question of value. If my source is right you should be trying to calculate differential resistance or something like that - the equation I've seen was basically a parallel resistor combination equation where the first value was the sum of bias resistors and the second one was the value of terminating resistor. In that case, the viable option would be a combination of two 820 and one 130 ohm resistor or two 10K and one 120R. There should be a correlation between the size of bias resistors and the speed of the bus but I haven't found any specifics so I'm open to suggestions. And the last question is about the position of the bias resistors. Bias resistors are only used at one point, right? What I mean is that the master has a terminating resistor and bias ones but the slaves don't have any bias resistors and not even slave with the terminating resistor.

The next thing are pull-up/pull-down resistors on the R, D, RE a DE lines. First I'll state that I'm planning on connecting RE and DE together because I don't see any benefit of being able to control both separately. Again as I understand the pullup on the DE/RE is there to mainly avoid unpredictable behavior during boot up and maybe some noise resistnce. So if I tie DE and RE pins together and use 10K pull-down resistor the transceiver will be by default enabled in receiver mode and thus avoiding sending some random stuff to the bus. Another resistor used is the 10K pull-up on the R line which should bring the R line to a known state (high) that is also used as a sign of an idle state. And that's it, no more pull-up/down resistors shlould be needed right?

My other question is about TVS diodes. I know that it would be best to have TVS from both data lines to the ground and one between the data lines but after some research, I've decided to use dual bidirectional TVS SM712. I think that it should be okay for home applications. Or am I wrong?

Due to the daisy chain topology of RS485 and myself trying to avoid excessive cable runs I've come up with a solution that seems like reinventing the wheel but I haven't found anything similar. The topology is transformed into a sort of hybrid star topology. Basically, I'll daisy chain a few slaves and on the "last" one I will turn on the dip switch allowing the signal lines to go through the same cable back to the master board. There will be the same lines connected to another RJ45 connector working as a link to the previous lave in a daisy chain. I hope that it is clear what am I trying to do. At this moment I would like to use both UARTs and on each of them have one slave just to avoid problems with collisions. Later I would like to implement Modbus which should take care of addressing slaves and thus collisions. I'm also open to suggestions on which library to use.

I would imagine that the dip switch used to route data lines back to the master would be best placed as close as possible to the RJ45 connector. Also, I'm planning to add an address selection circuit. Probably just 6 pin dip switch some resistors and 74HC4051. I know I could get away with only two pins (something like PCF8574) on ESP instead of four in the case of 74HC4051 but I don't have the best experience with I2C and mainly the libraries. I would like to point out that the exact pins used on ESP and RJ45 connectors aren't final, just connected to be connected. Mainly the circuit was created to help visualize what I'm talking about and found any errors. The last thing that I would like to point out is the +5V on the RJ45 connector. I'm thinking about using the cable as sort of the POE for some slave devices. Therefore it would be probably wise to use two wires for common ground and two for +5V (maybe even +12V).
master.pngslave.png
 

Sensacell

Joined Jun 19, 2012
3,064
What buad rate are you planning to use?

The baud rate determines how critical the network topology is, star connections are bad news at high data rates.
If the node distance is more than 1/4 wavelength at the chosen bit rate, signal reflections become very problematic.
 

Thread Starter

Kibirad

Joined Oct 18, 2021
24
What buad rate are you planning to use?

The baud rate determines how critical the network topology is, star connections are bad news at high data rates.
If the node distance is more than 1/4 wavelength at the chosen bit rate, signal reflections become very problematic.
I'm not really sure what baud rate I will use. But there is a misunderstanding. I'm not planning on using star topology but just sort of star - it looks like a star but it really isn't. Take a look at the attached diagram. It should work as a normal daisy chain but on the third slave will be dip switch turned on allowing the AB data line to return back to the master board where it will be transferred to another RJ45 connector. So basically switching the switch will create a loop back to the master board where it will be routed to the second RJ45 connector. Also now that I'm looking at it. I've drawn the return path incorrectly. It should go back to second to "last" slave, then back to the previous.. just to be exact. But it should be sufficient to give you an idea of what I'm planning to do.
diagram.png
 
Last edited:

MrChips

Joined Oct 2, 2009
27,122
Besides the baud rate the total length of your network is important.

I have not yet seen RS-485 in a serial daisy-chained.

RE-485 is intended to be used as one length of twisted-pair cable with proper termination at both ends of the cable.
Slave devices are connected as parallel stubs "daisy-chained" off the cable (not star network).
 

Thread Starter

Kibirad

Joined Oct 18, 2021
24
So the idea is that returning the cable back is a way to avoid network stubs?
To make it all one loop?
The idea is to mainly reduce excessive cable runs. Imagine the main board in the middle of the building. You have some slaves on the north of the building so you run cables to it. Then you have some slaves on the south of the building. So to preserve daisy chain topology you need to run a cable from the north part of the building all the way to the south. that would be the normal configuration.
What am I suggesting is that you use unused cables in the UTP and loop back the data lines to the main board where are they transferred to another connector that can be used to run for example the south "branch" of the slaves. Just by switching one switch you just saved cable run from the "last" slave on the north to main board.
 

MrChips

Joined Oct 2, 2009
27,122
You only need to run one cable from one end of the network to the other end.
What is the distance between the north and south side of the building?
Maximum cable length for RS-485 is 1000m.
 

Thread Starter

Kibirad

Joined Oct 18, 2021
24
Besides the baud rate the total length of your network is important.

I have not yet seen RS-485 in a serial daisy-chained.

RE-485 is intended to be used as one length of twisted-pair cable with proper termination at both ends of the cable.
Slave devices are connected as parallel stubs "daisy-chained" off the cable (not star network).
Yes, I know all these things about topology and decreasing baud rate with distance. I also know that the recommended topology is daisy chain and the backbone with the stubs is workable but not ideal. On the other hand, I've seen some calculations and even with high baud rate the length of the stubs wasn't really that critical. If I remember correctly even the 10cm stub wasn't a problem but that isn't even the direction I'm planning to go with.

I only mentioned the pseudo hybrid star topology because it may look like it at first glance - multiple cables running from the master, some of the branches then daisy chained.

Take look at the schematics in my first post. I'm running data lines from MAX485 IC to pins 8 and 7 on J12 RJ45 connector. With UTP you connect J12 on master board with J6 on slave device. There you can see the junction connecting J6 with J5. Then you insert cable connecting J5 with J6 of another slave etc. After you you get to the "last" slave you turn on both switches of the SW3 routing the data lines back through all previous slaves back to the main board into the J12 connector. But now the data lines are on pins 2 and 1. Which are routed directly to pins 8 and 7 of J13. So the first slave connected to the J13 is basically daisy chained to all the previous slaves connected via J12.
 

Thread Starter

Kibirad

Joined Oct 18, 2021
24
You only need to run one cable from one end of the network to the other end.
What is the distance between the north and south side of the building?
Maximum cable length for RS-485 is 1000m.
Yes, but I still need to run a cable from the middle of the building to the north slaves and from them to the south slaves. But I mentioned that just as a example. The length of wire used to connect all the slaves with master shouldn't be more than 100m. For that reason, the cable length limitation of RS485 isn't an issue.
In the end, the topology isn't really the problem that I'm facing. The thing I most wanted to get feedback on was the values, use of bias and pull-up/down resistors and if I understood their function.
 

MrChips

Joined Oct 2, 2009
27,122
You can still run one cable end to end. The cable is properly terminated only at the ends, not at the stubs.
The main board is placed anywhere along the cable. No termination is used on the main board, only pull-up and pull-down bias resistors.
 

MrChips

Joined Oct 2, 2009
27,122
Ok. I misunderstood what you meant by "daisy chain" in your diagram.
To me it would appear in your diagram that each slave was receiving the signal and then actively relaying on to the next slave.

A proper RS-485 "daisy chain" network is basically one twisted pair that runs linearly throughout the entire network.
You may choose to use one pair of screw terminals, two pairs of screw terminals, or a pair of RJ45 jacks on each slave.
Essentially, the A and B data lines are all wired from unit to unit.

No termination or bias resistors are used on slave units.
Only the two extreme ends of the cable are to be terminated with the proper termination resistor. This is to prevent reflections on the cable. When the ends are properly terminated there must be no other termination along the length of the cable.

Pull-up and pull-down resistors are used to bias the A and B lines to the proper DC voltages at idle state. These can be located anywhere on the cable. It is customary to place them on the master unit.

https://www.ti.com/lit/wp/slla545/slla545.pdf

https://www.maximintegrated.com/en/design/technical-documents/app-notes/3/3884.html
 

Thread Starter

Kibirad

Joined Oct 18, 2021
24
Ok. I misunderstood what you meant by "daisy chain" in your diagram.
To me it would appear in your diagram that each slave was receiving the signal and then actively relaying on to the next slave.

A proper RS-485 "daisy chain" network is basically one twisted pair that runs linearly throughout the entire network.
You may choose to use one pair of screw terminals, two pairs of screw terminals, or a pair of RJ45 jacks on each slave.
Essentially, the A and B data lines are all wired from unit to unit.

No termination or bias resistors are used on slave units.
Only the two extreme ends of the cable are to be terminated with the proper termination resistor. This is to prevent reflections on the cable. When the ends are properly terminated there must be no other termination along the length of the cable.

Pull-up and pull-down resistors are used to bias the A and B lines to the proper DC voltages at idle state. These can be located anywhere on the cable. It is customary to place them on the master unit.

https://www.ti.com/lit/wp/slla545/slla545.pdf

https://www.maximintegrated.com/en/design/technical-documents/app-notes/3/3884.html
Sorry for the late reply, but I haven't gotten to it until now. Thank you for the links. I've spent some time researching but haven't found these. That said, I've used the equation from the first link, and the bias resistor value result was around 420-465ohm. That seems to me pretty low after seeing some other designs. I've found out somewhere that the value of these resistors equals the noise resistance of the circuit. So the value could be a little higher for the sake of lowering the heating of the circuit? I also haven't found out if using an external failsafe (created by bias resistors) can do any harm to the circuit containing IC with a built-in failsafe.

Next are pull-up/down resistors on the "input" side of the IC. After I've done some reading, I'm pretty confident that you really only need two resistors. First of them at the R (RO) line and the second on the line controlling DE and RE, which are tied together. But what I'm really not sure about is the value of the resistors and how it is calculated, and what exactly does pull-up on the R line.
 
Top