Hi guys, I am new to Arduino. I have a project about getting data from DPM-C530 to Arduino Uno using rs485. I use module 485 to convert rs485 to UART. But the monitor always prints the constant value ( ~ 170 - 180 ) if the register has data.
Here is the result in the monitor ( The correct value are V1 : 222V and V : 77V)
Here is my code:
#include <ModbusMaster.h>
#define MAX485_DE 3
#define MAX485_RE_NEG 2
ModbusMaster node;
void preTransmission()
{
digitalWrite(MAX485_RE_NEG, 1);
digitalWrite(MAX485_DE, 1);
delay(200);
}
void postTransmission()
{
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
delay(200);
}
void setup() {
// put your setup code here, to run once:
pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);
//Init receive mode
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
//Modbus communication runs at 9600 baud
Serial.begin(9600);
//Modbus slave ID 3
node.begin(2, Serial);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop() {
// put your main code here, to run repeatedly:
uint8_t resultMain;
uint16_t data[8];
resultMain = node.readHoldingRegisters(0x0100, 8);
if (resultMain == node.ku8MBSuccess)
{
Serial.println("---------------------");
Serial.print("PM3_V1N :");
Serial.println(((node.getResponseBuffer(0x00)/10000.0f)+ (node.getResponseBuffer(0x01)/ 100.0f)));
Serial.print("PM3_V2N :");
Serial.println(node.getResponseBuffer(0x03)/ 100.0f);
Serial.print("PM3_V3N :");
Serial.println(node.getResponseBuffer(0x05)/ 100.0f);
Serial.print("PM3_V :");
Serial.println((((node.getResponseBuffer(0x06)/10000.0f)+ (node.getResponseBuffer(0x07))/100.0f)));
Serial.print("Freq :");
//Serial.println((((node.getResponseBuffer(0x43))/100.0f)));
delay(5000);
}
}