-1

Here is the modbus register Map i find from CHINT

Hi professers, i am trying to read the data from DDSU666-H ( Smart metter) CHINT using modbus RTU, i only get the raw data but i don't know how to convert it to float , in the code below is about Voltage , real data is 233,4V but in the serial is like this, can some one help me to convert this one to float 233,4V, thank you so much! enter image description here

 Here is my code, i get it from modbusmaster library.
/*

  RS485_HalfDuplex.pde - example using ModbusMaster library to communicate
  with EPSolar LS2024B controller using a half-duplex RS485 transceiver.

  This example is tested against an EPSolar LS2024B solar charge controller.
  See here for protocol specs:
  http://www.solar-elektro.cz/data/dokumenty/1733_modbus_protocol.pdf

  Library:: ModbusMaster
  Author:: Marius Kintel <marius at kintel dot net>

  Copyright:: 2009-2016 Doc Walker

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

#include <ModbusMaster.h>

/*!
  We're using a MAX485-compatible RS485 Transceiver.
  Rx/Tx is hooked up to the hardware serial port at 'Serial'.
  The Data Enable and Receiver Enable pins are hooked up as follows:
*/
#define MAX485_DE      50
#define MAX485_RE_NEG  52

// instantiate ModbusMaster object
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);
  // Init in receive mode
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);

  // Modbus communication runs at 115200 baud
  Serial1.begin(9600);
  Serial.begin(9600);

  // Modbus slave ID 1
  node.begin(12, Serial1);
  // Callbacks allow us to configure the RS485 transceiver correctly
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
}
void loop()
{
  uint8_t i, result;
  uint16_t data[2];
  union
  {
    uint32_t j;
    float f;
  } u;
  // Read 16 registers starting at 0x3100)
  Serial.println("-----------------------");
  result = node.readHoldingRegisters(0x2000, 2);
  if (result == node.ku8MBSuccess)
  {
    for (i = 0; i < 2; i++)
    {
      data[i] = node.getResponseBuffer(i);
    }
    Serial.println(data[0]);
    Serial.println(data[1]);
    u.j = ((unsigned long)data[1] << 16 | data[0]);
    Serial.println(u.f);
  }

5
  • not a question about Arduino ... it is a general programming question at best
    – jsotola
    Jan 26 at 19:16
  • please remove the picture of text and add the actusl text ... text in a picture cannot be copied for analysis
    – jsotola
    Jan 26 at 19:19
  • you mean " hi professer" text ?
    – HẢI HỒ
    Jan 27 at 13:48
  • no, the printout of the readings ... it should be text, not a picture
    – jsotola
    Jan 27 at 16:23
  • Could you share your wiring between rs485 module and ddsu please ?
    – acca rien
    Jun 21 at 20:08

1 Answer 1

2

Seems the data sheet does not specify the endianness. Or maybe it does, but you are not showing it. From the numbers you get, it appears that the floats come in big-endian order, whereas your code assumes little-endian.

Change the assignment of u.j as follows:

u.j = ((unsigned long)data[0] << 16 | data[1]);
3
  • oh,, i actually read voltage register successfully, but with the frequentcy ( 0x200E), it doesn't work , haha
    – HẢI HỒ
    Jan 27 at 13:46
  • Hello expert, why i can't read the frequency and power active register while i can read voltage and current ?
    – HẢI HỒ
    Jan 30 at 14:58
  • @HẢIHỒ: No idea. Check the documentation of your device. Jan 30 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.