Skip to content

Commit

Permalink
Merge pull request #749 from sjasonsmith/SWSERIAL_SEND
Browse files Browse the repository at this point in the history
Fix single-pin half-duplex in SoftwareSerial::send
  • Loading branch information
fpistm committed Nov 6, 2019
2 parents 2b1bdca + 2991308 commit db1b90f
Showing 1 changed file with 7 additions and 8 deletions.
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

0 comments on commit db1b90f

Please sign in to comment.