@@ -18,8 +18,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818Implementation of SoftwareSerial Library for Arduino 101
1919
2020CurieSoftwareSerial 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;
5757bool firstStartBit = true ;
5858bool bufferOverflow = true ;
5959bool 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
0 commit comments