Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constant 0xE4 response #119

Closed
l3pond opened this issue Mar 31, 2021 · 1 comment
Closed

Constant 0xE4 response #119

l3pond opened this issue Mar 31, 2021 · 1 comment

Comments

@l3pond
Copy link

l3pond commented Mar 31, 2021

Hello, @emelianov !

First of all, I must thank you for this great library. I already used this on other personal projects with no sweat.

On this particular one, I'm trying to read data from a energy meter Schneider EasyLogic DM6200 using a TTGO T-Beam V1.0 (ESP32 core). As a transceiver, I'm using HW-726, which converts RS485 to TTL 3.3V.

The settings on the energy meter are:

Protocol: Modbus RTU
Data bits: 8
Baud rate: 9600
Parity: Even
Device Address: 1
Stop Bit: 1

On the other hand, the code that I'm using on the T-Beam side is:

#include <ModbusRTU.h>
#include <HardwareSerial.h>
#include <axp20x.h>

HardwareSerial S(1);

#define RXD 13
#define TXD 2

#define SLAVE_ID 1
#define FIRST_REG 3907
#define REG_COUNT 2

ModbusRTU mb;

// Energy management chip
AXP20X_Class axp;

uint32_t res = 0;

bool cb(Modbus::ResultCode event, uint16_t transactionId, void* data) { // Callback to monitor errors
  if (event != Modbus::EX_SUCCESS) {
    Serial.print("Request result: 0x");
    Serial.println(event, HEX);
  }
  return true;
}

void setup() {
  Serial.begin(115200);

  // AXP192 initializing
  Wire.begin(21, 22);
  if (!axp.begin(Wire, AXP192_SLAVE_ADDRESS)) {
    Serial.println("AXP192 Begin PASS");
  } else {
    Serial.println("AXP192 Begin FAIL");
  }
  axp.setPowerOutPut(AXP192_LDO2, AXP202_ON);   // LoRa
  axp.setPowerOutPut(AXP192_LDO3, AXP202_ON);   // GPS
  axp.setPowerOutPut(AXP192_DCDC2, AXP202_OFF);  // unused
  axp.setPowerOutPut(AXP192_EXTEN, AXP202_OFF);
  axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
  axp.setDCDC1Voltage(3300);

  
  S.begin(9600,SERIAL_8E1,RXD,TXD);
  mb.begin(&S);
  mb.master();
  Serial.println("Initializing...");
}

void loop() {
  uint16_t res[REG_COUNT];
  uint32_t current_time = millis();
  static uint32_t prev_time = 0;
  static uint32_t prev_task_time = 0;

  if(current_time - prev_time > 1000){
      prev_time = current_time;
      if (!mb.slave()) {    // Check if no transaction in progress
        mb.readHreg(SLAVE_ID, FIRST_REG, res, REG_COUNT, cb); // Send Read Hreg from Modbus Server
      }
  }
  if (current_time - prev_task_time > 5) { //5ms delay
      prev_task_time = current_time;
      mb.task();
  }
}

The code is an adaptation of #110 solution.

However, I'm getting constant 0xE4 request results, with empty variable.
Any suggestions overcome these constants timeouts? Maybe change the timeout time in MODBUSIP_TIMEOUT 1000 as suggested in #114 ?

Thank you in advance.

@l3pond
Copy link
Author

l3pond commented Mar 31, 2021

Found the problem. It was on the transducer part.

Thank you!

@l3pond l3pond closed this as completed Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant