Sunday 12 January 2014

More about my Modbus library

These days I have been working in my Modbus library. My start point has been my contribution to jpmzometa's library. Indeed it was just a timer for the T3.5 delay to detect the end of the message and the RS-485 interface.



I must admit that I've had a good experience with this Modbus-Slave library. Anyway, as its author claims, this library has some known issues:

  1. It implements only functions  3 (read holding registers), 6 (preset single register) and 16 (preset multiple registers).
  2. It lacks a character frame format, it is to say, there is no parity control and only allows 8N1 frames. Indeed the Arduino IDE 1.05 now supports other frames formats.
  3. The Serial buffer is limited to 59 registers.
Apart of these,
  1. It uses Serial.print( byte, BYTE), which fails when compiling with Arduino IDE greater than 1.00. It needs to be replaced by Serial.write( byte ). Indeed it was written for Arduino IDE < 1.00.
  2. The Arduino family has increased with other devices like the Arduino Mega with 4 serial ports or the Leonardo with 2 serial ports (1 USB plus another UART). This library was restricted only to the first Serial port and didn't support any other port.
  3. It is based on another work, thought for PC systems, which didn't care about memory. This library wastes a lot of memory resources, because it declares several arrays and moves them between function calls. This isn't the most efficient way to work with an Arduino.
  4. The Modbus library can also implement a Master, because both share most of the code. There are some small differences regarding to the register handling.
  5. There may be some issues with small microcontrollers like the ATMEGA8 or the ATMEGA168. I have experienced memory overflows that reset the controller.
At this moment, I have succeeded with most of the Modbus Slave implementation. Specifically,
  1. My library allows 4 serial ports depending on the device type and it isn't just restricted to Arduino AVR's. It also allows other popular microcontrollers like the ATMEGA644P or the 1284P. Indeed I'm testing it with a 1284P.
  2. Now I'm implementing functions 1 Read coils, 2 Read digital inputs, 5 Write single coil and 15 Write multiple coils.

No comments:

Post a Comment