Master Slave communication through RS485

I ordered a sensor that measures three parameters at specific register addresses. The sensor uses a modbus protocol for communication (RS 485). I use the arduino as master and the sensor as slave. Since I don't have the sensor yet, there is a software (Modsim32) that allows me to simulate a Slave. I would like to make my arduino communicate with the simulation software through the RS485 using the Modbus RTU protocol.
when a run the program based on ModbusMaster library I find in the serial port a 226, according to what i had read that is a error message. But why?

Here is my code

#include <ModbusMaster.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
  We're using a MAX485-compatible RS485 Transceiver.
  Rx/Tx is hooked up to the hardware serial port at 'Serial'.
  The Data Enable and Receiver Enable pins are hooked up as follows:
#define MAX485_DE      3
#define MAX485_RE_NEG  2

LiquidCrystal_I2C lcd(0x27, 20, 4);

// instantiate ModbusMaster object
ModbusMaster node;

void preTransmission()
  digitalWrite(MAX485_RE_NEG, 1);
  digitalWrite(MAX485_DE, 1);

void postTransmission()
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);

void setup()

  // Modbus communication runs at 115200 baud

  // Modbus slave ID 10
  node.begin(10, Serial);


  pinMode(MAX485_RE_NEG, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);
  // Init in receive mode
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);

  // Callbacks allow us to configure the RS485 transceiver correctly

void loop()
  uint8_t result;

  // Read 1 registers starting at 0x3100)
  result = node.readInputRegisters(0x3100, 1);   // I am getting 226 here

  lcd.setCursor(0, 0);

  /*  if (result == node.ku8MBSuccess)
      Serial.print("Vbatt: ");
      Serial.print("Vload: ");
      Serial.print("Pload: ");
      Serial.println((node.getResponseBuffer(0x0D) +
                      node.getResponseBuffer(0x0E) << 16)/100.0f);


Does anyone has an idea about this Problem?

Here you can see a picture of the Slave simulation software

It would help us to help you if you told us which Arduino you are using, which RS485 module you are using, and how you have connected the various pieces together.

I use an arduino Uno. The communication is done through the RS485 and a USB port.

The connections are made as follows:
DI ---> TX Pin
R0 ---> RX Pin
DE ---> Pin 2
RE ---> Pin 3

As for the rs485 and the USB module I have put the link just below and small picture of the connection.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.