Software serial, for when you are out of serial pins

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

Revision:
3:7238e9bb74d2
Parent:
1:f8b4b764ace7
Child:
4:c010265ed202
--- a/SoftSerial_rx.cpp	Sat Apr 26 16:21:42 2014 +0000
+++ b/SoftSerial_rx.cpp	Sat Apr 26 16:35:20 2014 +0000
@@ -12,15 +12,17 @@
 
 //Start receiving byte
 void SoftSerial::rx_gpio_irq_handler(void) {
+    rxout.attach_us(this, &SoftSerial::rx_handler, bit_period + (bit_period >> 1));   //Start reading first data byte
     rx->fall(NULL);
     rx_bit = 0;
     rx_error = false;
-    rxout.attach_us(this, &SoftSerial::rx_handler, bit_period + (bit_period >> 1));   //Start reading first data byte
 };    
 
 void SoftSerial::rx_handler(void) {
+    if (!rx_bit)
+        rxticker.attach_us(this, &SoftSerial::rx_handler, bit_period); 
+        
     rx_bit++;
-    rxout.attach_us(this, &SoftSerial::rx_handler, bit_period); 
     
     //Receive data
     int val = rx->read();
@@ -72,7 +74,7 @@
         out_buffer = read_buffer;
     }
     read_buffer = 0;
-    rxout.detach(); 
+    rxticker.detach(); 
     rx->fall(this, &SoftSerial::rx_gpio_irq_handler);
 }