Modbus communication issue MAX485

Dear all,

I am trying to create communication between an arduino Mega and a modbus RTU energy meter by using a MAX485 module.

Firstly, I have checked adresses by usine Modbus doctor and results are following:

As a consequence, slave adress is 0x4B
And register adress is 0x111

When I try this code with on arduino MEGA:


#define DE 3
#define RE 2

ModbusMaster node;


void preTransmission()
{
  digitalWrite(DE,1);
  digitalWrite(RE,1);
}

void postTransmission()
{
  digitalWrite(DE,0);
  digitalWrite(RE,0);
}


void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
  pinMode(DE,OUTPUT);
  pinMode(RE,OUTPUT);
  digitalWrite(DE,0);
  digitalWrite(RE,0);
  node.begin(0x4B,Serial1);
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
}



void loop()
{
  uint8_t Resultat;
  Resultat = node.readHoldingRegisters(0x111, 16);
  if (Resultat == node.ku8MBSuccess)
  {
    Serial.print("connexion");
    Serial.println(Resultat);
  }
  else 
  {
    Serial.print("Echec:");
    Serial.println(Resultat);
  }
  delay(1000);  
}

The Serial response is always 226. I do not suceed to discuss with the energy meter.

Can you help me?

Thank you by advance

What is Modbus library do you use?

Your screenshot shows even parity.
try:
Serial1.begin(9600, SERIAL_8E1);

Just in case, does your device support reading of 16 consecutive registers?

226 is 0xE2 which says

/**
    ModbusMaster response timed out exception.

    The entire response was not received within the timeout period, 
    ModbusMaster::ku8MBResponseTimeout. 
    
    @ingroup constant
    */
    static const uint8_t ku8MBResponseTimedOut           = 0xE2;

there might be an mistake in your wiring.
Show us clear pictures of all your modules. We need to see each and every connection.

If device is respecting modbus protocol, it should respond with exception. But I agree, we don't know if it does....

Thank you, it works with this modification !!

Nice to hear!

.

please mark @kmin 's answer as solution.