Can't communicate via modbus RTU (RS485) - Arduino (Master) to PC (Slave)

Hello Guys.

I am trying to communicate between arduino uno (as Master) and PC (as Slave) via modbus (RS-485). I am using am trying to communicate between arduino uno and PC via modbus (RS-485). I am using Simple Modbus Master
library which I think very easy to understand. First I communicate Arduino to PC through a USB to TTL converter. Here I use Multiway V10 software (Its a virtual modbus simulator) in Slave mode. And I was successful. But when I use MAX485 for RS-485 communication through A & B node , I am unable to communicate. Arduino sent signal to PC… and PC reply back also…But Arduino did not get it. I did not get anything in my LCD Display which I connect for Showing the modbus data. i have used two MAX 485 Transceiver.

So my setup now

Arduino - MAX485- MAX485 - USB to TTL converter - PC (Multiway)

Plz see this link. Multiway

Here is my code:

#include <SimpleModbusMaster.h>

#include <LiquidCrystal.h>

//////////////////// Port information ///////////////////
#define baud 9600
#define timeout 1000
#define polling 100 // the scan rate
#define retry_count 10

// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 6

// The total amount of available memory on the master to store data
#define TOTAL_NO_OF_REGISTERS 25

// This is the easiest way to create new packets
// Add as many as you want. TOTAL_NO_OF_PACKETS
// is automatically updated.
enum
{
PACKET1,
PACKET2,
PACKET3,
PACKET4,
PACKET5,
PACKET6,
PACKET7,
PACKET8,
PACKET9,
PACKET10,
PACKET11,
PACKET12,
PACKET13,
PACKET14,
PACKET15,
PACKET16,
PACKET17,
PACKET18,
PACKET19,
PACKET20,
PACKET21,
PACKET22,
PACKET23,
PACKET24,
PACKET25,
TOTAL_NO_OF_PACKETS // leave this last entry
};

// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];

// Masters register array
unsigned int regs[TOTAL_NO_OF_REGISTERS];

LiquidCrystal lcd(9, 8, 5, 4, 3, 2);

void setup()
{
// Initialize each packet

modbus_construct(&packets[PACKET1], 1, READ_INPUT_REGISTERS, 284, 1, 0);
modbus_construct(&packets[PACKET2], 1, READ_INPUT_REGISTERS, 226, 1, 1);
modbus_construct(&packets[PACKET3], 1, READ_INPUT_REGISTERS, 271, 1, 2);
modbus_construct(&packets[PACKET4], 1, READ_INPUT_REGISTERS, 272, 1, 3);
modbus_construct(&packets[PACKET5], 1, READ_INPUT_REGISTERS, 273, 1, 4);
modbus_construct(&packets[PACKET6], 1, READ_INPUT_REGISTERS, 241, 1, 5);
modbus_construct(&packets[PACKET7], 1, READ_INPUT_REGISTERS, 242, 1, 6);
modbus_construct(&packets[PACKET8], 1, READ_INPUT_REGISTERS, 530, 1, 7);
modbus_construct(&packets[PACKET9], 1, READ_INPUT_REGISTERS, 0, 1, 8 );
modbus_construct(&packets[PACKET10], 1, READ_INPUT_REGISTERS, 247, 1, 9);
modbus_construct(&packets[PACKET11], 1, READ_INPUT_REGISTERS, 0, 1, 10);
modbus_construct(&packets[PACKET12], 1, READ_INPUT_REGISTERS, 205, 1, 11);
modbus_construct(&packets[PACKET13], 1, READ_INPUT_REGISTERS, 203, 1, 12);
modbus_construct(&packets[PACKET14], 1, READ_INPUT_REGISTERS, 207, 1, 13);
modbus_construct(&packets[PACKET15], 1, READ_INPUT_REGISTERS, 209, 1, 14);
modbus_construct(&packets[PACKET16], 1, READ_INPUT_REGISTERS, 214, 1, 15);
modbus_construct(&packets[PACKET17], 1, READ_INPUT_REGISTERS, 216, 1, 16);
modbus_construct(&packets[PACKET18], 1, READ_INPUT_REGISTERS, 0, 1, 17);
modbus_construct(&packets[PACKET19], 1, READ_INPUT_REGISTERS, 0, 1, 18);
modbus_construct(&packets[PACKET20], 1, READ_INPUT_REGISTERS, 0, 1, 19);
modbus_construct(&packets[PACKET21], 1, READ_INPUT_REGISTERS, 0, 1, 20);
modbus_construct(&packets[PACKET22], 1, READ_INPUT_REGISTERS, 0, 1, 21);
modbus_construct(&packets[PACKET23], 1, READ_INPUT_REGISTERS, 0, 1, 22);
modbus_construct(&packets[PACKET24], 1, READ_INPUT_REGISTERS, 0, 1, 23);
modbus_construct(&packets[PACKET25], 1, READ_INPUT_REGISTERS, 0, 1, 24);
 
// Initialize the Modbus Finite State Machine
modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
 
}

void loop()
{
modbus_update();

lcd.begin(16, 2);
lcd.print("Op. Hrs:     Hrs");
lcd.setCursor(0, 1);
lcd.print(regs[0]);
delay(500);

lcd.begin(16, 2);
lcd.print("Actual Power: KW");
lcd.setCursor(0, 1);
lcd.print(regs[1]);
delay(500);

lcd.begin(16, 2);
lcd.print("Winding T. U:  C");
lcd.setCursor(0, 1);
lcd.print(regs[2]);
delay(500);

lcd.begin(16, 2);
lcd.print("Winding T. V:  C");
lcd.setCursor(0, 1);
lcd.print(regs[3]);
delay(500);

lcd.begin(16, 2);
lcd.print("Winding T. W:  C");
lcd.setCursor(0, 1);
lcd.print(regs[4]);
delay(500);

lcd.begin(16, 2);
lcd.print("HT In Temp:    C");
lcd.setCursor(0, 1);
lcd.print(regs[5]);
delay(500);

lcd.begin(16, 2);
lcd.print("HT Out Temp:   C");
lcd.setCursor(0, 1);
lcd.print(regs[6]);
delay(500);

lcd.begin(16, 2);
lcd.print("HT Out Pr.:  bar");
lcd.setCursor(0, 1);
lcd.print(regs[7]);
delay(500);
 
lcd.begin(16, 2);
lcd.print("LT In Temp:    C");
lcd.setCursor(0, 1);
lcd.print(regs[9]);
delay(500);

lcd.begin(16, 2);
lcd.print("LubeOil Temp:  C");
lcd.setCursor(0, 1);
lcd.print(regs[11]);
delay(500);

lcd.begin(16, 2);
lcd.print("LubeOil Pr.: bar");
lcd.setCursor(0, 1);
lcd.print(regs[12]);
delay(500);

lcd.begin(16, 2);
lcd.print("LubeOil Lvl: Per");
lcd.setCursor(0, 1);
lcd.print(regs[13]);
delay(500);

lcd.begin(16, 2);
lcd.print("Crank Pr.:  mbar");
lcd.setCursor(0, 1);
lcd.print(regs[14]);
delay(500);
 
lcd.begin(16, 2);
lcd.print("IntakeAir T.:  C");
lcd.setCursor(0, 1);
lcd.print(regs[15]);
delay(500);

lcd.begin(16, 2);
lcd.print("Receiver T.:   C");
lcd.setCursor(0, 1);
lcd.print(regs[16]);
delay(500);


}

I am connecting MAX485 to arduino as

Max 485 ------ Arduino

Pin 1--------------- RX; Pin 0
Pin 2--------------- TX; Pin 1
Pin 3 & 4 ---------- Tied and connected to D6 (Tx/Rx EnablePin)
Pin 5 --------------- GND
Pin 6 --------------- A
Pin 7 --------------- B
Pin 8 --------------- VCC

Problem is:

  1. master send request to slave,
  2. slave gets request,
  3. slave process request,
  4. slave returns answer to master
  5. master gets answer
  6. master do not process slave answer

Could you guys plz help me to short out the problem. Any assistance will be appreciated…Thanks in advance.

  • DIPU