Skip to content

Commit db1b90f

Browse files
authored
Merge pull request #749 from sjasonsmith/SWSERIAL_SEND
Fix single-pin half-duplex in SoftwareSerial::send
2 parents 2b1bdca + 2991308 commit db1b90f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Diff for: libraries/SoftwareSerial/src/SoftwareSerial.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,15 @@ inline void SoftwareSerial::send()
227227
tx_tick_cnt = OVERSAMPLE; // Wait OVERSAMPLE tick to send next bit
228228
} else { // Transmission finished
229229
tx_tick_cnt = 1;
230-
if (_output_pending || !(_half_duplex && active_listener == this)) {
230+
if (_output_pending) {
231231
active_out = nullptr;
232-
rx_bit_cnt = -1; // rx_bit_cnt = -1 : waiting for start bit
233-
rx_tick_cnt = 2; // 2 : next interrupt will be discarded. 2 interrupts required to consider RX pin level
234-
active_in = this;
235-
// When in half-duplex mode, we wait for HALFDUPLEX_SWITCH_DELAY bit-periods after the byte has
232+
233+
// When in half-duplex mode, wait for HALFDUPLEX_SWITCH_DELAY bit-periods after the byte has
236234
// been transmitted before allowing the switch to RX mode
237235
} else if (tx_bit_cnt > 10 + OVERSAMPLE * HALFDUPLEX_SWITCH_DELAY) {
238-
pinMode(_receivePin, _inverse_logic ? INPUT_PULLDOWN : INPUT_PULLUP); // pullup for normal logic!
236+
if (_half_duplex && active_listener == this) {
237+
setRXTX(true);
238+
}
239239
active_out = nullptr;
240240
}
241241
}
@@ -348,11 +348,10 @@ void SoftwareSerial::begin(long speed)
348348
if (!_half_duplex) {
349349
setTX();
350350
setRX();
351+
listen();
351352
} else {
352353
setTX();
353354
}
354-
355-
listen();
356355
}
357356

358357
void SoftwareSerial::end()

0 commit comments

Comments
 (0)