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)
#define THIS_SLAVE_ID 1
#define BPS 9600
#define ENABLE_DE_TX 9
#define ENABLE_RE_RX 10
Serial.println("Failed to start modbus RTU SErver");
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??