Hi, I am using Modbus to comunicate with a Nano through the serial usb but it only works when the client is in highlight execution (which means it is running slowly). I can't believe the Nano is too slow so I think it is the serial connection. I have tried running at higher baud rates as suggested previously but that doesnt help. Another way round is to use the serial through the Rx and TX pins.
In the further information on CMBullinar modbusRTU slave library it mentions that there is a dePin function for use with RS485 but I cannot understand wtfhat it says. and there is no descritpion of the hardware connections. I have tried implementing the dePin code but the compile produces errors, similarly to what happens if I try to use recent code posted by others using this library. Does anyone know how to used this library with RS485? The description appears not to match the library! heres the library link.
https://github.com/CMB27/ModbusRTUSlave?tab=readme-ov-file#description
Here is my code
#include <ModbusRTUSlave.h> // ModbusRTUSlave by CM Bullinar
ModbusRTUSlave modbus(Serial, dePin);// recomended by description
//ModbusRTUSlave modbus_slave(Serial); working version
const uint8_t slaveID = 1;
const uint32_t baud = 9600;
const uint8_t dePin = 13;
uint16_t holdingRegisters[20] = {0};
int sensor;
void setup() {
// put your setup code here, to run once:
modbus_slave.configureHoldingRegisters(holdingRegisters, 20);
modbus_slave.begin(slaveID, baud, SERIAL_8N1);
}
void loop() {
// put your main code here, to run repeatedly:
sensor = analogRead(A0);
holdingRegisters[2] = 123456;
modbus_slave.poll();
}
ERROR MESSAGES
C:\Users\Pete\Documents\Arduino\modbusMulinar\modbusMulinar.ino:2:31: error: 'dePin' was not declared in this scope
ModbusRTUSlave modbus(Serial, dePin);// recomended by description
^~~~~
C:\Users\Pete\Documents\Arduino\modbusMulinar\modbusMulinar.ino:2:31: note: suggested alternative: 'rewind'
ModbusRTUSlave modbus(Serial, dePin);// recomended by description
^~~~~
rewind
C:\Users\Pete\Documents\Arduino\modbusMulinar\modbusMulinar.ino: In function 'void setup()':
C:\Users\Pete\Documents\Arduino\modbusMulinar\modbusMulinar.ino:14:1: error: 'modbus_slave' was not declared in this scope
modbus_slave.configureHoldingRegisters(holdingRegisters, 20);
^~~~~~~~~~~~
C:\Users\Pete\Documents\Arduino\modbusMulinar\modbusMulinar.ino:14:1: note: suggested alternative: 'ModbusRTUSlave'
modbus_slave.configureHoldingRegisters(holdingRegisters, 20);
^~~~~~~~~~~~
ModbusRTUSlave
C:\Users\Pete\Documents\Arduino\modbusMulinar\modbusMulinar.ino: In function 'void loop()':
C:\Users\Pete\Documents\Arduino\modbusMulinar\modbusMulinar.ino:22:1: error: 'modbus_slave' was not declared in this scope
modbus_slave.poll();
^~~~~~~~~~~~
C:\Users\Pete\Documents\Arduino\modbusMulinar\modbusMulinar.ino:22:1: note: suggested alternative: 'ModbusRTUSlave'
modbus_slave.poll();
^~~~~~~~~~~~
ModbusRTUSlave
exit status 1
Compilation error: 'dePin' was not declared in this scope