File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed
libraries/SoftwareSerial/src Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ The latest version of this library can always be found at
3535#define _DEBUG 0
3636#define _DEBUG_PIN1 11
3737#define _DEBUG_PIN2 13
38+
39+ #define HALFDUPLEX_SWITCH_DELAY 5
3840//
3941// Includes
4042//
@@ -93,8 +95,6 @@ bool SoftwareSerial::listen()
9395 {
9496 if (active_object)
9597 active_object->stopListening ();
96- if (_singleWirePin)
97- setupRXPin (_singleWirePin);
9898
9999 _buffer_overflow = false ;
100100 _receive_buffer_head = _receive_buffer_tail = 0 ;
@@ -393,7 +393,7 @@ void SoftwareSerial::begin(long speed)
393393 pinMode (_DEBUG_PIN2, OUTPUT);
394394#endif
395395
396- // Single-wire will be in TX mode by default
396+ // Single-wire will not listen by default
397397 if (!_singleWirePin)
398398 listen ();
399399}
@@ -439,7 +439,7 @@ int SoftwareSerial::available()
439439size_t SoftwareSerial::write (uint8_t b)
440440{
441441 if (_singleWirePin && isListening ())
442- return 0 ;
442+ setupTXPin () ;
443443
444444 if (_tx_delay == 0 ) {
445445 setWriteError ();
@@ -489,8 +489,13 @@ size_t SoftwareSerial::write(uint8_t b)
489489 *reg |= reg_mask;
490490
491491 SREG = oldSREG; // turn interrupts back on
492- tunedDelay (_tx_delay);
493-
492+
493+ if (!_singleWirePin)
494+ tunedDelay (_tx_delay);
495+ else if (isListening ()) {
496+ tunedDelay (_tx_delay * HALFDUPLEX_SWITCH_DELAY);
497+ setupRXPin (_singleWirePin);
498+ }
494499 return 1 ;
495500}
496501
You can’t perform that action at this time.
0 commit comments