Removed delays in TasmotaSerial and TasmotaModbus Tx enable switching

This commit is contained in:
Theo Arends 2023-01-02 15:08:40 +01:00
parent e375448090
commit ea6a5a2d4e
4 changed files with 19 additions and 7 deletions

View File

@ -11,9 +11,11 @@ All notable changes to this project will be documented in this file.
### Changed ### Changed
- Energy totals max supported value from +/-21474.83647 to +/-2147483.647 kWh - Energy totals max supported value from +/-21474.83647 to +/-2147483.647 kWh
- Removed delays in TasmotaSerial and TasmotaModbus Tx enable switching
### Fixed ### Fixed
- Energy dummy switched voltage and power regression from v12.2.0.2 - Energy dummy switched voltage and power regression from v12.2.0.2
- Orno WE517 modbus serial config 8E1 setting (#17545)
### Removed ### Removed

View File

@ -125,6 +125,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm
### Changed ### Changed
- ESP32 Framework (Core) from v2.0.5.3 to v2.0.6 (IPv6 support) - 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 - 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) - 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) - 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) - 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 motorstop set to 0 [#17403](https://github.com/arendst/Tasmota/issues/17403)
- Shutter default tilt configuration [#17484](https://github.com/arendst/Tasmota/issues/17484) - 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 ### Removed

View File

@ -424,7 +424,6 @@ size_t TasmotaSerial::write(uint8_t b) {
if (m_tx_enable_pin > -1) { if (m_tx_enable_pin > -1) {
digitalWrite(m_tx_enable_pin, HIGH); digitalWrite(m_tx_enable_pin, HIGH);
delayMicroseconds(10); // delay(1) will exception here
} }
size_t size = 0; size_t size = 0;
if (m_hardserial) { if (m_hardserial) {
@ -461,7 +460,6 @@ size_t TasmotaSerial::write(uint8_t b) {
size = 1; size = 1;
} }
if (m_tx_enable_pin > -1) { if (m_tx_enable_pin > -1) {
delayMicroseconds(10); // delay(1) will exception here
digitalWrite(m_tx_enable_pin, LOW); digitalWrite(m_tx_enable_pin, LOW);
} }
return size; return size;

View File

@ -27,10 +27,15 @@ enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_D
//#define TASMOTAMODBUSDEBUG //#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) TasmotaModbus::TasmotaModbus(int receive_pin, int transmit_pin, int tx_enable_pin) : TasmotaSerial(receive_pin, transmit_pin, 2)
{ {
// setTransmitEnablePin(tx_enable_pin); #ifdef TASMOTA_MODBUS_TX_ENABLE
mb_tx_enable_pin = tx_enable_pin; 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; mb_address = 0;
} }
@ -59,10 +64,12 @@ int TasmotaModbus::Begin(long speed, uint32_t config)
if (begin(speed, config)) { if (begin(speed, config)) {
result = 1; result = 1;
if (hardwareSerial()) { result = 2; } if (hardwareSerial()) { result = 2; }
#ifdef TASMOTA_MODBUS_TX_ENABLE
if (mb_tx_enable_pin > -1) { if (mb_tx_enable_pin > -1) {
pinMode(mb_tx_enable_pin, OUTPUT); pinMode(mb_tx_enable_pin, OUTPUT);
digitalWrite(mb_tx_enable_pin, LOW); digitalWrite(mb_tx_enable_pin, LOW);
} }
#endif // TASMOTA_MODBUS_TX_ENABLE
} }
return result; return result;
} }
@ -148,22 +155,25 @@ uint8_t TasmotaModbus::Send(uint8_t device_address, uint8_t function_code, uint1
buf = (uint8_t *)malloc(bufsize); buf = (uint8_t *)malloc(bufsize);
memset(buf, 0, bufsize); memset(buf, 0, bufsize);
uint16_t i; 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]); snprintf((char *)&buf[i*3], (bufsize-i*3), "%02X ",frame[i]);
}
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("MBS: Serial Send: %s"), buf); AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("MBS: Serial Send: %s"), buf);
free(buf); free(buf);
#endif #endif
flush(); flush();
#ifdef TASMOTA_MODBUS_TX_ENABLE
if (mb_tx_enable_pin > -1) { if (mb_tx_enable_pin > -1) {
digitalWrite(mb_tx_enable_pin, HIGH); digitalWrite(mb_tx_enable_pin, HIGH);
delayMicroseconds(10); // delay(1) will exception here
} }
#endif // TASMOTA_MODBUS_TX_ENABLE
write(frame, framepointer); write(frame, framepointer);
#ifdef TASMOTA_MODBUS_TX_ENABLE
if (mb_tx_enable_pin > -1) { if (mb_tx_enable_pin > -1) {
delayMicroseconds(10); // delay(1) will exception here
digitalWrite(mb_tx_enable_pin, LOW); digitalWrite(mb_tx_enable_pin, LOW);
} }
#endif // TASMOTA_MODBUS_TX_ENABLE
free(frame); free(frame);
return 0; return 0;
} }