Sunday, 26 January 2014

Modbus Master-Slave library

Finally most of my work seems to be done. I've written a class which includes either a Master or an Slave. Indeed at this moment I have two prototypes, which are running a Master and an Slave and are linked through an RS-485.

Both boards have LCDs and they are displaying the next information:
  • number of incoming messages;
  • number of outcoming messages;
  • number of wrong messages.

The code is published here. It still needs to be converted to the Arduino library format. The Slave seems to be almost complete, but not the Master, which still lacks functions 1, 2 and 15. I have also seen that this needs some extra work, particularly when having more than a Modbus port on the same board.

I have tested this code using several tools:
Both need a full blog page in order to show how to test my library.

6 comments:

  1. Great Work!
    Looking forward to the completed Master code.
    Cheers

    ReplyDelete
  2. I want to make my Arduino UNO R3 as Modbus TCP Master Please can you give me small example and library

    ReplyDelete
    Replies
    1. This library is only serial, not for TCP.

      Delete
  3. problemas arduino leonardo
    Arduino:1.6.4 (Windows 7), Placa:"Arduino Leonardo"

    Opciones de compilación cambiadas, reconstruyendo todo

    Utilizando biblioteca SoftwareSerial en carpeta: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial

    Utilizando biblioteca Modbus-Master-Slave-for-Arduino-master en carpeta: C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master (legacy)



    C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10604 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Leonardo" -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\leonardo -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial -IC:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master C:\Users\home\AppData\Local\Temp\build882416740262060061.tmp\Materv1.cpp -o C:\Users\home\AppData\Local\Temp\build882416740262060061.tmp\Materv1.cpp.o

    In file included from Materv1.ino:2:0:
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h: In member function 'void Modbus::begin(long int)':
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h:316:14: error: cannot convert 'Serial_*' to 'HardwareSerial*' in assignment
    port = &Serial;
    ^
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h: In member function 'void Modbus::begin(long int, uint8_t)':
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h:399:14: error: cannot convert 'Serial_*' to 'HardwareSerial*' in assignment
    port = &Serial;
    ^
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h: In member function 'void Modbus::sendTxBuffer()':
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h:924:13: error: 'UCSR0A' was not declared in this scope
    UCSR0A=UCSR0A |(1 << TXC0);
    ^
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h:924:34: error: 'TXC0' was not declared in this scope
    UCSR0A=UCSR0A |(1 << TXC0);
    ^
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h:960:22: error: 'UCSR0A' was not declared in this scope
    while (!(UCSR0A & (1 << TXC0)));
    ^
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h:960:37: error: 'TXC0' was not declared in this scope
    while (!(UCSR0A & (1 << TXC0)));
    ^
    Error de compilación

    ReplyDelete
  4. problemas al compilar arduino leonardo !!
    Arduino:1.6.4 (Windows 7), Placa:"Arduino Leonardo"

    Opciones de compilación cambiadas, reconstruyendo todo

    Utilizando biblioteca SoftwareSerial en carpeta: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial

    Utilizando biblioteca Modbus-Master-Slave-for-Arduino-master en carpeta: C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master (legacy)



    C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10604 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Leonardo" -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\leonardo -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial -IC:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master C:\Users\home\AppData\Local\Temp\build882416740262060061.tmp\Materv1.cpp -o C:\Users\home\AppData\Local\Temp\build882416740262060061.tmp\Materv1.cpp.o

    In file included from Materv1.ino:2:0:
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h: In member function 'void Modbus::begin(long int)':
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h:316:14: error: cannot convert 'Serial_*' to 'HardwareSerial*' in assignment
    port = &Serial;
    ^
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h: In member function 'void Modbus::begin(long int, uint8_t)':
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h:399:14: error: cannot convert 'Serial_*' to 'HardwareSerial*' in assignment
    port = &Serial;
    ^
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h: In member function 'void Modbus::sendTxBuffer()':
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h:924:13: error: 'UCSR0A' was not declared in this scope
    UCSR0A=UCSR0A |(1 << TXC0);
    ^
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h:924:34: error: 'TXC0' was not declared in this scope
    UCSR0A=UCSR0A |(1 << TXC0);
    ^
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h:960:22: error: 'UCSR0A' was not declared in this scope
    while (!(UCSR0A & (1 << TXC0)));
    ^
    C:\Users\home\Documents\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h:960:37: error: 'TXC0' was not declared in this scope
    while (!(UCSR0A & (1 << TXC0)));
    ^
    Error de compilación

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete