Software serial, for when you are out of serial pins

Dependents:   BufferedSoftSerial neurGAI_Seeed_BLUETOOTH LPC-SD-35 ESP-WROOM-02_test ... more

Revision:
10:236fce2e5b8c
Parent:
6:517082212c00
--- a/SoftSerial_rx.cpp	Sat Jul 05 08:07:49 2014 +0000
+++ b/SoftSerial_rx.cpp	Sat Jul 05 13:22:43 2014 +0000
@@ -1,5 +1,7 @@
 #include "SoftSerial.h"
 
+uint32_t overhead_us = 200 * 1000000 / SystemCoreClock;         //Random estimation of the overhead of mbed libs, makes slow devices like LPC812 @ 12MHz perform better
+
 int SoftSerial::_getc( void ) {
     while(!readable());
     out_valid = false;
@@ -13,18 +15,20 @@
 //Start receiving byte
 void SoftSerial::rx_gpio_irq_handler(void) {
     rxticker.prime();
-    rxticker.setNext(bit_period + (bit_period >> 1));
+    rxticker.setNext(bit_period + (bit_period >> 1) - overhead_us);
     rx->fall(NULL);
     rx_bit = 0;
     rx_error = false;
 };    
 
 void SoftSerial::rx_handler(void) {
+    //Receive data
+    int val = rx->read();
+ 
     rxticker.setNext(bit_period);
     rx_bit++;
     
-    //Receive data
-    int val = rx->read();
+    
     if (rx_bit <= _bits) {
         read_buffer |= val << (rx_bit - 1);
         return;