Espressif ESP32-S2 Programming Manual page 634

Table of Contents

Advertisement

Chapter 2. API Reference
Modbus Slave API Overview
Modbus Master API Overview
Modbus Port Initialization
initialized before calling any other Modbus API. The functions below are used to create and then initialize Modbus
controller interface (either master or slave) over a particular transmission medium (either Serial or TCP/IP):
mbc_slave_init()
mbc_master_init()
mbc_slave_init_tcp()
mbc_master_init_tcp()
The API call uses the first parameter to recognize the type of port being initialized. Supported enumeration
for different ports: MB_PORT_SERIAL_MASTER,
MB_PORT_TCP_MASTER,
void*
master_handler
// Initialization of Modbus master for serial port
esp_err_t err
=
mbc_master_init(MB_PORT_SERIAL_MASTER, &master_handler);
if
(master_handler
==
ESP_LOGE(TAG,
"mb controller initialization
}
This example code to initialize slave port:
void*
slave_handler
// Initialization of Modbus slave for TCP
esp_err_t err
=
mbc_slave_init_tcp(&slave_handler);
if
(slave_handler
==
// Error handling is performed here
ESP_LOGE(TAG,
"mb controller initialization
}
Espressif Systems
Fig. 26: Modbus data mapping
The ESP_Modbus supports Modbus SERIAL and TCP ports and a port must be
MB_PORT_TCP_SLAVE
=
NULL;
// Pointer to allocate interface structure
NULL
||
err
!=
ESP_OK) {
=
NULL;
// Pointer to allocate interface structure
NULL
||
err
!=
ESP_OK) {
Submit Document Feedback
MB_PORT_SERIAL_SLAVE
are reserved for internal usage.
fail.");
fail.");
623
accordingly. The parameters
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