Modbus RTU - Multi Devices

This commit is contained in:
2026-04-14 15:19:00 -05:00
commit fe8acfbc2c
1482 changed files with 182833 additions and 0 deletions

32
modbus_uart.txt Normal file
View File

@@ -0,0 +1,32 @@
if (cfg->rtu.de_pin >= 0)
{
ret = uart_set_mode(uart_num, UART_MODE_RS485_HALF_DUPLEX);
if (ret != ESP_OK)
{
ESP_LOGE(TAG, "uart_set_mode(RS485_HALF_DUPLEX) failed: %s", esp_err_to_name(ret));
return ret;
}
ESP_LOGI(TAG, "UART RS485 half-duplex mode enabled (DE pin=%d)", cfg->rtu.de_pin);
}
else
{
ESP_LOGI(TAG, "UART normal mode enabled (shield auto-direction assumed)");
}
if (resp_len > 0U)
{
int written = uart_write_bytes(g_rtu_ctx.uart_num,
(const char *)tx_buf,
(uint32_t)resp_len);
ESP_LOGI(TAG, "UART wrote %d bytes", written);
if (written < 0)
{
ESP_LOGW(TAG, "uart_write_bytes failed");
continue;
}
ESP_ERROR_CHECK(uart_wait_tx_done(g_rtu_ctx.uart_num, pdMS_TO_TICKS(100)));
}