Hello everyone,
I have been scouring the forums trying to get my setup functioning and so far no luck. I am a bit of a novice so, that's isn't exactly helpful either.
I have an Arduino Mega 2560 and a piece of hardware that communicates using the Modbus standard via RS485. My RS485 converter is a MAX485.
The modbus hardware info:
-maximum polling interval of 10 ms
-32-bit Floating point or signed integer Little Endian [CDAB]
-the manual says all data is stored in 2 16-bit registers with starting addresses listed in the register map. The address below is the starting address for example.
-I am interested in measuring temperature which according to the register map verbatim is Hex address 0x41 which is type 32-bit integer.
I think part of my problem is that the library is expecting a 16-bit chunk of data and I am not exactly sure how to break this up into 2 pieces and then recombine them.
I have the MAX485 to Arduino, respectively, wired as follows:
Vcc - 5v
GND - GND
A - A on modbus device
B - B on modbus device
R0 - RX0
RE/DE - tied together to Digital pin 3
DI - TX0
I am using the ModbusMaster.h library from the Arduino IDE. There is a line near the bottom of my code, 'node.getResponseBuffer(0x00/10.00)' that I am not exactly sure what should go in place of '0x00'. The 10 is scaling I believe from other examples that I can find.
I would appreciate any resources or help that anyone can provide to get this functioning.
Thank you!
My code:
#include <ModbusMaster.h>
#define MAX485_DE 3
// instantiate ModbusMaster object
ModbusMaster node;
void preTransmission()
{
digitalWrite(MAX485_DE, 1);
}
void postTransmission()
{
digitalWrite(MAX485_DE, 0);
}
void setup()
{
pinMode(MAX485_DE, OUTPUT);
digitalWrite(MAX485_DE, 0);
// Modbus communication runs at 115200 baud
Serial.begin(38400);
//Baudrate of modbus device is 38400
Serial1.begin(38400);
// Modbus slave ID is 9
node.begin(9, Serial1);
// Callbacks allow us to configure the RS485 transceiver correctly
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop()
{
uint8_t result;
//Need data from starting address 0x41 with length 2
result = node.readHoldingRegisters(0x41, 2);
//digitalWrite(MAX485_DE, 0);
Serial.println(node.getResponseBuffer(0x00)/10.00);
delay(500);
}