3
\$\begingroup\$

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!

\$\endgroup\$
2
\$\begingroup\$

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)!

\$\endgroup\$
  • \$\begingroup\$ Thanks for the info. Your first link is a good overview. You are right that one can find anything if use google properly, but thats not always easy to do. You gave a good insight to look in the vendors specs/tutorials. Until now I have done only point-to-point simple communication. So multiplepoint communication is kinda obscure for me. \$\endgroup\$ – GAttuso Apr 28 '15 at 17:00
1
\$\begingroup\$

You might want to consider the hardware at an early stage if it's MODBUS-RTU. The MODBUS-RTU protocol has a 3-1/2 character MARK condition to indicate START/END, which an ordinary UART may not support.

With MODBUS ASCII there is no such issue- the colon character and CR/LF are used as delimiters. Of course the downside is that it's much slower.

\$\endgroup\$
  • \$\begingroup\$ For MODBUS-RTU, one solution is to attach the RXD input to a timer input as well. That way you can detect the MARK condition using a timer. \$\endgroup\$ – Kuba Ober Apr 28 '15 at 14:36
  • \$\begingroup\$ @KubaOber Exactly- which is why you have to consider it at an early stage- devote (most likely) an additional pin and some internal timer hardware. \$\endgroup\$ – Spehro Pefhany Apr 28 '15 at 14:43
  • \$\begingroup\$ Thank you. This is a type of pitfall that I haven't been aware of. As far as I understand there is no way to quickly estimate for a certain MCU if that is the case and can be found only deep in specification? \$\endgroup\$ – GAttuso Apr 28 '15 at 16:58
  • 1
    \$\begingroup\$ Yes, you'll have to study the features of the CPU peripherals if you need to support that flavor of Modbus. \$\endgroup\$ – Spehro Pefhany Apr 28 '15 at 17:09

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.