From ea6a5a2d4e3978ae87078b8eba62fd90ad23f9bb Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 2 Jan 2023 15:08:40 +0100 Subject: [PATCH] Removed delays in TasmotaSerial and TasmotaModbus Tx enable switching --- CHANGELOG.md | 2 ++ RELEASENOTES.md | 2 ++ .../TasmotaSerial-3.6.0/src/TasmotaSerial.cpp | 2 -- .../TasmotaModbus-3.6.0/src/TasmotaModbus.cpp | 20 ++++++++++++++----- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 119ada0af..0f8e98bc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,9 +11,11 @@ All notable changes to this project will be documented in this file. ### Changed - Energy totals max supported value from +/-21474.83647 to +/-2147483.647 kWh +- Removed delays in TasmotaSerial and TasmotaModbus Tx enable switching ### Fixed - Energy dummy switched voltage and power regression from v12.2.0.2 +- Orno WE517 modbus serial config 8E1 setting (#17545) ### Removed diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 0d4803065..d1ad2cc54 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -125,6 +125,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm ### Changed - ESP32 Framework (Core) from v2.0.5.3 to v2.0.6 (IPv6 support) - Energy totals max supported value from +/-21474.83647 to +/-2147483.647 kWh +- Removed delays in TasmotaSerial and TasmotaModbus Tx enable switching - TuyaMcu rewrite by btsimonh [#17051](https://github.com/arendst/Tasmota/issues/17051) - Tasmota OTA scripts now support both unzipped and gzipped file uploads [#17378](https://github.com/arendst/Tasmota/issues/17378) @@ -134,5 +135,6 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm - ESP8266 set GPIO's to input on power on fixing relay spikes [#17531](https://github.com/arendst/Tasmota/issues/17531) - Shutter default motorstop set to 0 [#17403](https://github.com/arendst/Tasmota/issues/17403) - Shutter default tilt configuration [#17484](https://github.com/arendst/Tasmota/issues/17484) +- Orno WE517 modbus serial config 8E1 setting [#17545](https://github.com/arendst/Tasmota/issues/17545) ### Removed diff --git a/lib/default/TasmotaSerial-3.6.0/src/TasmotaSerial.cpp b/lib/default/TasmotaSerial-3.6.0/src/TasmotaSerial.cpp index b30ec296c..a233422be 100644 --- a/lib/default/TasmotaSerial-3.6.0/src/TasmotaSerial.cpp +++ b/lib/default/TasmotaSerial-3.6.0/src/TasmotaSerial.cpp @@ -424,7 +424,6 @@ size_t TasmotaSerial::write(uint8_t b) { if (m_tx_enable_pin > -1) { digitalWrite(m_tx_enable_pin, HIGH); - delayMicroseconds(10); // delay(1) will exception here } size_t size = 0; if (m_hardserial) { @@ -461,7 +460,6 @@ size_t TasmotaSerial::write(uint8_t b) { size = 1; } if (m_tx_enable_pin > -1) { - delayMicroseconds(10); // delay(1) will exception here digitalWrite(m_tx_enable_pin, LOW); } return size; diff --git a/lib/lib_basic/TasmotaModbus-3.6.0/src/TasmotaModbus.cpp b/lib/lib_basic/TasmotaModbus-3.6.0/src/TasmotaModbus.cpp index 98773a285..4319c5d8a 100644 --- a/lib/lib_basic/TasmotaModbus-3.6.0/src/TasmotaModbus.cpp +++ b/lib/lib_basic/TasmotaModbus-3.6.0/src/TasmotaModbus.cpp @@ -27,10 +27,15 @@ enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_D //#define TASMOTAMODBUSDEBUG +#define TASMOTA_MODBUS_TX_ENABLE // Use local Tx enable on write buffer + TasmotaModbus::TasmotaModbus(int receive_pin, int transmit_pin, int tx_enable_pin) : TasmotaSerial(receive_pin, transmit_pin, 2) { -// setTransmitEnablePin(tx_enable_pin); - mb_tx_enable_pin = tx_enable_pin; +#ifdef TASMOTA_MODBUS_TX_ENABLE + mb_tx_enable_pin = tx_enable_pin; // Use local Tx enable on write buffer +#else + setTransmitEnablePin(tx_enable_pin); // Use TasmotaSerial Tx enable on write byte +#endif // TASMOTA_MODBUS_TX_ENABLE mb_address = 0; } @@ -59,10 +64,12 @@ int TasmotaModbus::Begin(long speed, uint32_t config) if (begin(speed, config)) { result = 1; if (hardwareSerial()) { result = 2; } +#ifdef TASMOTA_MODBUS_TX_ENABLE if (mb_tx_enable_pin > -1) { pinMode(mb_tx_enable_pin, OUTPUT); digitalWrite(mb_tx_enable_pin, LOW); } +#endif // TASMOTA_MODBUS_TX_ENABLE } return result; } @@ -148,22 +155,25 @@ uint8_t TasmotaModbus::Send(uint8_t device_address, uint8_t function_code, uint1 buf = (uint8_t *)malloc(bufsize); memset(buf, 0, bufsize); uint16_t i; - for (i = 0; i < framepointer;i++) + for (i = 0; i < framepointer;i++) { snprintf((char *)&buf[i*3], (bufsize-i*3), "%02X ",frame[i]); + } AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("MBS: Serial Send: %s"), buf); free(buf); #endif flush(); +#ifdef TASMOTA_MODBUS_TX_ENABLE if (mb_tx_enable_pin > -1) { digitalWrite(mb_tx_enable_pin, HIGH); - delayMicroseconds(10); // delay(1) will exception here } +#endif // TASMOTA_MODBUS_TX_ENABLE write(frame, framepointer); +#ifdef TASMOTA_MODBUS_TX_ENABLE if (mb_tx_enable_pin > -1) { - delayMicroseconds(10); // delay(1) will exception here digitalWrite(mb_tx_enable_pin, LOW); } +#endif // TASMOTA_MODBUS_TX_ENABLE free(frame); return 0; }