Hi I am trying to use the ModbusRTUSlave library by CM Bullinar . I am using a Nano and USB-RS485 converter by EasySYNC which I have used extensively. Is it possible to define pins 10 and 11 as RX and TX so that the usb port remains usable with this library? I borrowed the code for that from the master version of the library. my code loads but polling from a master leads to time out at the read holding register function. (thats a Labview modbus client which I use routinely and works with the modbus running through the usb connection). Has anyone done this successfully or know a library that is easy to use this way?
```cpp
#include <SoftwareSerial.h>
#include <ModbusRTUSlave.h> // ModbusRTUSlave by CM Bullinar
ModbusRTUSlave modbus_slave(Serial);
const uint8_t slaveID = 1;
const uint32_t baud = 9600;
// Define software serial pins for RX and TX
#define RX_PIN 10
#define TX_PIN 11
// Create a software serial port
SoftwareSerial mySerial(RX_PIN, TX_PIN);
uint16_t holdingRegisters[20] = {0};
int sensor;
void setup() {
// put your setup code here, to run once:
modbus_slave.configureHoldingRegisters(holdingRegisters, 21);
modbus_slave.begin(slaveID, baud, SERIAL_8N1);
}
void loop() {
// put your main code here, to run repeatedly:
sensor = analogRead(A0);
holdingRegisters[0] = sensor;
modbus_slave.poll();
}
I did that but still not working, maybe i put it in the wrong place?
#include <SoftwareSerial.h>
#include <ModbusRTUSlave.h> // ModbusRTUSlave by CM Bullinar
const uint8_t slaveID = 1;
const uint32_t baud = 9600;
// Define software serial pins for RX and TX
#define RX_PIN 10
#define TX_PIN 11
// Create a software serial port
SoftwareSerial mySerial(RX_PIN, TX_PIN);
ModbusRTUSlave modbus_slave(mySerial);
uint16_t holdingRegisters[20] = {0};
int sensor;
void setup() {
// put your setup code here, to run once:
modbus_slave.configureHoldingRegisters(holdingRegisters, 21);
modbus_slave.begin(slaveID, baud, SERIAL_8N1);
}
void loop() {
// put your main code here, to run repeatedly:
sensor = analogRead(A0);
holdingRegisters[0] = sensor;
modbus_slave.poll();
}
#include <SoftwareSerial.h>
#include <ModbusRTUSlave.h> // ModbusRTUSlave by CM Bullinar
const uint8_t slaveID = 1;
const uint32_t baud = 4800;
// Define software serial pins for RX and TX
#define RX_PIN 10
#define TX_PIN 11
// Create a software serial port
SoftwareSerial mySerial(RX_PIN, TX_PIN);
ModbusRTUSlave modbus_slave(mySerial);
uint16_t holdingRegisters[2];
int sensor;
void setup() {
// put your setup code here, to run once:
modbus_slave.configureHoldingRegisters(holdingRegisters, 2);
modbus_slave.begin(slaveID, baud, SERIAL_8N1);
}
void loop() {
// put your main code here, to run repeatedly:
holdingRegisters[0] = 333;
holdingRegisters[1] = 777;
modbus_slave.poll();
delay(10);