Skip to content

Fix single-pin half-duplex in SoftwareSerial::send #749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions libraries/SoftwareSerial/src/SoftwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,15 @@ inline void SoftwareSerial::send()
tx_tick_cnt = OVERSAMPLE; // Wait OVERSAMPLE tick to send next bit
} else { // Transmission finished
tx_tick_cnt = 1;
if (_output_pending || !(_half_duplex && active_listener == this)) {
if (_output_pending) {
active_out = nullptr;
rx_bit_cnt = -1; // rx_bit_cnt = -1 : waiting for start bit
rx_tick_cnt = 2; // 2 : next interrupt will be discarded. 2 interrupts required to consider RX pin level
active_in = this;
// When in half-duplex mode, we wait for HALFDUPLEX_SWITCH_DELAY bit-periods after the byte has

// When in half-duplex mode, wait for HALFDUPLEX_SWITCH_DELAY bit-periods after the byte has
// been transmitted before allowing the switch to RX mode
} else if (tx_bit_cnt > 10 + OVERSAMPLE * HALFDUPLEX_SWITCH_DELAY) {
pinMode(_receivePin, _inverse_logic ? INPUT_PULLDOWN : INPUT_PULLUP); // pullup for normal logic!
if (_half_duplex && active_listener == this) {
setRXTX(true);
}
active_out = nullptr;
}
}
Expand Down Expand Up @@ -348,11 +348,10 @@ void SoftwareSerial::begin(long speed)
if (!_half_duplex) {
setTX();
setRX();
listen();
} else {
setTX();
}

listen();
}

void SoftwareSerial::end()
Expand Down