Chapter 2. API Reference
};
ESP_ERROR_CHECK(mbc_master_setup((void*)&comm_info));
Note: Refer to
esp_netif component
The slave IP addresses in the table can be assigned automatically using mDNS service as described in the example.
Refer to
protocols/modbus/tcp/mb_tcp_master
Note: RS485 communication requires call to UART specific APIs to setup communication mode and pins. Refer
to
Running UART Communication
Master Communication
is performed using function below:
mbc_master_start()
esp_err_t err
=
mbc_master_start();
if
(err
!=
ESP_OK) {
ESP_LOGE(TAG,
"mb controller start fail,
}
The list of functions below are used by the Modbus master stack from a user's application:
mbc_master_send_request(): This function executes a blocking Modbus request. The master sends a data
request (as defined in parameter request structure mb_param_request_t) and then blocks until a response from
corresponding slave and returns the status of command execution. This function provides a standard way for read/write
access to Modbus devices in the network.
mbc_master_get_cid_info(): The function gets information about each characteristic supported in the data
dictionary and returns the characteristic's description in the form of the
structure. Each characteristic is accessed using its CID.
mbc_master_get_parameter(): The function reads the data of a characteristic defined in the parameters of
a Modbus slave device. The additional data for request is taken from parameter description table.
Example:
const
mb_parameter_descriptor_t*
uint8_t
temp_data[4]
uint8_t
type
=
0;
....
// Get the information for characteristic cid from data dictionary
esp_err_t err
=
mbc_master_get_cid_info(cid, ¶m_descriptor);
if
((err
!=
ESP_ERR_NOT_FOUND)
err
=
mbc_master_get_parameter(param_descriptor->cid,
param_key, (uint8_t*)temp_data, &type);
→
if
(err
==
ESP_OK) {
ESP_LOGI(TAG,
",
→
}
else
{
ESP_LOGE(TAG,
Espressif Systems
for more information about network interface initialization.
for more information.
section of UART documentation.
The starting of the Modbus controller is the final step in enabling communication. This
param_descriptor
=
{0};
// temporary buffer to hold maximum CID size
&&
(param_descriptor
"Characteristic #%d %s (%s) value = (0x%08x) read successful.
param_descriptor->cid,
(char*)param_descriptor->param_key,
(char*)param_descriptor->param_units,
*(uint32_t*)temp_data);
"Characteristic #%d (%s) read fail, err = 0x%x
Submit Document Feedback
err=%x.", err);
mb_parameter_descriptor_t
=
NULL;
!=
NULL)) {
(char*)param_descriptor->
627
(continued from previous page)
(%s).",
(continues on next page)
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?