Skip to content

Commit 3c833b2

Browse files
committed
ATLEDGE-442 Fix some SoftwareSerial Rx limitations
Fixed some limitations for Rx on SOC_GPIO pins. Rx should now be functional on all pins except pin 13.
1 parent 0b100b2 commit 3c833b2

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

libraries/CurieSoftwareSerial/SoftwareSerial.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
Implementation of SoftwareSerial Library for Arduino 101
1919
2020
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
2323
*/
2424

2525
// When set, _DEBUG co-opts pins 11 and 13 for debugging with an
@@ -57,6 +57,7 @@ int initRxCenteringDelay;
5757
bool firstStartBit = true;
5858
bool bufferOverflow = true;
5959
bool invertedLogic = false;
60+
bool isSOCGpio = false;
6061

6162
//
6263
// Debugging
@@ -126,7 +127,7 @@ void SoftwareSerial::recv()
126127
if (invertedLogic ? digitalRead(rxPin) : !digitalRead(rxPin))
127128
{
128129
// The very first start bit the sketch receives takes about 5us longer
129-
if(firstStartBit)
130+
if(firstStartBit && !isSOCGpio)
130131
{
131132
delayTicks(initRxCenteringDelay);
132133
}
@@ -140,7 +141,7 @@ void SoftwareSerial::recv()
140141
// compensate for the centering delay if the ISR was too late and missed the center of the start bit.
141142
if(i == 8)
142143
{
143-
if(firstStartBit)
144+
if(firstStartBit && !isSOCGpio)
144145
{
145146
delayTicks(initRxIntraBitDelay);
146147
}
@@ -175,9 +176,24 @@ void SoftwareSerial::recv()
175176
bufferOverflow = true;
176177
}
177178

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+
}
181197
DebugPulse(_DEBUG_PIN1, 1);
182198
}
183199
interrupts();
@@ -261,7 +277,11 @@ void SoftwareSerial::begin(long speed)
261277
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
262278
//pre-calculate delays
263279
bitDelay = (F_CPU/speed);
264-
280+
PinDescription *p = &g_APinDescription[rxPin];
281+
if (p->ulGPIOType == SOC_GPIO)
282+
{
283+
isSOCGpio = true;
284+
}
265285
//toggling a pin takes about 62 ticks
266286
_tx_delay = bitDelay - 62;
267287
//reading a pin takes about 70 ticks

libraries/CurieSoftwareSerial/SoftwareSerial.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
Implementation of SoftwareSerial Library for Arduino 101
1919
2020
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
2323
*/
2424

2525
#ifndef SoftwareSerial_h

0 commit comments

Comments
 (0)