3

Designing a modbus master using a STM32F030CCT6 and a SN75HVD10 (3.3V).

This is the schematic Schematic

When i send the following message from the UART: 01 03 00 00 00 06 c5 c8

I see the following scopes (top is A, and the bottom is B). Sent using SN75HVD10

However when sending the same message using a Raspberry PI (5V) and a RS-485 converter cable the following scopes can be seen: Sent using Raspberry PI

As you can see, the channels here are reversed. Whats on A using SN75HVD10 is on B using RPi. So i thought to myself, ok, lets switch the cables. But then the microcontroller stops responding and no traces can be seen on the scope.

What can be done do change the "channels". Also, why is not the signal going down to 0V?

  • So it turned out that when i swapped the channels it started to work, but i had a bug in my MCU code making the MCU crash once the communication started to work. – Lars Stenberg Apr 20 '20 at 06:02

2 Answers2

3

Unfortunately this is common. RS485 and Modbus standards define the A and B the other way than your tranceiver, and many other tranceivers as well.

So, your schematic must flip A and B somewhere. As Modbus B - tranceiver A should have pull-up, and Modbus A - tranceiver B should have pull-down, the resistors are correct respective to the tranceiver, so only swap Modbus A and B.

The tranceiver also has internal pull-down on B pin, which matches that of Modbus A being pulled down.

So this can't be solved by just inverting the UART data.

You must also share same ground reference between your devices. If they share ground via power supplies or other ground pins, that is fine, but if they are isolated from each other, then you need a ground wire between RS485 device.

Justme
  • 127,425
  • 3
  • 97
  • 261
  • The other side is a Carlo Gavazzi EM-24, so it's nothing I have control over. I used https://www.mikroe.com/rs485-33v-click as a design guide for the schematics. Not in the office now, but why don't you think it's enough to invert the uart as proposed by reroute? – Lars Stenberg Apr 17 '20 at 19:47
  • 2
    I did not say you need a reroute. If those go to a connector, you can just flip the wires. Your modbus_a in the schematics is really modbus_b, and modbus_b in the schematics is really modbus_a. But you can't be sure of other devices either. EM-24 says A- is D-, and B+ is D+. FTDI says B is D- and A is D+. Click says A is D+ and B is D-. RS485 says Logic 1 is OFF so A is low, non-inverted, B high, inverted. But tranceiveds say Logic 1 is means A high, non-inverted, B low, inverted. It's a mess. Only flipping the wires, you get pull-ups and pull-downs the right way, according to modbus and UART – Justme Apr 17 '20 at 20:20
  • What a messed up standard :), I'll do more tests on Monday. Thanks for your help, kind stranger – Lars Stenberg Apr 17 '20 at 20:34
  • 1
    Not really - the RS485 standard is solid and has no room for interpretation, and Modbus builds up on top of RS485 standard, it is solid standard too. It's just that the standard mandates something in a way that is not intuitive, unless you get the perspective. Because RS232 had Logic 1 as the OFF/MARK state with -12V output and Logic 0 as the ON/SPACE state with +12V output, the RS485 A output follows that logic inversion. Basically, with the inverted logic, RS485 A is inverted from logic data, and B non-inverted. Many tranceivers say A is non-inverted from logic data, and B is inverted. – Justme Apr 17 '20 at 20:43
  • So it turned out that i had a bug in the MCU code, making it crash once the communication started to work (by flipping the cables). Thanks for your excellent explanation! – Lars Stenberg Apr 20 '20 at 06:03
1

Invert the UART polarity in your microcontroller, (Idle high vs Idle low)

Otherwise as a bodge option, tie the data pin of the tranciever low (I think, may be high), and instead connect your TX to the TX enable pin (DE),

Reroute
  • 4,377
  • 6
  • 14
  • Inverting UART feature could work, but it would leave the pull-ups and pull-downs the incorrect way. – Justme Apr 17 '20 at 17:34