Skip to content

Commit 369aeee

Browse files
committed
600 Baud comm. support, unsupported baudrate notification
- Added a 600 Baud line in DELAY_TABLE, for each CPU frequency. (successfully tested for 16 MHz) - begin(long speed) now returns a bool indicating if speed has been found in DELAY_TABLE (if not, the method returns false immediately)
1 parent 0e0715a commit 369aeee

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

libraries/SoftwareSerial/SoftwareSerial.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ The latest version of this library can always be found at
4040
//
4141
#include <avr/interrupt.h>
4242
#include <avr/pgmspace.h>
43-
#include "Arduino.h"
44-
#include "SoftwareSerial.h"
43+
#include <Arduino.h>
44+
#include <SoftwareSerial.h>
4545
//
4646
// Lookup table
4747
//
@@ -70,6 +70,7 @@ static const DELAY_TABLE PROGMEM table[] =
7070
{ 4800, 233, 474, 474, 471, },
7171
{ 2400, 471, 950, 950, 947, },
7272
{ 1200, 947, 1902, 1902, 1899, },
73+
{ 600, 1902, 3804, 3804, 3800, },
7374
{ 300, 3804, 7617, 7617, 7614, },
7475
};
7576

@@ -91,6 +92,7 @@ static const DELAY_TABLE table[] PROGMEM =
9192
{ 4800, 110, 233, 233, 230, },
9293
{ 2400, 229, 472, 472, 469, },
9394
{ 1200, 467, 948, 948, 945, },
95+
{ 600, 948, 1895, 1895, 1890, },
9496
{ 300, 1895, 3805, 3805, 3802, },
9597
};
9698

@@ -115,6 +117,7 @@ static const DELAY_TABLE PROGMEM table[] =
115117
{ 4800, 296, 595, 595, 592, },
116118
{ 2400, 592, 1189, 1189, 1186, },
117119
{ 1200, 1187, 2379, 2379, 2376, },
120+
{ 600, 2379, 4759, 4759, 4755, },
118121
{ 300, 4759, 9523, 9523, 9520, },
119122
};
120123

@@ -373,13 +376,15 @@ void SoftwareSerial::setRX(uint8_t rx)
373376
// Public methods
374377
//
375378

376-
void SoftwareSerial::begin(long speed)
379+
bool SoftwareSerial::begin(long speed)
377380
{
378381
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
379382

383+
long baud = 0;
384+
380385
for (unsigned i=0; i<sizeof(table)/sizeof(table[0]); ++i)
381386
{
382-
long baud = pgm_read_dword(&table[i].baud);
387+
baud = pgm_read_dword(&table[i].baud);
383388
if (baud == speed)
384389
{
385390
_rx_delay_centering = pgm_read_word(&table[i].rx_delay_centering);
@@ -389,6 +394,7 @@ void SoftwareSerial::begin(long speed)
389394
break;
390395
}
391396
}
397+
if (baud != speed) return false;
392398

393399
// Set up RX interrupts, but only if we have a valid RX baud rate
394400
if (_rx_delay_stopbit)
@@ -407,6 +413,8 @@ void SoftwareSerial::begin(long speed)
407413
#endif
408414

409415
listen();
416+
417+
return true;
410418
}
411419

412420
void SoftwareSerial::end()

libraries/SoftwareSerial/SoftwareSerial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class SoftwareSerial : public Stream
8282
// public methods
8383
SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false);
8484
~SoftwareSerial();
85-
void begin(long speed);
85+
bool begin(long speed);
8686
bool listen();
8787
void end();
8888
bool isListening() { return this == active_object; }

0 commit comments

Comments
 (0)