Hello everyone,
I am trying to get data from my battery unit. I follow as :
http://downloads.arduino.cc/libraries/github.com/4-20ma/ModbusMaster-2.0.1.zip
Here is my code:
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 9600 baud, default config 8bit data, parity None, 1 bit stop
Serial.begin(9600, SERIAL_8N1);
// Modbus slave ID 1
node.begin(1, Serial);
// 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.readHoldingRegisters(0x3, 2);
if (result == node.ku8MBSuccess)
{
Serial.print("Phase A voltage: ");
Serial.println(node.getResponseBuffer(0x00)/100.0f);
}
delay(1000);
}
But i always get result of 226 and some unreadable text. Can you pls take a look and give me some advices?
Thank a lot.
modbus diagram rs485.pdf (196 KB)
Modbus Communication protocol.pdf (449 KB)
Juraj
September 20, 2017, 4:38am
2
If some module is connected to serial pins, you can't use Serial for debug printing
wilga
September 20, 2017, 5:42am
3
Hi
readHoldingRegisters = code function0x03
result = node.readHoldingRegisters(0x3, 2) is going to read modbus register 0x03 lenght 2
In your case you are reading Battery Voltage and should return 4 word
Is 226V is correct ??
Juraj:
If some module is connected to serial pins, you can't use Serial for debug printing
Thanks, I will try to use other Serial for debug printing.
wilga:
Hi
readHoldingRegisters = code function0x03
result = node.readHoldingRegisters(0x3, 2) is going to read modbus register 0x03 lenght 2
In your case you are reading Battery Voltage and should return 4 word
Is 226V is correct ??
hi Wilga, it isn't correct, the voltage should be in range of 47-52 (VDC).
Juraj
September 20, 2017, 11:40am
5
I use Modbus TCP. Modbus works with 2 byte registers. if the value is in two registers you calculate it like reg1 * 65535L + reg2
MarkT
September 20, 2017, 11:47am
7
Normally with an RS485 driver you common RE and #DE so you only need to drive a signal line
to switch direction. The only time you want to disable both read and write is for low power mode
if battery operated.
You'll noticed the RE and #DE pins are neighbours on the typical driver chips to make layout
easy for this commoning.
Thanks you all for your times. I had followed as the video DIY RS485 wifi ESP 8266 Adaptor Part 1 - Flashing and software - YouTube and it worked (I used NodeMCU 1.0 and XY-017), then i can get information via virtual COM. Thus i think the circuit i have is fine. But when i change to use Modbus serial, i get an error again.
Any idea, please help!.