Espressif ESP32-S2 Programming Manual page 640

Hide thumbs Also See for ESP32-S2:
Table of Contents

Advertisement

Chapter 2. API Reference
Field
Description
start_offset
Zero based register relative offset for defined register area. Example: register address = 40002 ( 4x
register area - Function 3 - holding register ), start_offset = 2
type
Type of the Modbus register area. Refer to
address A pointer to the memory area which is used to store the register data for this area descriptor.
size
The size of the memory area in bytes which is used to store register data.
mbc_slave_set_descriptor()
The function initializes Modbus communication descriptors for each type of Modbus register area (Holding
Registers, Input Registers, Coils (single bit output), Discrete Inputs).
mbc_slave_start()
from master.
#define MB_REG_INPUT_START_AREA0
#define MB_REG_HOLDING_START_AREA0
#define MB_REG_HOLD_CNT
#define MB_REG_INPUT_CNT
mb_register_area_descriptor_t reg_area;
structure
unit16_t holding_reg_area[MB_REG_HOLD_CNT]
registers
unit16_t input_reg_area[MB_REG_INPUT_CNT]
registers
reg_area.type
=
MB_PARAM_HOLDING;
register area
reg_area.start_offset
register area in Modbus protocol
reg_area.address
=
(void*)&holding_reg_area[0];
storage instance
reg_area.size
=
sizeof(holding_reg_area)
register storage area in bytes
ESP_ERROR_CHECK(mbc_slave_set_descriptor(reg_area));
reg_area.type
=
MB_PARAM_INPUT;
reg_area.start_offset
reg_area.address
=
(void*)&input_reg_area[0];
reg_area.size
=
sizeof(input_reg_area)
ESP_ERROR_CHECK(mbc_slave_set_descriptor(reg_area));
At least one area descriptor per each Modbus register type must be set in order to provide register access to its area.
If the master tries to access an undefined area, the stack will generate a Modbus exception.
Direct access to register area from user application must be protected by critical section:
portENTER_CRITICAL(&param_lock);
holding_reg_area[2]
portEXIT_CRITICAL(&param_lock);
Slave Communication Options
(tasks, RTOS objects and other resources).
mbc_slave_setup()
The function is used to setup communication parameters of the Modbus stack.
Example initialization of Modbus TCP communication:
Espressif Systems
Table 9: Table 3 Modbus register area descriptor
API is called the Modbus stack can access the data in user data structures by request
(0)
(0)
(100)
(100)
=
MB_REG_HOLDING_START_AREA0;
=
MB_REG_INPUT_START_AREA0;
+=
10;
The function initializes the Modbus controller interface and its active context
Submit Document Feedback
mb_param_type_t
for more information.
Once areas are initialized and the
// Modbus register area
=
{0};
// storage area for
=
{0};
// storage area for
<<
1;
<<
1;
629
descriptor␣
holding␣
input␣
// Set type
of␣
// Offset
of␣
// Set pointer
to␣
// Set the size
of␣
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Table of Contents

Save PDF