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.
#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");
}
}
}