RS485 protocol reading

Trying to communicate with sensor over RS485. When I send command, I receive data nicely. When I connect another master which reads from the same sensor, I try to read data without sending a command. Data are there, most probably as response to commands sent by another master. When buffer is long, about 128 chars, they come corrupted on tail. If I read data very fast, in loop, buffer is corrupted at the begining.

Question: How to read data, requested by another master on RS485.

1 Like

Actually, you don’t! Study that actual electrical specifications for RS-485. There can be ONLY one master. RS-485 is only an electrical standard and only one connection can control which other station can send.

But I get data on second device, without issuing a command.

If data are short, for example
:R51,2,\r\n
they are good all the time.
When data are long, like:
:r50=2,192,1372,5,99999,115518,134619,694157,132,0,6,1,1,100,250813,172013,
I can get:
garbage115518,134619,694157,132,0,6,1,1,100,250813,172013,
Or
:r50=2,192,1372,5,99999,115518,134619,694157,132,0,6,1,1,100,250813,garbage

Sure you are correct that it is electrical standard and electrical pulses go in two wires, where they are read.

If I keep reading in a loop, I get consequently:
:R50, 2\r\n - it is command.
:r50=2,3,... - response

Command comes from another master. I do not send it. Slave responses. Looks like master reads Ok, but I get partially garbage.

I simplified a bit, but idea is that I see a command, which I readOK, then response, which most of the time is correputed, but not all the time.

If I am the only master sending/receiving, data are Ok all the time.

Thanks anyway.

What you are calling pulses is the voltage, + and -, switching from one wire to the other. Bi-polar switching and a quiet period with no data has a steady + on one wire and a steady - on the other. When the master is waiting for a message from a slave, it disconnects the transmitting transistors from the wires so the receiving components can detect the data.

Yes. Agreed.

I do not send data from second master. I only read them. It is not a master. I get the same voltage + and - on the second set of wires. Wires are parallel (I assume this - device - slave, is not exactly known to me. There are two 485 outputs - one standard master (monitor), another - for development). Short set of data - ok. Long - with garbage. Can 120Ohm on receiving end solve situation? I use Arduino 485 shield and not sure if there is 120Ohm resistor.

Once again - no sending data from my device - only reading.
If I disconnect their master, monitor, I get data nicely all the time - no garbage. If I connect monitor and stop sending command - response is sometimes garbaged.
Thanks.

When did it change from a master to a slave? This is why you are getting confusing answers form the forum.

How does the so-called, second master know the line is free and all other units are ready to receive? It doesn’t and there is your problem.

I read next portion of data, asking if serial available, like this:
if(m_serial->available())
m_serial->readStringUntil('\n');

Let me try to explain:

Probably analogy is like this:

Imagine standard master/slave communication for 485. Protocol is like this:

Master sends: :R50,2\r\n
Master receives: : r50=2,192,1372,5,99999,115518,134619,694157,132,0,6,1,1,100,250813,172013,\r\n

All is good.

Now I connect three more wires to A and B and ground to slave in parallel and connect then to second 485 shield.
I start reading data. No command! Only read. I get:
:R50,2\r\n
Next read:
garbage=2,5,99999,115518,134619,694157,132,0,6,1,1,100,250813,172013,\r\n
Next read:
:R50,2\r\n
Next read:
another garbage=,5,99999,115518,134619,694157,132,0,6,1,1,100,250813,172013,\r\n
and so on.

My Arduino behaves like this.

If it is the only master, send command, get response. All is good. Data are clean and nice.
When ‘standard’ master comes in play, I detect this and stop sending command to avoid collisions
and start only reading like:

if(m_serial->available())
String str = m_serial->readStringUntil('\n');

And I get short data good, long data with corruption. Always tail or head are correputed. Middle portion of string is good.

How do you do this?

I power master by myself, so I know when I do this.

I read pin where it powers - on/off.

Could it be that having second set of wires in parallel to original, there is no enough current/voltage for proper data reading?
Like if I have two lamps each of which 30W and I have voltage 10V with max current 3A, one lamp will be bright at 30W (Ohm's law), but when two are connected, each will be 15W consumption, thus darker than the only lamp.

This does not answer the question, why ‘short’ data are good, and why middle portion is good.

And then original master should start showing garbage, but seems it shows fine (not sure if it caches, etc).

To make things more understandable. I use battery monitor:
2024 NEW KH140F Bluetooth Battery Monitor 0-120V 400A Voltage Current Tester Capacity Indicator RV Battery VA Coulomb Meter - AliExpress 1420
Box with numbers is master for slave which is box of black color. It has two 485 exits for R9 connector. One goes to monitor, another for any connection – that’s what I use. I power monitor at will (I do not want it to be active when there is nobody looking). I try to get data from slave. There is defined protocol – command/response.
If monitor is off, I send command, receive response – good. When I power monitor (master), it starts sending commands, the same as I sent before – I just want to read responses and pick whatever I like. I do not send commands – they are good for me. But I do not get responses properly. Only some of them.

Thanks for discussion!

You are are reading the TTL voltage from the adapter, NOT the RS-485 lines, which have no GROUND reference. You are not following the standard. Good luck!

1 Like

You have to be in master mode to do that. With all the confusion post an annotated schematic showing exactly how this bunch of stuff is connected. Be sure to show all connections, power, ground and all power sources.

1 Like

To Paul_KD7HB: Of course I do not read voltage from adapter. I try to make things understandible for you how it works on physical level, making analogy. You can try to do the same as I do - very simple. Parallel wires to existing 485 wires A, B and ground.
And please do not accuse me in not existent things. At least this is not polite.

Sounds like you need a simple RS485 sniffer. Google is your friend here.

There is NO ground in RS-485. Ground is used with a 4th wire to signal a slave that it can send. Is your system?

Since you cannot post a simple schematic and I am not good at guessing, I am bailing out, good luck!

I will. Give me some time please.