Cannot pull holding registers from Modbus slave.

Hello, I am trying to pull 4 holding registers from a ABB TotalFlow meter. The meter is set up as a slave to communicate via Modbus RS232. The holding registers are 7001-7004. My pin out is as follows:

Tx2/Pin16 -> RX on meter
Rx2/Pin17 -> TX on meter
Ground -> Ground

I do not know if I need to jump the RTS to the CTS pins on the meter, it doesn't work for me either way. I have never used this library and I have never worked with this protocol before. Can someone give me a hand? Thanks. Here is the code I am trying to use. :confused:

#include <ModbusMaster.h>


// instantiate ModbusMaster object
ModbusMaster node;


void setup()
{
  // use Serial (port 0); initialize Modbus communication baud rate
  Serial.begin(9600);
Serial2.begin(9600);

  // communicate with Modbus slave ID 2 over Serial (port 0)
  node.begin(2, Serial2);
}


void loop()
{
  static uint32_t i;
  uint8_t j, result;
  uint16_t data[4];
  
  i++;
  
  // set word 0 of TX buffer to least-significant word of counter (bits 15..0)
  node.setTransmitBuffer(0, lowWord(i));
  
  // set word 1 of TX buffer to most-significant word of counter (bits 31..16)
  node.setTransmitBuffer(16, highWord(i));
  
 
  
  // slave: read (6) 16-bit registers starting at register 2 to RX buffer
  result = node.readHoldingRegisters(7001, 4);
  
  // do something with data if read is successful
  
  if (result == node.ku8MBSuccess)
  {
    for (j = 0; j < 4; j++)
    {
      data[j] = node.getResponseBuffer(j);
      Serial.println(data[j]);
      Serial.println("ok");
      
    }
  }
}

I've worked with Modbus professionally for a few years, although not yet on the Arduino, and I can offer you a few hints.

First, make sure your meter is configured to communicate with the Arduino. According to docs, the ABB meter you mention has four different protocol versions it can enable to communicate - Modbus ASCII, Modbus RTU, Square D, and another variant. Only one will work with the Arduino library - probably modbus RTU.

I'd recommend checking the meter using a USB RS485 dongle... basically a serial port that can talk to a modbus/RTU network. Make sure the meter communicates successfully using that before trying the Arduino.

Modbus serial settings can be finicky... make sure the meter is expecting the same wire count (2 or 4 wire modbus), parity, speed, and take note of any timeout or delay settings... by default modbus works with 0 delay between commands in most implementations, and some devices are too slow to keep up... sometimes you have to insert a delay between commands or increase the number of milliseconds before a command times out.

Once you have the meter communicating with the dongle, do the same with the Arduino. Check to be sure you're using the same modbus settings (including checking to see that the Arduino is trying to speak RTU instead of Modbus/TCP over ethernet).

Check your address settings if you haven't done so. Some devices expect the Master (only one on each network) to be at a specific address, and won't work unless it's using that number. Lots of devices default to 0 or 1, so you can get conflicts if you don't change addresses before you try to use them.

Once you have both devices' settings worked out, make sure you're using the right register number. There are at least three separate methods of specifying registers/coils that I know of, and manufacturers sometimes use their own notation. Modicon notation is common, but not universal. Also, the number of the register might have a prefix depending on what type you're trying to read. Control Solutions has a good explanation of some of these quirks here:

In short... modbus can be a headache, and I wouldn't recommend it for new implementations. It can be very attractive to use older models of industrial grade sensors, so it's good to be able to work with it.

Thank you Erik. I appreciate the tips. I am trying to communicate via Modbus RTU. I sure wish you had some experience with the arduino modbus libraries. That seems to be my biggest problem. Again, thank you for responding.