Fix UART Flow Control for ESP-IDF

This commit is contained in:
brambo123 2024-03-12 20:47:39 +01:00
parent bb08168a11
commit 6cf23940e7
3 changed files with 10 additions and 7 deletions

View File

@ -214,9 +214,9 @@ void Modbus::send_raw(const std::vector<uint8_t> &payload) {
this->write_array(payload);
this->write_byte(crc & 0xFF);
this->write_byte((crc >> 8) & 0xFF);
if (this->flow_control_pin_ != nullptr) {
this->flush();
this->flush();
this->flow_control_pin_->digital_write(false);
}
waiting_for_response = payload[0];

View File

@ -89,30 +89,33 @@ def validate_invert_esp32(config):
)
return config
def validate_tx_buffer(value):
value = cv.validate_bytes(value)
if (
value <= 0 or
CORE.is_esp32
value <= 0
or CORE.is_esp32
):
return value
raise cv.Invalid(
"Hardware does not support UART TX buffer."
)
def validate_flow_control_support(config):
if CONF_FLOW_CONTROL_PIN not in config:
return config
if CORE.is_esp32:
if CORE.using_arduino and CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION] < cv.Version(2, 0, 8):
raise cv.Invalid(
"ESP32 RS485 UART Flow Control requires framework version 2.0.8 or higher."
)
"ESP32 RS485 UART Flow Control requires framework version 2.0.8 or higher."
)
return config
raise cv.Invalid(
"Hardware does not support RS485 flow control."
)
def _uart_declare_type(value):
if CORE.is_esp8266:
return cv.declare_id(ESP8266UartComponent)(value)

View File

@ -122,7 +122,7 @@ void IDFUARTComponent::setup() {
}
if (this->flow_control_pin_ != nullptr) {
err = uart_set_mode(uart_num, UART_MODE_RS485_HALF_DUPLEX);
err = uart_set_mode(this->uart_num_, UART_MODE_RS485_HALF_DUPLEX);
if (err != ESP_OK) {
ESP_LOGW(TAG, "uart_set_mode failed: %s", esp_err_to_name(err));
this->mark_failed();