From 7dbdddb5953bc85174f86ef3e27716f58a26e170 Mon Sep 17 00:00:00 2001 From: proddy Date: Sun, 30 Aug 2020 21:18:40 +0200 Subject: [PATCH] merge with Michael's latest uart code - https://github.com/proddy/EMS-ESP/commit/754356b5e280d00e7be0990a6026e0f782de48dc --- src/uart/emsuart_esp8266.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/uart/emsuart_esp8266.cpp b/src/uart/emsuart_esp8266.cpp index 720a199bd..8c278eb6c 100644 --- a/src/uart/emsuart_esp8266.cpp +++ b/src/uart/emsuart_esp8266.cpp @@ -46,9 +46,9 @@ void ICACHE_RAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) { if (USIS(EMSUART_UART) & ((1 << UIBD))) { // BREAK detection = End of EMS data block USC0(EMSUART_UART) &= ~(1 << UCBRK); // reset tx-brk - if (emsTxBufIdx < emsTxBufLen) { // irq tx_mode is interrupted by - emsTxBufIdx = emsTxBufLen + 1; // stop tx - // drop_next_rx = true; // we have trash in buffer + if (emsTxBufLen > 0) { // timer tx_mode is interrupted by + emsTxBufLen = 0; + drop_next_rx = true; } USIC(EMSUART_UART) = (1 << UIBD); // INT clear the BREAK detect interrupt length = 0; @@ -89,6 +89,9 @@ void ICACHE_FLASH_ATTR EMSuart::emsuart_recvTask(os_event_t * events) { // ISR to Fire when Timer is triggered void ICACHE_RAM_ATTR EMSuart::emsuart_tx_timer_intr_handler() { + if (emsTxBufLen == 0) { + return; + } emsTxBufIdx++; if (emsTxBufIdx < emsTxBufLen) { USF(EMSUART_UART) = emsTxBuf[emsTxBufIdx]; @@ -98,7 +101,8 @@ void ICACHE_RAM_ATTR EMSuart::emsuart_tx_timer_intr_handler() { timer1_write(EMSUART_TX_BRK_TIMER); } else { USC0(EMSUART_UART) &= ~(1 << UCBRK); // reset - sending_ = false; + sending_ = false; + emsTxBufLen = 0; } } @@ -279,7 +283,7 @@ uint16_t ICACHE_FLASH_ATTR EMSuart::transmit(uint8_t * buf, uint8_t len) { /* * Logic for tx_mode of 1 - * based on code from https://github.com/proddy/EMS-ESP/issues/103 by @susisstrolch + * based on original code from https://github.com/proddy/EMS-ESP/issues/103 by @susisstrolch * * Logic: * we emit the whole telegram, with Rx interrupt disabled, collecting busmaster response in FIFO.