From c1484f761c9827cb9e3904641f958eefd10d5810 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 28 Dec 2022 15:19:09 +0100 Subject: [PATCH] Fix exception 9 when modbus tx enable is used --- lib/default/TasmotaSerial-3.6.0/src/TasmotaSerial.cpp | 2 +- .../TasmotaModbus-3.6.0/src/TasmotaModbus.cpp | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/default/TasmotaSerial-3.6.0/src/TasmotaSerial.cpp b/lib/default/TasmotaSerial-3.6.0/src/TasmotaSerial.cpp index d690c62eb..20654b05f 100644 --- a/lib/default/TasmotaSerial-3.6.0/src/TasmotaSerial.cpp +++ b/lib/default/TasmotaSerial-3.6.0/src/TasmotaSerial.cpp @@ -460,7 +460,7 @@ size_t TasmotaSerial::write(uint8_t b) { size = 1; } if (m_tx_enable_pin > -1) { - delay(1); + delayMicroseconds(800); // 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 baf66f8b0..0fb316bd3 100644 --- a/lib/lib_basic/TasmotaModbus-3.6.0/src/TasmotaModbus.cpp +++ b/lib/lib_basic/TasmotaModbus-3.6.0/src/TasmotaModbus.cpp @@ -31,11 +31,6 @@ TasmotaModbus::TasmotaModbus(int receive_pin, int transmit_pin, int tx_enable_pi { // setTransmitEnablePin(tx_enable_pin); mb_tx_enable_pin = tx_enable_pin; - if (mb_tx_enable_pin > -1) { - pinMode(mb_tx_enable_pin, OUTPUT); - digitalWrite(mb_tx_enable_pin, LOW); - } - mb_address = 0; } @@ -64,6 +59,10 @@ int TasmotaModbus::Begin(long speed, uint32_t config) if (begin(speed, config)) { result = 1; if (hardwareSerial()) { result = 2; } + if (mb_tx_enable_pin > -1) { + pinMode(mb_tx_enable_pin, OUTPUT); + digitalWrite(mb_tx_enable_pin, LOW); + } } return result; } @@ -161,7 +160,7 @@ uint8_t TasmotaModbus::Send(uint8_t device_address, uint8_t function_code, uint1 } write(frame, framepointer); if (mb_tx_enable_pin > -1) { - delay(1); + delayMicroseconds(800); // delay(1) will exception here digitalWrite(mb_tx_enable_pin, LOW); } free(frame);