From 9084e36978e66fb1429c8461bcc4ba5bf64c037e Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Thu, 11 Nov 2021 14:44:54 +0100 Subject: [PATCH] Make serial more responsive at low bitrate --- lib/default/TasmotaSerial-3.3.0/src/TasmotaSerial.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/default/TasmotaSerial-3.3.0/src/TasmotaSerial.cpp b/lib/default/TasmotaSerial-3.3.0/src/TasmotaSerial.cpp index db3e3ccfa..57f695131 100644 --- a/lib/default/TasmotaSerial-3.3.0/src/TasmotaSerial.cpp +++ b/lib/default/TasmotaSerial-3.3.0/src/TasmotaSerial.cpp @@ -38,6 +38,8 @@ TasmotaSerial *tms_obj_list[16]; #endif // ESP8266 #ifdef ESP32 +#include "driver/uart.h" + #if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 static int tasmota_serial_index = 2; // Allow UART2 and UART1 only #elif CONFIG_IDF_TARGET_ESP32S2 // ESP32-S2 @@ -155,6 +157,14 @@ bool TasmotaSerial::begin(uint32_t speed, uint32_t config) { if (serial_buffer_size > 256) { TSerial->setRxBufferSize(serial_buffer_size); } + // For low bit rate, below 9600, set the Full RX threshold at 10 bytes instead of the default 120 + if (speed <= 9600) { + uart_set_rx_full_threshold(m_uart, 10); + } + // For bitrate below 115200, set the Rx time out to 5 chars instead of the default 10 + if (speed < 115200) { + uart_set_rx_timeout(m_uart, 5); + } } else { m_valid = false; }