Espressif ESP32-S2 Programming Manual page 637

Table of Contents

Advertisement

Chapter 2. API Reference
WRITE_TRIGGER },
};
// Calculate number of parameters in the table
uint16_t
num_device_parameters
parameters[0]));
During initialization of the Modbus stack, a pointer to the Data Dictionary (called descriptor) must be provided as
the parameter of the function below.
mbc_master_set_descriptor(): Initialization of master descriptor.
ESP_ERROR_CHECK(mbc_master_set_descriptor(&device_parameters[0], num_device_
parameters));
The Data Dictionary can be initialized from SD card, MQTT or other source before start of stack. Once the initial-
ization and setup is done, the Modbus controller allows the reading of complex parameters from any slave included
in descriptor table using its CID.
Master Communication Options
fined for port.
mbc_master_setup()
The communication structure provided as a parameter is different for serial and TCP communication mode.
Example setup for serial port:
mb_communication_info_t comm_info
.port
=
MB_PORT_NUM,
.mode
=
MB_MODE_RTU,
MODE_ASCII)
.baudrate
=
9600,
.parity
=
MB_PARITY_NONE
};
ESP_ERROR_CHECK(mbc_master_setup((void*)&comm_info));
Modbus master TCP port requires additional definition of IP address table where number of addresses should be
equal to number of unique slave addresses in master Modbus Data Dictionary:
The order of IP address string corresponds to short slave address in the Data Dictionary.
#define MB_SLAVE_COUNT 2
defined in Data Dictionary)
char*
slave_ip_address_table[MB_SLAVE_COUNT]
"192.168.1.2",
by user
"192.168.1.3",
NULL
};
mb_communication_info_t comm_info
.ip_port
=
MB_TCP_PORT,
= 502)
.ip_addr_type
=
.ip_mode
=
MB_MODE_TCP,
.ip_addr
=
(void*)slave_ip_address_table,
.ip_netif_ptr
=
corresponding network interface
Espressif Systems
0, PARAM_TYPE_FLOAT, 4, OPTS( 20, 30,
=
(sizeof(device_parameters)
Calling the setup function allows for specific communication options to be de-
=
{
// Serial port number
// Modbus mode of communication (MB_MODE_RTU or MB_
// Modbus communication baud rate
// parity option for serial port
// Number of slaves in the segment being accessed
// Address corresponds to UID1 and set to predefined
// corresponds to UID2 in the segment
// end of table
=
{
MB_IPV4,
esp_netif_ptr
Submit Document Feedback
1
=
{
// Modbus TCP port number
// version of IP protocol
// Port communication mode
// assign table of IP addresses
// esp_netif_ptr pointer to
626
(continued from previous page)
), PAR_PERMS_READ_
/
sizeof(device_
(as␣
value␣
(default␣
the␣
(continues on next page)
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?

Subscribe to Our Youtube Channel

Table of Contents

Save PDF