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");
}