espressif / esp-modbus

ESP-Modbus - the officially suppported library for Modbus protocol (serial RS485 + TCP over WiFi or Ethernet).
Apache License 2.0
85 stars 46 forks source link

ESP32 - esp-modbus - Error 107 in reading modbus register (IDFGH-11299) #40

Closed priya2212 closed 9 months ago

priya2212 commented 9 months ago

Dear @alisitsyn, Thank you for sharing the resources publicly and helping us in development. I am using ENERSOL MRF28 Meter and attached is the modbus mapping for the same. MFR28 Modbus mapping.pdf

I am using it with ESP32, the configurations are as follows -

  1. TX - 17, RX - 16, RTS - 5, 9600, Serial2. I am able to read the data with Modbusmaster library with Arduino framework. To use in ESP-IDF, I am using esp-modbus library. ESP-IDF Version - 4.4, attached is the example configuration - Screenshot from 2023-10-23 16-02-23

changed the Cmakelist as below -

# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/protocols/modbus/mb_example_common)
set(EXCLUDE_COMPONENTS freemodbus)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(modbus_master)

Modbus configuration is as below - Screenshot from 2023-10-23 16-05-27

In the example - I am trying reading the voltage parameter with following piece of code in device_parameter -

enum {
    CID_HOLD_DATA_0 = 0,
    CID_HOLD_DATA_1,
    CID_HOLD_DATA_2
};

// Example Data (Object) Dictionary for Modbus parameters:
// The CID field in the table must be unique.
// Modbus Slave Addr field defines slave address of the device with correspond parameter.
// Modbus Reg Type - Type of Modbus register area (Holding register, Input Register and such).
// Reg Start field defines the start Modbus register number and Reg Size defines the number of registers for the characteristic accordingly.
// The Instance Offset defines offset in the appropriate parameter structure that will be used as instance to save parameter value.
// Data Type, Data Size specify type of the characteristic and its data size.
// Parameter Options field specifies the options that can be used to process parameter value (limits or masks).
// Access Mode - can be used to implement custom options for processing of characteristic (Read/Write restrictions, factory mode values and etc).
const mb_parameter_descriptor_t device_parameters[] = {
    // { CID, Param Name, Units, Modbus Slave Addr, Modbus Reg Type, Reg Start, Reg Size, Instance Offset, Data Type, Data Size, Parameter Options, Access Mode}
    { CID_HOLD_DATA_0, STR("Data_channel_0"), STR("Volts"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 3860 , 2,
                    HOLD_OFFSET(holding_data0), PARAM_TYPE_FLOAT, PARAM_SIZE_U32, OPTS( 0, 300, 1 ), PAR_PERMS_READ_TRIGGER }
};

Unfortunately getting the error -

**E (3508) MB_CONTROLLER_MASTER: mbc_master_get_parameter(83): Master get parameter failure, error=(0x107) (ESP_ERR_TIMEOUT).
E (3508) MASTER_TEST: Characteristic #0 (Data_channel_0) read fail, err = 0x107 (ESP_ERR_TIMEOUT).**

The hardware is working with Arduino framework, I have tried increasing timeout. I suspect my device parameter is not correctly structured. I would appreciate if you could guide me a bit so that I can start my further development. Your help will be highly helpful to me.

Thanks. Priya

priya2212 commented 9 months ago

Closing it as I forgot to notice that the meter is working with Even Parity and adding it in code, it is working.

alisitsyn commented 9 months ago

Hi @priya2212 ,

Thank you for issue and update.

The hardware is working with Arduino framework, I have tried increasing timeout. I suspect my device parameter is not correctly

The config looks ok except baud rate = 9500, stack should work correctly with IEEE754 of your device, please check and confirm the float values are read correctly. Please also note that the communication parameters of your device can be changed through registers (See Modbus registers from 3772).

Let me know if you have any questions.