Modbus RTU Read multiple registers at once

radiator
Posts: 2
Joined: Mon Jan 23, 2023 7:28 pm

Modbus RTU Read multiple registers at once

Postby radiator » Mon Jan 23, 2023 7:43 pm

Hi,
I'm looking for a way how to read multiple input registers at once to reduce bus load. As basis i use the Master example. As long i read only one register it works fine.

Code: Select all

{ CID_UL1N, STR("UL1N"), STR("V"), MB_DEVICE_ADDR1, MB_PARAM_INPUT, 0, 2, INPUT_OFFSET(input_data0), PARAM_TYPE_ASCII, 4, OPTS( 0, 0, 0 ), PAR_PERMS_READ_WRITE_TRIGGER }
As soon i change the parameter descriptor to read 4 words the ESP reboots when the data is received.

Code: Select all

{ CID_UL1N, STR("UL1N"), STR("V"), MB_DEVICE_ADDR1, MB_PARAM_INPUT, 0, 4, INPUT_OFFSET(input_data), PARAM_TYPE_ASCII, 8, OPTS( 0, 0, 0 ), PAR_PERMS_READ_WRITE_TRIGGER }
The request is sent out OK and also the response of the slave is ok but the ESP reboots when data is received. I also defined the input data as an array so there shall be enough space to hold the received data. Also tried with different PARM_TYPE's

Code: Select all

typedef struct
{
    uint16_t input_data[16]; // 0
    
} input_reg_params_t;
I have disabled all the received data handling i do only call:

Code: Select all

err = mbc_master_get_cid_info(cid, &param_descriptor);
Works fine

Code: Select all

mbc_master_get_parameter(cid, (char*)param_descriptor->param_key,(uint8_t*)&value, &type);
crashes as soon as the slave answers.
request: 0x01 0x04 0x00 0x00 0x00 0x04 0xf1 0xc9
answer: 0x01 0x04 0x08 0x43 0x69 0xa0 0xba 0x00 0x00 0x00 0x00 0x58 0x55
Any help is appreciated as it looks like that i did not get something. crashing the device by receiving some data is quite strange to me.

radiator
Posts: 2
Joined: Mon Jan 23, 2023 7:28 pm

Re: Modbus RTU Read multiple registers at once

Postby radiator » Wed Jan 25, 2023 5:48 am

Issue fixed.
Had bug in the definition of the
value
.

pushkarvish4853
Posts: 1
Joined: Tue Oct 10, 2023 5:30 am

Re: Modbus RTU Read multiple registers at once

Postby pushkarvish4853 » Tue Oct 10, 2023 5:32 am

radiator wrote:
Wed Jan 25, 2023 5:48 am
Issue fixed.
Had bug in the definition of the
value
.
  1. Can you please help me how did you changed value definition so it worked actually I am too stuck at the same point, Thank you in advance.

Who is online

Users browsing this forum: Gaston1980 and 126 guests