Modbus 485 MKR register address help

HI

/* 
Function readVoltage()
Description: read voltage value from the Finder energy meter holding registers
*/ 
float readVoltage() {
  float volt = 0.;
  // Send reading request over RS485 
  if (!ModbusRTUClient.requestFrom(0x01, HOLDING_REGISTERS, 0x000C, 2)) {
    // Error handling
    Serial.print("- Failed to read the voltage! ");
    Serial.println(ModbusRTUClient.lastError()); 
  } else {
    // Response handler 
    uint16_t word1 = ModbusRTUClient.read();  // Read word1 from buffer
    uint16_t word2 = ModbusRTUClient.read();  // Read word2 from buffer
    uint32_t millivolt = word1 << 16 | word2; // Join word1 and word2 to retrieve voltage value in millivolts
    volt = millivolt/1000.0;                  // Convert to volts
  }

  return volt;
}

Can anybody help oh what value "0x000C" should be change to when using this meter, page 9

0x0000 if you want the voltage of L1 to N. You didn't define which voltage you want to read.
But attention: your code expects to read a 32bit Millivolt value but the linked meter returns Decivolt!

float readEnergy() {        
  float kwh = 0.;
  // Send reading request over RS485      
  if (!ModbusRTUClient.requestFrom(0x01, HOLDING_REGISTERS, 0x0040, 2)) {
    // Error handling   
    Serial.print("- Failed to read energy! ");    
    Serial.println(ModbusRTUClient.lastError());         
  } else {        
    // Response handler 
    uint16_t word1 = ModbusRTUClient.read();  // Read word1 from buffer
    //Serial.println(word1);
    uint16_t word2 = ModbusRTUClient.read();  // Read word2 from buffer

    if(word2>0){
     Serial.println("Kwh word2: " + String(word2)); 
    //Serial.println(word2);  
    }
    //Serial.println(word2);
    //int32_t dwh = word1 << 16 | word2;   // Join word1 and word2 to retrieve current value in kwh*10
    kwh = word1/10.0;                 // Convert current to kwh
  }

  return kwh;
}

The energy word2 is also always 0, so with above code it gives me 0.800 kWh - but the lcd display gives me 0.86 kWh

Anybody knows how to do the correct bitwise on word1 and word2, or if word2 shold be disregarted?

thanks pylon, figured that out during today, but it stil gives me headake what is up with the second byte, word2 :slight_smile:

It's quite bad style to edit the original post and fill in completely different code than there was while I was writing post #2. Somebody reading the thread won't realize that you there was a completely different code before.

That's because secion 2.1 states that the order is LSW before MSW. So your code is wrong, it should read

uint32_t decivolt = word2 << 16 | word1;

Because the resolution is 0.1kWh. Using that resolution you cannot display a value of 0.86kWh.

That's answered above.

Thanks again, pylon, restored the original question, sorry.

Do you know why all word2 values are 0, is there a setting in the device to reduce acurracy

All tested registres gives 0 in word2

0x0000
0x000C
0x0012
0x0040

One mesurement : gives 226.300V 0.472A 89.900W 0.800kWh
But 226.3Vx0.472A (L1 - single phase) calculates to 106,81W, not 89.900 - what am i missing

Thanks in advance :slight_smile:

PS I did connect 7-9 (T - A-) as termination on the meter and set switch 3 on in the MKR for termination (test wire is 50 cm twisted pair)

Yes, your values are too low for the high word being used.

Reduce the accuracy? It doesn't seem that you can modify the resolution (you know the difference between resolution and accuracy, don't you?).

What load do you have on that phase? You calculation is only for ohmic loads.

Thanks pylon

Makes sence

Volt * Ampere * Cos (phi )

Thanks for all your help