@@ -18,8 +18,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
18
Implementation of SoftwareSerial Library for Arduino 101
19
19
20
20
CurieSoftwareSerial library is a work in progress
21
- Currently only 38400 and 57600 bps is the supported baud rate for RX
22
- RX is only fully functional on pins 2, 4, 7, 8, 10, 11, 12.
21
+ Rx is only functional up to 57600 bps
22
+ Rx does not work for pin 13
23
23
*/
24
24
25
25
// When set, _DEBUG co-opts pins 11 and 13 for debugging with an
@@ -57,6 +57,7 @@ int initRxCenteringDelay;
57
57
bool firstStartBit = true ;
58
58
bool bufferOverflow = true ;
59
59
bool invertedLogic = false ;
60
+ bool isSOCGpio = false ;
60
61
61
62
//
62
63
// Debugging
@@ -126,7 +127,7 @@ void SoftwareSerial::recv()
126
127
if (invertedLogic ? digitalRead (rxPin) : !digitalRead (rxPin))
127
128
{
128
129
// The very first start bit the sketch receives takes about 5us longer
129
- if (firstStartBit)
130
+ if (firstStartBit && !isSOCGpio )
130
131
{
131
132
delayTicks (initRxCenteringDelay);
132
133
}
@@ -140,7 +141,7 @@ void SoftwareSerial::recv()
140
141
// compensate for the centering delay if the ISR was too late and missed the center of the start bit.
141
142
if (i == 8 )
142
143
{
143
- if (firstStartBit)
144
+ if (firstStartBit && !isSOCGpio )
144
145
{
145
146
delayTicks (initRxIntraBitDelay);
146
147
}
@@ -175,9 +176,24 @@ void SoftwareSerial::recv()
175
176
bufferOverflow = true ;
176
177
}
177
178
178
- // skip the stop bit/s
179
- // TODO: tweak this value depending on which gpio is used
180
- delayTicks (bitDelay >> 2 );
179
+ // wait until we see a stop bit/s or timeout;
180
+ uint8_t loopTimeout = 8 ;
181
+ if (invertedLogic)
182
+ {
183
+ while (digitalRead (rxPin) && (loopTimeout >0 ))
184
+ {
185
+ delayTicks (bitDelay >> 4 );
186
+ loopTimeout--;
187
+ }
188
+ }
189
+ else
190
+ {
191
+ while (!digitalRead (rxPin) && (loopTimeout >0 ))
192
+ {
193
+ delayTicks (bitDelay >> 4 );
194
+ loopTimeout--;
195
+ }
196
+ }
181
197
DebugPulse (_DEBUG_PIN1, 1 );
182
198
}
183
199
interrupts ();
@@ -261,7 +277,11 @@ void SoftwareSerial::begin(long speed)
261
277
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0 ;
262
278
// pre-calculate delays
263
279
bitDelay = (F_CPU/speed);
264
-
280
+ PinDescription *p = &g_APinDescription[rxPin];
281
+ if (p->ulGPIOType == SOC_GPIO)
282
+ {
283
+ isSOCGpio = true ;
284
+ }
265
285
// toggling a pin takes about 62 ticks
266
286
_tx_delay = bitDelay - 62 ;
267
287
// reading a pin takes about 70 ticks
0 commit comments