Hi, I am working with the TUF - 2000M and to get some data using RS485 port.
I am using Arduino Mega and RS485 module, Arduino will be the Master and TUF and other devices will be slaves, I chose Mega because of the possibility of multiple Serial ports, and when I tried to get the data through the oscilloscope in UNO, the value Shown on the RO had the dice received and something else unknown to me beside the some caractheres also unknown, already used some libs but i liked the use yhe lib ModbusMaster of GitHub.
this code:
#include <ModbusMaster.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 21
#define MAX485_RE_NEG 22
// 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()
{
pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);
// Init in receive mode
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
// Modbus communication runs at 115200 baud
Serial.begin(9600);
Serial1.begin(9600,SERIAL_8N1);
// Modbus slave ID 1
node.begin(1, Serial1);
// Callbacks allow us to configure the RS485 transceiver correctly
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop()
{
uint8_t result;
uint16_t data[6];
// result = node.writeSingleCoil(0x0002, state);
//state = !state;
result = node.readHoldingRegisters(0x21, 2);
Serial.println("result");
Serial.println(result,HEX);
if (result == node.ku8MBSuccess)
{
Serial.print("total flow for month: ");
Serial.println(node.getResponseBuffer(0x00));
// int vetor = (node.getResponseBuffer(0x01)/100.0f);;
// int vetor1 = ((node.getResponseBuffer(0x03)));
// Serial.println(vetor);
// Serial.println(vetor1);
}
delay(5000);
}
the manual of TUF : https://images-na.ssl-images-amazon.com/images/I/91CvZHsNYBL.pdf
the program response is in the attached image
My questions about this answers :
I) Do I have to do any operation on the bits I reach?
II) Is the number of registers manual already in HEXA or DEC?
Thanks for you answers, and sorry for my bad english
