Hi,
I'm starting a project with serial communication between arduinos on ModBUS protocol. The master library that Zabaat is using (
click) seems to me the best choice of all libraries available out there, but I have problem with it. I can not compile it for Leonardo or for DUE board. I will be using DUE as a master device, but I get following errors:
If I try to compile for DUE:
In file included from "sketch_name.ino":1:
C:\Users\...\Arduino\libraries\ModbusMaster/ModbusMaster.h:83: fatal error: util/crc16.h: No such file or directory
compilation terminated.
If I try to compile for Leonardo:
C:\Users\...\Arduino\libraries\ModbusMaster\ModbusMaster.cpp:36: error: conversion
from 'Serial_' to non-scalar type 'HardwareSerial' requested
C:\Users\...\Arduino\libraries\ModbusMaster\ModbusMaster.cpp: In member function 'void
ModbusMaster::begin(uint16_t)':
C:\Users\...\Arduino\libraries\ModbusMaster\ModbusMaster.cpp:139: error: no match for
'operator=' in 'MBSerial = Serial'
C:\Users\...\Arduino\"install folder of Arduino"\arduino-1.5.2\hardware\arduino\avr\cores\
arduino/HardwareSerial.h:33: note: candidates are: HardwareSerial& HardwareSerial::
operator=(const HardwareSerial&)
If I try to compile it for Uno, Duemilanove, Nano, Mega, Mega 2560... the arduino compile it without problems. I didn't find any compatibility list for this library, but I think that DUE and Leonardo boards aren't supported from this library. Have anyone working modbus master-serial communication for DUE board? Can I somehow change code, so it would work with DUE too? If this library doesn't work with Due or leonardo, can someone give me an advice, what library for master-slave communication between DUE and few Leonardo's should I use? Is there any good guide on how to setup all things? Also later I will try to communicate with industrial frequency inverters trought ModBUS, any suggestions (I'm using Schneider inverters).
PS: I'm using example code from the same zip file I downloaded library.
Example code:
#include <ModbusMaster.h>
// instantiate ModbusMaster object as slave ID 2
// defaults to serial port 0 since no port was specified
ModbusMaster node(2);
void setup()
{
// initialize Modbus communication baud rate
node.begin(19200);
}
void loop()
{
static uint32_t i;
uint8_t j, result;
uint16_t data[6];
i++;
// set word 0 of TX buffer to least-significant word of counter (bits 15..0)
node.setTransmitBuffer(0, lowWord(i));
// set word 1 of TX buffer to most-significant word of counter (bits 31..16)
node.setTransmitBuffer(1, highWord(i));
// slave: write TX buffer to (2) 16-bit registers starting at register 0
result = node.writeMultipleRegisters(0, 2);
// slave: read (6) 16-bit registers starting at register 2 to RX buffer
result = node.readHoldingRegisters(2, 6);
// do something with data if read is successful
if (result == node.ku8MBSuccess)
{
for (j = 0; j < 6; j++)
{
data[j] = node.getResponseBuffer(j);
}
}
}
Thank you very much for all replies!
Jakob