Getting SlaveId from official ArduinoModbusServer library w/MAX485 to USB module

Hi!!,
I'm trying to communicate two MAX485 modules with Nano boards (Slave) - PC Master(using ModBusPoll Program), using official ArdunoModbus library
( Official ArduinoModbus Library )

MAX485 modules using 4 pins

  • DI : connects to Arduno TX pin
  • DE : TX Enable Pin(connected to Pin 9 )
  • RE : RX Enable Pin(connected to Pin 10)
  • RO : connects to Arduno RX pin

I connected the MAX485 pins to Arduino, and programmed as below.
It works okay, PC Master(ModbusClient) send request and receive the result well.
But when the two Nano board powered on simultaneously, PC Master modbus request can't receive at all(Timeout error)

The program is as follows

#include <ArduinoRS485.h>
#include <ArduinoModbus.h>

#define THIS_SLAVE_ID 1
#define BPS 9600
#define ENABLE_DE_TX 9
#define ENABLE_RE_RX 10

void setup(){
Serial.begin(9600);
pinMode(ENABLE_DE_TX, OUTPUT);
pinMode(ENABLE_DE_RX, OUTPUT);
if(!ModbusRTUSErver.begin(THIS_SLAVE_ID, BPS)){
Serial.println("Failed to start modbus RTU SErver");
while(1);
}
digitalWrite(ENABLE_DE_TX, LOW);
digitalWrite(ENABLE_DE_RX, HIGH);

ModbusRTUServer.configureInputRegisters(0x00, 10);
}

void loop(){
digitalWrite(ENABLE_DE_TX, HIGH);
digitalWrite(ENABLE_DE_RX, LOW);

ModbusRTUServer.poll();
....
ModbusRTUServer.inputRegisterWrite(1, 1122);
...
}

I found out the cause of this error, the only one device(slave id) can send at a time in the SERIAL RS485 half-duplex communication.
The two Nano slave device Ids are setting TX Enable(Transmitting mode) simultaneously, the Modbus communication jammed into the error(timeout error)

So, each slave device should change DE(TX enable) pin disable(LOW) after it finished the TX.
But there aren't the any API functions like getting Modbus protocol frame request in the official ArduinoModbus library by Arduino.cc.

I think, I have to change the code like that getting the value of slave device id(from Master's modbus request), and setting DE pin to HIGH to transmitt(TX), after TX finishes, setting DE pin to LOW.

It seems that there's no way to getting slave device id in the <ArduinoModbus.h> library..
How could I resolve this??

max485-rs485-transceiver-module.jpg

max485-rs485-transceiver-module.jpg

I solved the problem,
Because the modbus protocol works on the basis of RS485, this problem can be solved through modifying the RE_PIN, DE_PIN numbers..
as follows...
Modify RS485 RE, DE pin setting