Electronic – RS-485 Modbus device to MCU

communicationmodbusrs485

I have a device (an energy meter) that sends data via RS-485 (Modbus protocol). And I want to collect it with MCU. The important thing is that I'm trying to design a board and I want it to be scalable. That means I might have 1 device connected, or maybe 2 or 3 devices connected (with different Slave IDs). I have the following questions:

  • I think that I need MCU with an UART and then I need to add RS-485 driver (like this one) and I'm fine? I mean Modbus is just a protocol, so on the design stage I shouldn't worry about that?
  • Should I consider a MCU with 1 UART or I need more? Is MCU with a signle UART is capable of communicating with multiple devices? I mean one UART will provide only Rx and Tx lines, so it is easy to connect to one device. But how to handle more?
  • Do I need to handle all the Modbus stuff manually? It can be done easily with PC, but how I can do it with my MCU? I will need to define function codes, data arrangement and all this stuff from scratch? Or there are available libraries for some MCUs?

Thanks in advance!

Best Answer

Yes, obviously you need an UART. Your driver looks also okay. One UART is enough. Do not attempt to build your project when you are not familiar with terms like: Bus system, RS485, Physical Layer, UART, RS232, half duplex, Master-Slave topology, bus-arbitration. With that you will understand what a bus system is and how multiple devices on a single line work. A good starting point are application notes from some rs485 vendors and tutorials, for example this one.

Personally, I used the ST3485, which has an application note explaining some basic stuff here but you can find the same information from all other vendors also.

For your Firmware and Protocool decryption there are many librarys out there. First of all you have to know if you want to build a Master or a Slave device. For all of the above: Google is your friend. But for google to find the right stuff, you need to know the terminology (what to search)!