Skip to content

Commit 4d3ccb4

Browse files
Clear SoftwareSerial rx delay if no interrupt register is found
Before enabling interupts, begin would see if the given receive pin actually has an associated PCINT register. If not, the interrupts would not be enabled. Now, the same check is done, but when no register is available, the rx parameters are not loaded at all (which in turn prevents the interrupt from being enabled). This allows all code to use the same "is rx enabled" (which will be added next).
1 parent 073ff13 commit 4d3ccb4

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

libraries/SoftwareSerial/SoftwareSerial.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,13 @@ void SoftwareSerial::begin(long speed)
385385
long baud = pgm_read_dword(&table[i].baud);
386386
if (baud == speed)
387387
{
388-
_rx_delay_centering = pgm_read_word(&table[i].rx_delay_centering);
389-
_rx_delay_intrabit = pgm_read_word(&table[i].rx_delay_intrabit);
390-
_rx_delay_stopbit = pgm_read_word(&table[i].rx_delay_stopbit);
388+
if (digitalPinToPCICR(_receivePin))
389+
{
390+
// Only setup rx when we have a valid PCINT for this pin
391+
_rx_delay_centering = pgm_read_word(&table[i].rx_delay_centering);
392+
_rx_delay_intrabit = pgm_read_word(&table[i].rx_delay_intrabit);
393+
_rx_delay_stopbit = pgm_read_word(&table[i].rx_delay_stopbit);
394+
}
391395
_tx_delay = pgm_read_word(&table[i].tx_delay);
392396
break;
393397
}
@@ -396,11 +400,8 @@ void SoftwareSerial::begin(long speed)
396400
// Set up RX interrupts, but only if we have a valid RX baud rate
397401
if (_rx_delay_stopbit)
398402
{
399-
if (digitalPinToPCICR(_receivePin))
400-
{
401-
*digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
402-
*digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
403-
}
403+
*digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
404+
*digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
404405
tunedDelay(_tx_delay); // if we were low this establishes the end
405406
}
406407

0 commit comments

Comments
 (0)