ArduinoRS485 on Due Won't Compile

I was hoping to drag and drop a working program from the mega to the due. It involves both ArduinoRS485.h and ArduinoModbus.h but it won't compile. I tried the example files for ArduinoRS485 and they won't compile either. Any time the library is included I get this error.

c:\Users\Cale\Documents\Arduino\libraries\ArduinoRS485\src\RS485.cpp: In member function 'virtual void RS485Class::begin(long unsigned int, uint16_t, int, int)':
c:\Users\Cale\Documents\Arduino\libraries\ArduinoRS485\src\RS485.cpp:67:34: error: no matching function for call to 'HardwareSerial::begin(long unsigned int&, uint16_t&)'
   _serial->begin(baudrate, config);
                                  ^
c:\Users\Cale\Documents\Arduino\libraries\ArduinoRS485\src\RS485.cpp:67:34: note: candidate is:
In file included from C:\Users\Cale\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/Arduino.h:195:0,
                 from c:\Users\Cale\Documents\Arduino\libraries\ArduinoRS485\src\RS485.h:23,
                 from c:\Users\Cale\Documents\Arduino\libraries\ArduinoRS485\src\RS485.cpp:20:
C:\Users\Cale\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/HardwareSerial.h:29:18: note: virtual void HardwareSerial::begin(long unsigned int)
     virtual void begin(unsigned long);
                  ^
C:\Users\Cale\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/HardwareSerial.h:29:18: note:   candidate expects 1 argument, 2 provided
c:\Users\Cale\Documents\Arduino\libraries\ArduinoRS485\src\RS485.cpp: In member function 'void RS485Class::sendBreak(unsigned int)':
c:\Users\Cale\Documents\Arduino\libraries\ArduinoRS485\src\RS485.cpp:168:36: error: no matching function for call to 'HardwareSerial::begin(long unsigned int&, uint16_t&)'
   _serial->begin(_baudrate, _config);
                                    ^
c:\Users\Cale\Documents\Arduino\libraries\ArduinoRS485\src\RS485.cpp:168:36: note: candidate is:
In file included from C:\Users\Cale\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/Arduino.h:195:0,
                 from c:\Users\Cale\Documents\Arduino\libraries\ArduinoRS485\src\RS485.h:23,
                 from c:\Users\Cale\Documents\Arduino\libraries\ArduinoRS485\src\RS485.cpp:20:
C:\Users\Cale\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/HardwareSerial.h:29:18: note: virtual void HardwareSerial::begin(long unsigned int)
     virtual void begin(unsigned long);
                  ^
C:\Users\Cale\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/HardwareSerial.h:29:18: note:   candidate expects 1 argument, 2 provided
c:\Users\Cale\Documents\Arduino\libraries\ArduinoRS485\src\RS485.cpp: In member function 'void RS485Class::sendBreakMicroseconds(unsigned int)':
c:\Users\Cale\Documents\Arduino\libraries\ArduinoRS485\src\RS485.cpp:178:36: error: no matching function for call to 'HardwareSerial::begin(long unsigned int&, uint16_t&)'
   _serial->begin(_baudrate, _config);
                                    ^
c:\Users\Cale\Documents\Arduino\libraries\ArduinoRS485\src\RS485.cpp:178:36: note: candidate is:
In file included from C:\Users\Cale\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/Arduino.h:195:0,
                 from c:\Users\Cale\Documents\Arduino\libraries\ArduinoRS485\src\RS485.h:23,
                 from c:\Users\Cale\Documents\Arduino\libraries\ArduinoRS485\src\RS485.cpp:20:
C:\Users\Cale\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/HardwareSerial.h:29:18: note: virtual void HardwareSerial::begin(long unsigned int)
     virtual void begin(unsigned long);
                  ^
C:\Users\Cale\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/HardwareSerial.h:29:18: note:   candidate expects 1 argument, 2 provided

exit status 1

Compilation error: exit status 1

The first error is the important one.
The Arduino Mega has 4 Serial ports and the compiler has trouble with using a Serial port in the ArduinoRS485 library.

There is a RS-485 library for the MKR boards with a SAMD21G processor, because there is a RS-485 shield for the MKR boards. Which library do you use and do you know if it is compatible with the Due ?

The libraries I've been using successfully on the mega are ArduinoRS485 and ArduinoModbus. The latter depends on the former. Both official libraries that say they're compatible with all architectures. ArduinoRS485 and it's examples work no problem on uno and mega. Simply won't compile on due.

I'm hoping someone has the answer as this is a bit out of my league.

Indeed, here: https://www.arduino.cc/reference/en/libraries/arduinors485/
they say:

That is a lie :broken_heart:

ArduinoRS485 library: https://github.com/arduino-libraries/ArduinoRS485
ArduinoModbus library: https://github.com/arduino-libraries/ArduinoModbus

I tried this example and it is not compatible.
It seems that Serial library for the Due has other classes and the second parameter of Serial.begin(baudrate, config) does not match.

The default configuration is 8N1 (8 data bits, no parity, 1 stop bit). I think that is used by the RS-485 library. You could remove that second parameter and fallback to the default.

If you see "_serial->begin(baudrate, config);" in the ArduinoRS485 library, then you can replace it with "_serial->begin(baudrate);".
There are three of them, this is the first one: https://github.com/arduino-libraries/ArduinoRS485/blob/master/src/RS485.cpp#L67

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.