0
\$\begingroup\$

I have an sensor with an RS485 interface that has a pinout with labels V, GND, A and B. In my system context, there will just be this one sensor and an ESP32 microcontroller running on 3.3V to communicate with it. Nothing else on the RS485 bus, it's a self-contained system. So I'm designing a little interface circuit to connect them together. I'm looking at using the SP3485EN-L chip to do the job.

The pinout of that chip has signal pins for A, B, RO, /RE, DI, DE. Does that mean that my microcontroller code needs to manage /RE and DE such that /RE is low and DE is low when expecting to receive data, and /RE is high and DE is high before sending data? I guess separate signals are available even though DE and /RE track each other, to allow for a neutral state between active states? I'm thinking I just hook up RO to a UART RX pin on the ESP32 and DI to a UART TX pin on the ESP32. Then throw a 120 ohm resistor across the A <-> B pins.

Something like this:

schematic

simulate this circuit – Schematic created using CircuitLab

I take it as obvious / given that all of these components have their GNDs connected together. Do I have the right idea? Anything I have omitted / need to watch out for?

Additional Information #1

In my application the Sensor is on the end of a 1.25 meter cable and the other end of that cable will be permanently attached (soldered) to the PCB on which the SP3485EN-L is mounted.

Additional Information #2 The datasheet indicates that the sensor adopts the Modbus-RTU communication protocol. And it appears to be a request / response prototcol.

\$\endgroup\$
4
  • \$\begingroup\$ Is this a bi-directional, or uni-directional (receive only) interface? \$\endgroup\$
    – SteveSh
    Dec 3, 2023 at 16:18
  • \$\begingroup\$ @SteveSh the protocol with the sensor appears to be request / response, so I think half-duplex is the right terminology \$\endgroup\$
    – vicatcu
    Dec 3, 2023 at 21:30
  • \$\begingroup\$ Then you need to terminate the line on both ends, as others have suggested. \$\endgroup\$
    – SteveSh
    Dec 4, 2023 at 2:52
  • 1
    \$\begingroup\$ You can connect /RE and DE to the same IO pin if you want to. that's what I usually do. then set the UART in RS485 mode and configure IO14 as RTS \$\endgroup\$ Dec 4, 2023 at 3:01

3 Answers 3

2
\$\begingroup\$

Nothing that is known wrong so far but your block design may or may not omit things on purpose.

First of all, RS-485 is not a 2-wire bus. Sure, there's two wires for differential data, but you must connect the grounds of the RS-485 interfaces together. You don't show that, but if you power the sensor and MCU from the same power supply, they might already be connected together. If you use two separate power supplies, their outputs may share a common reference (e.g. mains earth at inlet connected to supply output negative), or it may do damage (two floating power supplies).

You are correct that the bus must be terminated. But you need to be sure both ends of the bus is terminated. The sensor may or may not have a 120 ohm resistor built-in. Make sure you know that if there is an internal or or if it requires an external termination resiator you need to apply yourself. For a very short bus it might work wigh a single terminator.

You have selected an RS485 chip with 3.3V supply. RS-485 is nominally meant to be driven with 5V chips. Generally, this might not be an issue with short bus and only two devices, but you should carefully analyze or at least test the system if it will properly work with only 3.3V driven to the bus.

You can tie RE and DE together if you don't need to control them separately.

And finally what the have already said. Supply voltage connections to chips and the bypass caps are omitted. Fail-safe bias might be good to be prepared for if you need it, but also that's why the sensor may have provisions for it, if the V is a 5V output for biasing. And yes there is no protection but it may not be a problem for a short bus.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ There are many RS485 drivers and receivers out there spec'd to work with a +3.3 V supply. \$\endgroup\$
    – SteveSh
    Dec 3, 2023 at 16:16
3
\$\begingroup\$

Your circuit is correct, however incomplete.

enter image description here

( Datasheet, Page 4 )

(1) Know-State:

Adding Pullups on RO, DI, /RE and a Pulldown on DE puts the device into a know state during power-up. This avoids glitches on the data lines.

Per Datasheet, Page 7, Receiver: "The receiver is equipped with a fail-safe feature that guarantees the receiver output will be in a HIGH state when the input is left unconnected.". No such statement is to be found in the Driver section however.

(2) Fail-Safe:

As your IC is a rather old one, a external fail-safe implementation is required. Please consult the specific App-Note (Figure 4). However, take special note on Figure 5 and reconsider your IC choice - even if not stricly necessary in your PtP application.

(3) Decoupling:

I'm not sure if you left out the decoupling caps on the transreceiver in your schematic on purpose or for ease of reading. However, adding a 100nF and a 4u7 cap on the VCC pin is cconsidered not only good practice in this cases, but is most likely necessary.

(4) Protection:

As no information about the specific application was provided, i assume it is not used in an industrial environment. However, as the IC is only ESD-protected upto 2kV HBM (Datasheet Page 2), i would strongly suggest to add external TVS-Protection on the Bus-Lines.

(5) Summary:

As you picked a rather old device, you can run into extra effor to design a "complete RS485 solution". By using a more modern and pin-compatible device, you can drastically reduce your design time and enhance your feature set.

I suggest THVD1450 (50Mbps, 256 Nodes, 18kV IEC 61000-4-2, Hot Plug-in Capability, Open/Short/Idle Bus Failsafe) instead. It is available on Digikey and Mouser.

enter image description here

( Datasheet, Page 27, Figure 37 )

enter image description here

( Datasheet, Page 27, Table 7 )

enter image description here

( Datasheet, Page 29, Figure 40 )

You can add the Termination (I would stick to 120Ohm for the standards sake) on the right side of the R1/R2 network.

Note: This implementation is most likely "overkill" for your application - but not really expensive and therefore i would go with it to sleep good at night =)

\$\endgroup\$
3
  • 1
    \$\begingroup\$ External fail safe is not required, unless your application requires that the output of the receiver be in a known state in the event of a cable removal. This might be considered good practice for some applications, but is not required for every use of '485. \$\endgroup\$
    – SteveSh
    Dec 3, 2023 at 16:26
  • 1
    \$\begingroup\$ And if the cable is disconnected, why would you care about the output of the driver? \$\endgroup\$
    – SteveSh
    Dec 3, 2023 at 16:28
  • \$\begingroup\$ @SteveSh "(2) Fail-Safe: [...] choice - even if not stricly necessary in your PtP application.", "Note: This implementation is most likely "overkill" for your application - but not really expensive and therefore i would go with it to sleep good at night =)" \$\endgroup\$ Dec 3, 2023 at 22:43
1
\$\begingroup\$

Your setup is almost correct.

I think the 120 ohm terminator resistor is way too much, it is used when communication line is several metres long. You will get lower consumption with a higher resistor, like 22k or so (even none) if the chips reside on the same PCB.

Rather, you could (should) use two bias resistors: pull A toward +5V and B toward GND with, say, 47k. That will stabilize the line when no devices drives it, in order to cancel the noise.

To put the SP3485 in "neutral" state, you only have to bring DE ("driver enable") low.

To receive data, hold /RE low. This works even when you transmit with DE high: you get back what you are transmitting. Otherwise, you can raise both DE and /RE to transmit without receiving an echo. This "echo" can be used as a basic test: if you don't receive back what you are transmitting, then the line is shorted or the driver is broken. But this diagnostic is not very effective and, again, if the two communicating devices are quite near, it is not necessary.

\$\endgroup\$
2
  • \$\begingroup\$ I think you've entirely missed the point of termination in RS485. If you're not even going to try to match the characteristic impedance of your line then you may as well not bother. 22k as termination will have no useful effect at all. \$\endgroup\$
    – brhans
    Dec 3, 2023 at 14:27
  • 1
    \$\begingroup\$ @brhans the point was when the line is short, which is to say its impedance isn't very important relative to edge rate. Now, OP made no indication of length, so we cannot tell whether this is useful advice or not. I would prefer a lower termination value, even if the lines are short, to ensure an orderly return to default line conditions (the pull-up/down resistors are also a good idea, though they should be smaller to go with this smaller value terminator). \$\endgroup\$ Dec 3, 2023 at 14:34

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.