From 9084e36978e66fb1429c8461bcc4ba5bf64c037e Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Thu, 11 Nov 2021 14:44:54 +0100 Subject: [PATCH 1/2] 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; } From a36331fe4742d980d1940eec3cd6d17407b7fa04 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Thu, 11 Nov 2021 19:22:15 +0100 Subject: [PATCH 2/2] Improved for zigbee --- .../TasmotaSerial-3.3.0/src/TasmotaSerial.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/default/TasmotaSerial-3.3.0/src/TasmotaSerial.cpp b/lib/default/TasmotaSerial-3.3.0/src/TasmotaSerial.cpp index 57f695131..8b21de109 100644 --- a/lib/default/TasmotaSerial-3.3.0/src/TasmotaSerial.cpp +++ b/lib/default/TasmotaSerial-3.3.0/src/TasmotaSerial.cpp @@ -159,11 +159,21 @@ bool TasmotaSerial::begin(uint32_t speed, uint32_t config) { } // For low bit rate, below 9600, set the Full RX threshold at 10 bytes instead of the default 120 if (speed <= 9600) { + // At 9600, 10 chars are ~10ms uart_set_rx_full_threshold(m_uart, 10); + } else if (speed < 115200) { + // At 19200, 120 chars are ~60ms + // At 76800, 120 chars are ~15ms + uart_set_rx_full_threshold(m_uart, 120); + } else { + // At 115200, 256 chars are ~20ms + // Zigbee requires to keep frames together, i.e. 256 bytes max + uart_set_rx_full_threshold(m_uart, 256); } - // For bitrate below 115200, set the Rx time out to 5 chars instead of the default 10 + // For bitrate below 115200, set the Rx time out to 6 chars instead of the default 10 if (speed < 115200) { - uart_set_rx_timeout(m_uart, 5); + // At 76800 the timeout is ~1ms + uart_set_rx_timeout(m_uart, 6); } } else { m_valid = false;