How to properly define multiple Modbus register areas?
Posted: Tue Jan 10, 2023 5:20 pm
Hi,
I'm having issues with defining multiple separate Modbus holding register areas using the serial slave example. I get the following error:
"MB_CONTROLLER_SLAVE: mbc_slave_set_descriptor(217): mb incorrect descriptor or already defined."
Here is how I define the areas in the main app:
What am I doing wrong? It specifically complains on the reg293 reg_area, so it's okay with the first 3. Each register in the program is just a single float register in my definition.
Thank you in advance!
I'm having issues with defining multiple separate Modbus holding register areas using the serial slave example. I get the following error:
"MB_CONTROLLER_SLAVE: mbc_slave_set_descriptor(217): mb incorrect descriptor or already defined."
Here is how I define the areas in the main app:
- #define MB_REG_HOLDING_START_AREA0 (40263)
- #define MB_REG_HOLDING_START_AREA1 (40267)
- #define MB_REG_HOLDING_START_AREA2 (40291)
- #define MB_REG_HOLDING_START_AREA3 (40293)
- #define MB_REG_HOLDING_START_AREA4 (40389)
- #define MB_REG_HOLDING_START_AREA5 (40907)
- #define MB_REG_HOLDING_START_AREA6 (40931)
- #define MB_REG_HOLDING_START_AREA7 (40933)
- #define MB_REG_HOLDING_START_AREA8 (41027)
- static void setup_reg_data(void)
- {
- // Define initial state of parameters
- holding_reg_params.reg263= 0;
- holding_reg_params.reg267 = 0;
- holding_reg_params.reg291 = 0;
- holding_reg_params.reg293 = 0;
- holding_reg_params.reg389 = 0;
- holding_reg_params.reg907 = 0;
- holding_reg_params.reg931 = 0;
- holding_reg_params.reg1027 = 0;
- }
- reg_area.type = MB_PARAM_HOLDING; // Set type of register area
- reg_area.start_offset = MB_REG_HOLDING_START_AREA0;
- reg_area.address = (void*)&holding_reg_params.reg263;
- reg_area.size = sizeof(float) << 1;
- ESP_ERROR_CHECK(mbc_slave_set_descriptor(reg_area));
- reg_area.type = MB_PARAM_HOLDING; // Set type of register area
- reg_area.start_offset = MB_REG_HOLDING_START_AREA1;
- reg_area.address = (void*)&holding_reg_params.reg267;
- reg_area.size = sizeof(float) << 1;
- ESP_ERROR_CHECK(mbc_slave_set_descriptor(reg_area));
- reg_area.type = MB_PARAM_HOLDING;
- reg_area.start_offset = MB_REG_HOLDING_START_AREA2;
- reg_area.address = (void*)&holding_reg_params.reg291;
- reg_area.size = sizeof(float) << 1;
- ESP_ERROR_CHECK(mbc_slave_set_descriptor(reg_area));
- reg_area.type = MB_PARAM_HOLDING;
- reg_area.start_offset = MB_REG_HOLDI NG_START_AREA3;
- reg_area.address = (void*)&holding_reg_params.reg293;
- reg_area.size = sizeof(float) << 1;
- ESP_ERROR_CHECK(mbc_slave_set_descriptor(reg_area));
- reg_area.type = MB_PARAM_HOLDING;
- reg_area.start_offset = MB_REG_HOLDING_START_AREA4;
- reg_area.address = (void*)&holding_reg_params.reg389;
- reg_area.size = sizeof(float) << 1;
- ESP_ERROR_CHECK(mbc_slave_set_descriptor(reg_area));
- reg_area.type = MB_PARAM_HOLDING;
- reg_area.start_offset = MB_REG_HOLDING_START_AREA5;
- reg_area.address = (void*)&holding_reg_params.reg907;
- reg_area.size = sizeof(float) << 1;
- ESP_ERROR_CHECK(mbc_slave_set_descriptor(reg_area));
- reg_area.type = MB_PARAM_HOLDING;
- reg_area.start_offset = MB_REG_HOLDING_START_AREA6;
- reg_area.address = (void*)&holding_reg_params.reg931;
- reg_area.size = sizeof(float) << 1;
- ESP_ERROR_CHECK(mbc_slave_set_descriptor(reg_area));
- reg_area.type = MB_PARAM_HOLDING;
- reg_area.start_offset = MB_REG_HOLDING_START_AREA7;
- reg_area.address = (void*)&holding_reg_params.reg933;
- reg_area.size = sizeof(float) << 1;
- ESP_ERROR_CHECK(mbc_slave_set_descriptor(reg_area));
- reg_area.type = MB_PARAM_HOLDING;
- reg_area.start_offset = MB_REG_HOLDING_START_AREA8;
- reg_area.address = (void*)&holding_reg_params.reg1027;
- reg_area.size = sizeof(float) << 1;
- ESP_ERROR_CHECK(mbc_slave_set_descriptor(reg_area));
- reg_area.type = MB_PARAM_HOLDING;
- setup_reg_data(); // Set values into known state
Thank you in advance!