1
\$\begingroup\$

I am in the process of trying to design a circuit that will have four RS485 RTU Modbus ports, two acting as clients and two acting as servers, on which I will connect up to fifteen sensors. I am thinking of using a MAX485 transceiver to convert from serial ports to Modbus.

From my understanding, for this to work, the MCU requires four serial ports for this, one for each chip.

Is there a smarter way of doing this kind of communication without needing an MCU with four serial USART ports, which are not that common and are expensive?

Is it possible to just use one port and multiplex it to four different transceivers?

How many serial ports do I need for two client and two server Modbus ports to run simultaneously?

The reason I want so many Modbus ports is that, even though in theory, one Modbus can handle 32 sensors, I think.

In practise, every commercial product we tried struggles past fifteen sensors and we have more than fifteen sensors.

\$\endgroup\$
5
  • \$\begingroup\$ What is "convert from serial ports"? "Serial port" is what users/PC programmers call the RS-232 port on a PC. Is that what you've got? If so then you can't use MAX485 without first taking the signal down to UART levels using for example MAX232. \$\endgroup\$
    – Lundin
    Jun 22, 2022 at 9:03
  • \$\begingroup\$ In the context of MCUs/electronics, we speak of UART, SPI, I2C, CAN etc. All of them common serial buses. \$\endgroup\$
    – Lundin
    Jun 22, 2022 at 9:04
  • \$\begingroup\$ You might want to look into why you're tunning into problems with the number of slaves. What kind of cabling in what structure are you using? The should be a line bus (not a tree) and at the end there should be a termination resisor. \$\endgroup\$
    – kruemi
    Jun 22, 2022 at 9:18
  • \$\begingroup\$ Modbus must support at least 32 devices on bus. Basically a master and 31 sensors. If bus needs to be polarized with fail-safe bias resistors, the allowed count of supported devices drops to 28. Depending on cabling, grounding, termination and other devices it could be much more. The MAX485 is just rated for 32 devices as it presents one unit load. \$\endgroup\$
    – Justme
    Jun 22, 2022 at 11:15
  • \$\begingroup\$ Why does it struggle? What happens when you get to 15 sensors? \$\endgroup\$
    – user253751
    Jun 22, 2022 at 12:56

3 Answers 3

1
\$\begingroup\$

You might want to take a look at the RP2040 by the folks at Raspberry Pi

Tough it only sports 2 UART you can add more by using the Programmable IO (PIO) cores to create more UART as you need them.

There are code examples to implement UART TX and RX in the PIO cores in the official github pico-examples repository.

So assuming that you need 2 PIO cores per serial port (one RX one TX) you can still create 4 UART additionally to the two already present in the RP2040.

\$\endgroup\$
1
\$\begingroup\$

Max number of devices on one Modbus data link

... one Modbus can handle 32 sensors, I think.

Wikipedia:

Modbus is restricted to addressing 247 devices on one data link, ...

Looking for a right MCU

You probably haven't looked good enough, but there are rather cheap MCUs which have quite a few of USARTs. You mentioned expensive, but what is expensive for you?

Example: STM32G0B1Kxxx - STM32 Cortex-M0 with 6 USARTs, in 32-pin LQFP, for 7$ - is that expensive for your project?

Of course, there's another factor nowadays - availability, considering current situation, but that's another topic.

Some other answers

How many serial ports do I need for two master and two slave Modbus ports to run simultaneously?

2 + 2 = 4

Is it possible to just use one port and multiplex it to four different transceivers?

Of course not.

In practice, every commercial product we tried struggles past fifteen sensors and we have more than fifteen sensors.

That's fishy. Perhaps the limiting factor is not the number of sensors on the bus, but its bandwidth?

Ideas

Have you ever worked with FPGAs? You can get rather cheap small FPGA with enough cells to implement even 16x USARTs in a small package, and just use some custom interface to talk with MCU. More work, more flexibility.

\$\endgroup\$
1
  • \$\begingroup\$ 1) Limit is 32 physical devices even if you can have 247 logical addresses 2) Master ports can obviously share a single UART so 3 UARTs is bare minimum 3) Bus topology (length, termination, cabling, failsafe biasing, stubs, branches, reflections, grounding, noise) will affect how many devices in practice can be on bus. A host plus 15 sensors is not unreasonably low number yet. \$\endgroup\$
    – Justme
    Jun 23, 2022 at 4:48
1
\$\begingroup\$

MCUs with 4 UARTs uncommon and expensive? That is not true.

Using a manufacturer search tools I find cheapest and smallest MCU with 4 UARTs cheaper than a dollar in production quantities. In practice your MCU needs to be big enough to do whatever it needs to do to work, so in practice if you just buy any 32-bit ARM MCU with enough memory to do the job, it will likely have easily more than 4 UART/USART interfaces.

If you want 4 buses that work simultaneously, you need 4 UARTs. As two of the buses are masters, you can choose to not communicate and wait a response on more than one master port, so bare minimum is three UARTs.

It just might be cheaper to get a MCU with 4 or more UARTs than to get a smaller MCU add hardware and support code to multiplex two ports to one UART.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.