Espressif ESP32-S2 Programming Manual page 635

Table of Contents

Advertisement

Chapter 2. API Reference
Modbus Master API Overview
The following overview describes how to setup Modbus master communication. The overview reflects a typical
programming workflow and is broken down into the sections provided below:
1.
Modbus Port Initialization
2.
Configuring Master Data Access
3.
Master Communication Options
4.
Master Communication
5.
Modbus Master Teardown
Configuring Master Data Access
Modbus IO driver. The additional layer is called Modbus controller and its goal is to add an abstraction such as
CID - characteristic identifier. The CID is linked to a corresponding Modbus registers through the table called Data
Dictionary and represents device physical parameter (such as temperature, humidity, etc.) in specific Modbus slave
device. This approach allows the upper layer (e.g., MESH or MQTT) to be isolated from Modbus specifics thus
simplify Modbus integration with other protocols/networks.
The Data Dictionary is the list in the Modbus master which shall be defined by user to link each CID to its cor-
responding Modbus registers representation using Register Mapping table of the Modbus slave being used. Each
element in this data dictionary is of type
physical characteristic:
Field
Description Detailed information
cid
Characteristic
The identifier of characteristic (must be unique).
ID
param_key
Characteristic
String description of the characteristic.
Name
param_units
Characteristic
Physical Units of the characteristic.
Units
mb_slave_addr
Modbus
The short address of the device with correspond parameter UID.
Slave
Address
mb_param_type
Modbus
Type of Modbus register area.
Register
MB_PARAM_COIL,
Type
Discrete input register area accordingly;
mb_reg_start
Modbus
Relative register address of the characteristic in the register area.
Register
Start
mb_size M odbus
Length of characteristic in registers.
Register
Size
param_offset
Instance
Offset to instance of the characteristic in bytes. It is used to calculate the absolute address
Offset
to the characteristic in the storage structure. It is optional field and can be set to zero if the
parameter is not used in the application.
param_type
Data
Specifies type of the characteristic.
Type
PARAM_TYPE_U32
IEEE754 floating point format;
param_size
Data
The storage size of the characteristic (bytes).
Size
param_opts
Parameter
Limits, options of characteristic used during processing of alarm in user application (optional)
Options
accessParameter
Can be used in user application to define the behavior of the characteristic dur-
access
ing processing of data in user application; PAR_PERMS_READ_WRITE_TRIGGER,
type
PAR_PERMS_READ, PAR_PERMS_READ_WRITE_TRIGGER;
Espressif Systems
- Initialization of Modbus controller interface for the selected port.
- Configure data descriptors to access slave parameters.
- Allows to setup communication options for selected port.
- Start stack and sending / receiving data.
- Destroy Modbus controller and its resources.
The architectural approach of ESP_Modbus includes one level above standard
mb_parameter_descriptor_t
Table 7: Table 1 Modbus master Data Dictionary description
MB_PARAM_DISCRETE
- Unsigned integer 8/16/32 bit type;
Submit Document Feedback
and represents the description of one
MB_PARAM_INPUT, MB_PARAM_HOLDING,
- represents Input , Holding, Coil and
PARAM_TYPE_U8, PARAM_TYPE_U16,
PARAM_TYPE_ASCII
- ASCII string or binary data;
624
PARAM_TYPE_FLOAT
-
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