SinelaboreRT Header Logo

SinelaboreRT

As simple as possible, but not any simpler!

User Tools

Site Tools


wiki:news:11aug2015

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
wiki:news:11aug2015 [2018/09/11 22:08] – [Building a ModbusRTU slave with state machines, activity diagrams and minimal runtime environment] pmuellerwiki:news:11aug2015 [2018/09/11 22:10] pmueller
Line 4: Line 4:
 In one of the last design articles I described how to use state-machines in low power embedded software design together with timers and queues to create a wireless sensor node. In one of the last design articles I described how to use state-machines in low power embedded software design together with timers and queues to create a wireless sensor node.
  
-This time I use the same architecture to design and implement a basic ModbusRTU client.  A UML state machine diagram shows the core behavior of the client. An activity diagram shows how the received frame is checked and a reply telegram generated. The client supports not all function codes and has a simple address map. But it will be easy to expand the design with more features.+This time I use the same architecture to design and implement a basic ModbusRTU server.  A UML state machine diagram shows the core behavior of the server. An activity diagram shows how the received frame is checked and a reply telegram generated. The server supports not all function codes and has a simple address map. But it will be easy to expand the design with more features.
  
-The design is based again on a small TI MSP430 board already used in the previous article. The whole client runs in  less than 256 bytes of ram and needs only few kilobytes of code. A RS485 interface was added as physical interface as defined by the ModbusRTU specification.+The design is based again on a small TI MSP430 board already used in the previous article. The whole server runs in  less than 256 bytes of ram and needs only few kilobytes of code. A RS485 interface was added as physical interface as defined by the ModbusRTU specification.
  
 Modbus defines function codes to read/write either bit or word data. Function code four is defined to read analog input words (in our case only simulated values). Function codes one and five are defined to read/write digital outputs (coils). For demo purposes a LED is connected to a port pin of the µC. Modbus defines function codes to read/write either bit or word data. Function code four is defined to read analog input words (in our case only simulated values). Function codes one and five are defined to read/write digital outputs (coils). For demo purposes a LED is connected to a port pin of the µC.
Line 13: Line 13:
  
  
-For those not familiar with Modbus and ModbusRTU. Have a look www.modbus.org and search for the technical specification of the RS485 layer and the ModbusRTU client protocol.+For those not familiar with Modbus and ModbusRTU. Have a look www.modbus.org and search for the technical specification of the RS485 layer and the ModbusRTU server protocol.
  
  
Line 20: Line 20:
 {{:wiki:news:modbus_client:modbus.asta|modbus.asta}} for download. {{:wiki:news:modbus_client:modbus.asta|modbus.asta}} for download.
 The fastest overview provides an interaction diagram (see below). The relevant players are: The fastest overview provides an interaction diagram (see below). The relevant players are:
-  * ''modbus'': The central function realizing the modbus client functionality. The code was fully     generated from a state machine diagram discussed later on. +  * ''modbus'': The central function realizing the modbus server functionality. The code was fully     generated from a state machine diagram discussed later on. 
   * ''modbus_helper'': Helper functions used from the state machine and the rx frame checking code.   * ''modbus_helper'': Helper functions used from the state machine and the rx frame checking code.
   * ''ringbuf'', ''timer'', ''crc16'' ...: Library classes that can be reused from project to project. These classes were already used in the previous examples (e.g. wireless temperature sensor).   * ''ringbuf'', ''timer'', ''crc16'' ...: Library classes that can be reused from project to project. These classes were already used in the previous examples (e.g. wireless temperature sensor).
Line 94: Line 94:
 ====== Wrapping Up ====== ====== Wrapping Up ======
  
-This article has presented the design of a MobusRTU client. It is is based on some library classes which can be reused from project to project. In addition state machine and activity diagrams were used to model the behavior of the device. From these models code was generated. So the design and the code will be always in sync and the modes are not just drawings!+This article has presented the design of a MobusRTU server. It is is based on some library classes which can be reused from project to project. In addition state machine and activity diagrams were used to model the behavior of the device. From these models code was generated. So the design and the code will be always in sync and the modes are not just drawings!
  
 The source code and model file is available upon request. I'm happy to receive suggestions for improvement which I will add and make available for others again.  The source code and model file is available upon request. I'm happy to receive suggestions for improvement which I will add and make available for others again. 
wiki/news/11aug2015.txt · Last modified: 2022/08/17 19:41 by pmueller

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki