@@ -246,13 +246,14 @@ ISR(PCINT3_vect, ISR_ALIASOF(PCINT0_vect));
246
246
//
247
247
// Constructor
248
248
//
249
- SoftwareSerial::SoftwareSerial (uint8_t receivePin, uint8_t transmitPin, bool inverse_logic /* = false */ ) :
249
+ SoftwareSerial::SoftwareSerial (uint8_t receivePin, uint8_t transmitPin, bool inverse_logic /* = false */ , bool full_duplex /* = true */ ) :
250
250
_rx_delay_centering(0 ),
251
251
_rx_delay_intrabit(0 ),
252
252
_rx_delay_stopbit(0 ),
253
253
_tx_delay(0 ),
254
254
_buffer_overflow(false ),
255
- _inverse_logic(inverse_logic)
255
+ _inverse_logic(inverse_logic),
256
+ _full_duplex(full_duplex)
256
257
{
257
258
setTX (transmitPin);
258
259
setRX (receivePin);
@@ -273,7 +274,11 @@ void SoftwareSerial::setTX(uint8_t tx)
273
274
// output high. Now, it is input with pullup for a short while, which
274
275
// is fine. With inverse logic, either order is fine.
275
276
digitalWrite (tx, _inverse_logic ? LOW : HIGH);
276
- pinMode (tx, OUTPUT);
277
+ if (_full_duplex)
278
+ pinMode (tx, OUTPUT);
279
+ else
280
+ pinMode (tx, INPUT);
281
+ _transmitPin = tx;
277
282
_transmitBitMask = digitalPinToBitMask (tx);
278
283
uint8_t port = digitalPinToPort (tx);
279
284
_transmitPortRegister = portOutputRegister (port);
@@ -418,6 +423,9 @@ size_t SoftwareSerial::write(uint8_t b)
418
423
setWriteError ();
419
424
return 0 ;
420
425
}
426
+
427
+ if (!_full_duplex)
428
+ pinMode (_transmitPin, OUTPUT);
421
429
422
430
// By declaring these as local variables, the compiler will put them
423
431
// in registers _before_ disabling interrupts and entering the
@@ -461,6 +469,11 @@ size_t SoftwareSerial::write(uint8_t b)
461
469
else
462
470
*reg |= reg_mask;
463
471
472
+ if (!_full_duplex){
473
+ pinMode (_transmitPin, INPUT);
474
+ *reg |= reg_mask; // send 1
475
+ }
476
+
464
477
SREG = oldSREG; // turn interrupts back on
465
478
tunedDelay (_tx_delay);
466
479
0 commit comments