mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +01:00
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)
This commit is contained in:
parent
0e0715abd3
commit
369aeeef51
@ -40,8 +40,8 @@ http://arduiniana.org.
|
|||||||
//
|
//
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
#include "Arduino.h"
|
#include <Arduino.h>
|
||||||
#include "SoftwareSerial.h"
|
#include <SoftwareSerial.h>
|
||||||
//
|
//
|
||||||
// Lookup table
|
// Lookup table
|
||||||
//
|
//
|
||||||
@ -70,6 +70,7 @@ static const DELAY_TABLE PROGMEM table[] =
|
|||||||
{ 4800, 233, 474, 474, 471, },
|
{ 4800, 233, 474, 474, 471, },
|
||||||
{ 2400, 471, 950, 950, 947, },
|
{ 2400, 471, 950, 950, 947, },
|
||||||
{ 1200, 947, 1902, 1902, 1899, },
|
{ 1200, 947, 1902, 1902, 1899, },
|
||||||
|
{ 600, 1902, 3804, 3804, 3800, },
|
||||||
{ 300, 3804, 7617, 7617, 7614, },
|
{ 300, 3804, 7617, 7617, 7614, },
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -91,6 +92,7 @@ static const DELAY_TABLE table[] PROGMEM =
|
|||||||
{ 4800, 110, 233, 233, 230, },
|
{ 4800, 110, 233, 233, 230, },
|
||||||
{ 2400, 229, 472, 472, 469, },
|
{ 2400, 229, 472, 472, 469, },
|
||||||
{ 1200, 467, 948, 948, 945, },
|
{ 1200, 467, 948, 948, 945, },
|
||||||
|
{ 600, 948, 1895, 1895, 1890, },
|
||||||
{ 300, 1895, 3805, 3805, 3802, },
|
{ 300, 1895, 3805, 3805, 3802, },
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -115,6 +117,7 @@ static const DELAY_TABLE PROGMEM table[] =
|
|||||||
{ 4800, 296, 595, 595, 592, },
|
{ 4800, 296, 595, 595, 592, },
|
||||||
{ 2400, 592, 1189, 1189, 1186, },
|
{ 2400, 592, 1189, 1189, 1186, },
|
||||||
{ 1200, 1187, 2379, 2379, 2376, },
|
{ 1200, 1187, 2379, 2379, 2376, },
|
||||||
|
{ 600, 2379, 4759, 4759, 4755, },
|
||||||
{ 300, 4759, 9523, 9523, 9520, },
|
{ 300, 4759, 9523, 9523, 9520, },
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -373,13 +376,15 @@ void SoftwareSerial::setRX(uint8_t rx)
|
|||||||
// Public methods
|
// Public methods
|
||||||
//
|
//
|
||||||
|
|
||||||
void SoftwareSerial::begin(long speed)
|
bool SoftwareSerial::begin(long speed)
|
||||||
{
|
{
|
||||||
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
|
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
|
||||||
|
|
||||||
|
long baud = 0;
|
||||||
|
|
||||||
for (unsigned i=0; i<sizeof(table)/sizeof(table[0]); ++i)
|
for (unsigned i=0; i<sizeof(table)/sizeof(table[0]); ++i)
|
||||||
{
|
{
|
||||||
long baud = pgm_read_dword(&table[i].baud);
|
baud = pgm_read_dword(&table[i].baud);
|
||||||
if (baud == speed)
|
if (baud == speed)
|
||||||
{
|
{
|
||||||
_rx_delay_centering = pgm_read_word(&table[i].rx_delay_centering);
|
_rx_delay_centering = pgm_read_word(&table[i].rx_delay_centering);
|
||||||
@ -389,6 +394,7 @@ void SoftwareSerial::begin(long speed)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (baud != speed) return false;
|
||||||
|
|
||||||
// Set up RX interrupts, but only if we have a valid RX baud rate
|
// Set up RX interrupts, but only if we have a valid RX baud rate
|
||||||
if (_rx_delay_stopbit)
|
if (_rx_delay_stopbit)
|
||||||
@ -407,6 +413,8 @@ void SoftwareSerial::begin(long speed)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
listen();
|
listen();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoftwareSerial::end()
|
void SoftwareSerial::end()
|
||||||
|
@ -82,7 +82,7 @@ public:
|
|||||||
// public methods
|
// public methods
|
||||||
SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false);
|
SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false);
|
||||||
~SoftwareSerial();
|
~SoftwareSerial();
|
||||||
void begin(long speed);
|
bool begin(long speed);
|
||||||
bool listen();
|
bool listen();
|
||||||
void end();
|
void end();
|
||||||
bool isListening() { return this == active_object; }
|
bool isListening() { return this == active_object; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user