From e7dac29e6aabb997a948d92a7513df89a1b3fcfb Mon Sep 17 00:00:00 2001 From: Vasil Date: Sat, 24 Jul 2021 12:34:14 +0300 Subject: [PATCH] Added explicit TX port and mask selection on write operation. The case as follows: two instances of NeoSWSerial are engaged. The first works in "listen-only" mode, while the second uses request-reply operation. After calling .listen() on first instance, the second instance does not transmit any data. The problem is that txPort and txBitMask are static variables shared across instances, and in write() function they are not assigned and used from previous call to another port instance. So transmission happen to wrong port. May be the cause of issue https://github.com/SlashDevin/NeoSWSerial/issues/33 --- src/NeoSWSerial.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/NeoSWSerial.cpp b/src/NeoSWSerial.cpp index ce8edfe..5cf7d81 100644 --- a/src/NeoSWSerial.cpp +++ b/src/NeoSWSerial.cpp @@ -539,6 +539,9 @@ size_t NeoSWSerial::write(uint8_t txChar) // the last 0 data bit. Then we could wait for the // remaining 1 data bits and stop bit with interrupts // re-enabled. + + txBitMask = digitalPinToBitMask( txPin ); + txPort = portOutputRegister( digitalPinToPort( txPin ) ); while (txBit++ < 9) { // repeat for start bit + 8 data bits if (b) // if bit is set