Thank you very much for your help @Steveiboy @blh64. I was able to extract the data from the charge controller
#include <ModbusMaster.h>
#define MAX485_DE 2
#define MAX485_RE_NEG 2
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);
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
Serial1.begin(115200);
Serial.begin(9600);
node.begin(1, Serial1);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
bool state = true;
void loop()
{
uint8_t result;
uint16_t data[6];
result = node.readDiscreteInputs(0x3100, 5);
if (result == node.ku8MBSuccess) {
Serial.print("Array Power(W): ");
Serial.println((node.getResponseBuffer(0x02 |
node.getResponseBuffer(0x03) << 16) / 100.0f);
}
result = node.readInputRegisters(0x3200, 3);
if (result == node.ku8MBSuccess)
{
Serial.print("Battery Status : ");
Serial.print(node.getResponseBuffer(0x00), HEX);
Serial.print("\t");
uint16_t batStatus = node.getResponseBuffer(0x00);
uint8_t temp = (batStatus & 0x00F0) >> 4; // D7-D4 shifted down
if ( temp == 0x00 ) {
Serial.print("Normal (Temp)");
} else if ( temp == 0x01 ) {
Serial.print("Over Temp.(Higher than the warning settings)");
} else if ( temp == 0x02 ) {
Serial.print("Low Temp.(Lower than the warning settings)");
}
Serial.print("\t");
temp = (batStatus & 0x000F); // D3-D0
if ( temp == 0x00 ) {
Serial.println("Normal (Voltage)");
} else if ( temp == 0x01 ) {
Serial.println("Over Voltage.");
} else if ( temp == 0x02 ) {
Serial.println("Under Voltage");
} else if ( temp == 0x03 ) {
Serial.print("Over discharge");
} else if ( temp == 0x04 ) {
Serial.println("Fault (Voltage)");
}
Serial.print("Charging Status : ");
Serial.print(node.getResponseBuffer(0x01), HEX);
Serial.print("\t");
uint16_t CharStatus = node.getResponseBuffer(0x01);
uint8_t Charging = (CharStatus & 0x000C) >> 2; //D3-D2 shifted down
// Serial.print(Charging,BIN);
if ( Charging == 0x00 ) {
Serial.println("No charging");
} else if ( Charging == 0x01 ) {
Serial.println("Float");
} else if ( Charging == 0x02 ) {
Serial.println("Boost");
}
else if ( Charging == 0x03 ) {
Serial.println("Equalization");
}
Serial.print("Array Status : ");
Serial.print(node.getResponseBuffer(0x01), HEX);
Serial.print("\t");
uint16_t ArrStatus = node.getResponseBuffer(0x01);
uint8_t Arr = (ArrStatus & 0xC000) >> 14; //D15-D14 shifted down
if ( Arr == 0x00 ) {
Serial.println("Normal");
} else if ( Arr == 0x01 ) {
Serial.println("No input power connected");
} else if ( Arr == 0x02 ) {
Serial.println("Higher input voltage");
}
else if ( Arr == 0x03 ) {
Serial.println("Input voltage error");
}
Serial.print("Load Status : ");
Serial.print(node.getResponseBuffer(0x02), HEX);
Serial.print("\t");
uint16_t LoadStatus = node.getResponseBuffer(0x02);
uint8_t Load = (LoadStatus & 0x3000) >> 12; //D3-12 shifted down
if ( Load == 0x00 ) {
Serial.println("Light load");
} else if ( Load == 0x01 ) {
Serial.println("Moderate");
} else if ( Load == 0x02 ) {
Serial.println("Rated");
}
else if ( Load == 0x03 ) {
Serial.println("Overload");
}
Serial.print("Device Status : ");
Serial.print(node.getResponseBuffer(0x00), HEX);
Serial.print("\n");
uint16_t DeviceStatus = node.getResponseBuffer(0x00);
if ( DeviceStatus & 0x8000 ) {
Serial.println("Wrong identification for rated voltage");
}
}
result = node.readDiscreteInputs(0x2000, 1);
if (result == node.ku8MBSuccess)
{
uint16_t DeviceStatus = node.getResponseBuffer(0x00);
if ( DeviceStatus & 0x0040 ) {
Serial.println("The temperature inside the controller is higher than the over-temperature protection point");
}
else {
Serial.println("Normal");
}
}
Serial.println("===================================================");
delay(1000);
}