[SERIAL] Make SERIAL gateway frame format (data/parity/stop bits) configurable (#2342)
Serial.begin() was hardcoded to SERIAL_8N1 across all four UART init paths (UART0/1/2/3), with no way to override it via a build flag -- unlike SERIALBaud, which already is. Devices using non-8N1 framing (e.g. even-parity RS232 sources) currently can't be read correctly at all, not just unreliably: a parity mismatch misaligns the frame, not just adds occasional noise. Adds SERIAL_CONFIG following the existing #ifndef/#define override pattern used throughout this codebase, defaulting to SERIAL_8N1 so existing environments are unaffected byte-for-byte. Verified: default (SERIAL_8N1) and an override (SERIAL_CONFIG=SERIAL_8E1) both build successfully on ESP32. Co-authored-by: simowilso <simowilso@users.noreply.github.com> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2 files changed
+11
-7
No files matched your search
@@ -81,6 +81,10 @@ extern bool XtoSERIAL(const char* topicOri, JsonObject& SERIALdata);
|
||||
# define SERIALBaud 9600 // The serial connection Baud
|
||||
#endif
|
||||
|
||||
#ifndef SERIAL_CONFIG
|
||||
# define SERIAL_CONFIG SERIAL_8N1 // The serial frame format (data/parity/stop bits), e.g. SERIAL_8E1 for 8 data bits/even parity/1 stop bit
|
||||
#endif
|
||||
|
||||
/*-------------------PIN DEFINITIONS----------------------*/
|
||||
#ifndef SERIAL_UART
|
||||
// set hardware serial UART to be used for device communication or
|
||||
|
||||
@@ -78,9 +78,9 @@ void setupSERIAL() {
|
||||
# if SERIAL_UART == 0 // init UART0
|
||||
Serial.end(); // stop if already initialized
|
||||
# ifdef ESP32
|
||||
Serial.begin(SERIALBaud, SERIAL_8N1, SERIAL_RX_GPIO, SERIAL_TX_GPIO);
|
||||
Serial.begin(SERIALBaud, SERIAL_CONFIG, SERIAL_RX_GPIO, SERIAL_TX_GPIO);
|
||||
# else
|
||||
Serial.begin(SERIALBaud, SERIAL_8N1);
|
||||
Serial.begin(SERIALBaud, SERIAL_CONFIG);
|
||||
# endif
|
||||
# if defined(ESP8266) && defined(SERIAL_UART0_SWAP)
|
||||
Serial.swap(); // swap UART0 ports from (GPIO1,GPIO3) to (GPIO15,GPIO13)
|
||||
@@ -91,9 +91,9 @@ void setupSERIAL() {
|
||||
# elif SERIAL_UART == 1 // init UART1
|
||||
Serial1.end(); // stop if already initialized
|
||||
# ifdef ESP32
|
||||
Serial1.begin(SERIALBaud, SERIAL_8N1, SERIAL_RX_GPIO, SERIAL_TX_GPIO);
|
||||
Serial1.begin(SERIALBaud, SERIAL_CONFIG, SERIAL_RX_GPIO, SERIAL_TX_GPIO);
|
||||
# else
|
||||
Serial1.begin(SERIALBaud, SERIAL_8N1);
|
||||
Serial1.begin(SERIALBaud, SERIAL_CONFIG);
|
||||
# endif
|
||||
SERIALStream = &Serial1;
|
||||
THEENGS_LOG_NOTICE(F("SERIAL HW UART1" CR));
|
||||
@@ -101,16 +101,16 @@ void setupSERIAL() {
|
||||
# elif SERIAL_UART == 2 // init UART2
|
||||
Serial2.end(); // stop if already initialized
|
||||
# ifdef ESP32
|
||||
Serial2.begin(SERIALBaud, SERIAL_8N1, SERIAL_RX_GPIO, SERIAL_TX_GPIO);
|
||||
Serial2.begin(SERIALBaud, SERIAL_CONFIG, SERIAL_RX_GPIO, SERIAL_TX_GPIO);
|
||||
# else
|
||||
Serial2.begin(SERIALBaud, SERIAL_8N1);
|
||||
Serial2.begin(SERIALBaud, SERIAL_CONFIG);
|
||||
# endif
|
||||
SERIALStream = &Serial2;
|
||||
THEENGS_LOG_NOTICE(F("SERIAL HW UART2" CR));
|
||||
|
||||
# elif SERIAL_UART == 3 // init UART3
|
||||
Serial3.end(); // stop if already initialized
|
||||
Serial3.begin(SERIALBaud, SERIAL_8N1);
|
||||
Serial3.begin(SERIALBaud, SERIAL_CONFIG);
|
||||
SERIALStream = &Serial3;
|
||||
THEENGS_LOG_NOTICE(F("SERIAL HW UART3" CR));
|
||||
# endif
|
||||
|
||||
Reference in new issue
Block a user