Modbus Slave on UART0

kcmopilot
Posts: 1
Joined: Sun Nov 30, 2025 7:22 pm

Modbus Slave on UART0

Postby kcmopilot » Sun Nov 30, 2025 7:37 pm

Using ESP-IDF version 5.4.1. Custom hardware using ESP32-S3 with Modbus RTU on UART0. There is a MUX that switches between the debug serial and Modbus.

I was able to make it work briefly, reading data from a PLC master, so I can verify that the hardware is all correct. However, no matter what I try, as soon as I call mbc_slave_create_serial(), the system locks up when monitoring via JTAG. I can't figure out how to get around this, and I can't figure out how to debug further.

Code: Select all

    // Set up the MUX for the serial port.  Modbus UART is the same as the debug UART
    gpio_set_direction(MODBUS_MUX_PIN, GPIO_MODE_OUTPUT);
    gpio_set_level(MODBUS_MUX_PIN, 1);
    ESP_LOGI(TAG, "GPIO for MUX configured");
    
    // Set up the serial port
    comm_config.ser_opts.port = MODBUS_PORT_NUM;
    comm_config.ser_opts.mode = MB_RTU;
    comm_config.ser_opts.baudrate = MB_BAUD_RATE;
    comm_config.ser_opts.parity = MB_PARITY_NONE;
    comm_config.ser_opts.uid = get_modbus_slave_id();
    comm_config.ser_opts.data_bits = UART_DATA_8_BITS;
    comm_config.ser_opts.stop_bits = UART_STOP_BITS_1;

    // Create the Serial port
    ESP_LOGI(TAG, "Calling mbc_slave_create_serial");
    esp_err_t err = (mbc_slave_create_serial(&comm_config, &s_slave_handle)); 	// locks up here.

    if (s_slave_handle == NULL || err != ESP_OK) {
        ESP_LOGE(TAG, "mb controller initialization fail.");
    }
    else {
        ESP_LOGI(TAG, "Controller created");
    }

Who is online

Users browsing this forum: Amazon [Bot], ChatGPT-User, Google [Bot] and 1 guest