EasyManua.ls Logo

Espressif ESP32-S2 - Page 641

Espressif ESP32-S2
1695 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Chapter 2. API Reference
esp_netif_init();
...
mb_communication_info_t comm_info = {
.ip_port = MB_TCP_PORT, // Modbus TCP port number (default
,= 502)
.ip_addr_type = MB_IPV4, // version of IP protocol
.ip_mode = MB_MODE_TCP, // Port communication mode
.ip_addr = NULL, // This field keeps the client IP
,address to bind, NULL - bind to any client
.ip_netif_ptr = esp_netif_ptr // esp_netif_ptr - pointer to the
,corresponding network interface
};
// Setup communication parameters and start stack
ESP_ERROR_CHECK(mbc_slave_setup((void*)&comm_info));
Example initialization of Modbus serial communication:
#define MB_SLAVE_DEV_SPEED 9600
#define MB_SLAVE_ADDR 1
#define MB_SLAVE_PORT_NUM 2
...
// Setup communication parameters and start stack
mb_communication_info_t comm_info = {
.mode = MB_MODE_RTU, // Communication type
.slave_addr = MB_SLAVE_ADDR, // Short address of the slave
.port = MB_SLAVE_PORT_NUM, // UART physical port number
.baudrate = MB_SLAVE_DEV_SPEED, // Baud rate for communication
.parity = MB_PARITY_NONE // Parity option
};
ESP_ERROR_CHECK(mbc_slave_setup((void*)&comm_info));
Slave Communication The function below is used to start Modbus controller interface and allows communication.
mbc_slave_start()
ESP_ERROR_CHECK(mbc_slave_start());
mbc_slave_check_event()
The blocking call to function waits for a event specied (represented as an event mask parameter). Once the master
accesses the parameter and the event mask matches the parameter type, the application task will be unblocked and
function will return the corresponding event mb_event_group_t which describes the type of register access being
done.
mbc_slave_get_param_info()
The function gets information about accessed parameters from the Modbus controller event queue. The KConfig
CONFIG_FMB_CONTROLLER_NOTIFY_QUEUE_SIZE key can be used to configure the notification queue size. The
timeout parameter allows a timeout to be specified when waiting for a notification. The mb_param_info_t
structure contains information about accessed parameter.
Espressif Systems 630
Submit Document Feedback
Release v4.4

Table of Contents