Device Tree on Modbus

Education is the most powerful weapon you can use to change the world.

—Nelson Mandela

Unless you've been living under a rock since the late '70's, you've probably heard about Modbus, the communications protocol used for a wide variety of industrial systems, from sensors to programmable logic controllers(PLCs). Modbus can be found in most factories and automated assembly lines. Modbus devices can be quite complicated; but what if we used an embedded Device Tree to describe them?
That would enable the automatic discovery and configuration
of Modbus devices and peripherals, wouldn't it?

Modbus

Modbus is a communications protocol developed by Schneider Electric (nee Modicon) in the 1970's. Simple to implement, and robust in operation, it is used by a wide variety of manufacturers. Modbus is often associated with supervisory and data acquisition (SCADA) systems for process control. Manufacturing, power generation, refining, waste treatment plants, you name it, and you are likely to find Modbus devices installed there.

Modbus Addressing

Modbus Address Map Modbus has four (4) independent address spaces, and utilizes different Function Codes, or commands, to access each one of those address spaces. The age of Modbus starts to show when you look at the name of the first address space, namely "Coils". Yup, "Coils", that's what they used to call bits back in the electromechanical dark ages, when a bit was literally a single coil turning on or off! The second address space is known as the "Discrete Inputs" space, and it is typically used to read to read the state of individual switches on a device. The largest address space is called the "Holding Register" address space, and it is typically used for device control registers. Lastly, is the "Input Register" address space, typically used for reading multibit values, like an Analog-to-Digital converter output. Modbus has decently large address spaces, which is one of the reasons it has survived as a standard for over forty(40) years, it was designed to grow as needed.

 

Modbus Addressing with Device Tree

Modbus Device Tree One technique that I have successfully used in the past, is locating a Binary Level OBject (i.e. BLOB) within one of the address spaces of the Modbus Device, typically in the Holding Register Address Space starting at address offset zero (0x0000). I have done this many times in the past using an IPMI FRU : (Intelligent Peripheral Management Interface - Field Replaceable Unit) data structure definition, but it is just as simple to implement using the Device Tree data structure definition. At a minimum, the Device Tree data structure can identify the make and model number of the Modbus device. However, using Device Tree Overlays with more detailed device and register descriptions, it is feasible to embed the entire description of the Modbus device within the Binary Level OBject (i.e. BLOB).

In the past Modbus devices have usually required a very specific driver for each different make and model number of device, with little or no automatic discovery and configuration of Modbus devices being possible. Technicians would usually need to add each Modbus device to their supervisory and data acquisition (SCADA) systems manually.

Summary

Adding the Device Tree data structure to Modbus devices is pretty straightforward and simple, and enables the automatic discovery and configuration of Modbus devices and peripherals.

References, Footnotes, and more...

  1. Modbus Specifications
  2. Device Tree for Dummies - Thomas Petroni
  3. BeagleBlack Device Tree Tutorial - Adafruit
  4. Xilinx Device Tree Tutorial - Xillybus
  5. Altera Device Tree Tutorial - Xillybus
  6. ARM Device Tree Support - Ubuntu
  7. Altera Device Tree Support - Altera
  8. Index of Device Tree Bindings - kernal.org
  9. Device Tree Graphing - kernal.org
  10. libfdt - manipulating FDT Blobs - David Gibson
  11. Linux Bootloaders - informit.com
  12. Device Tree PnP - Eli Billauer
  13. Device Tree Overlay Manager - Pantelis Antoniou
  14. Device Tree Overlay Proposal - Grant Likely
  15. BeagleBlack Univeral I/O - cdsteinkuehler
  16. BeagleBlack Device Tree Overlay Generator - Kilobaser
  17. GPIOs on the Beaglebone Black using the Device Tree Overlays- derek molloy
  18. Supporting 200 Different Expansion Boards - elinux.org
  19. DT, The Disaster so Far - Mark Rutland
  20. Board File to Device Tree Migration - Pantelis Antoniou
  21. Device Tree Overlays - Jonathon Corbet

Featured Projects

Latest News