E45_TTL_100, Lora transceiver, tested on KL25Z connection with E45 via RS232. Power 100 mW, 868 MHz, range 2 km

Dependencies:   MODSERIAL mbed

Revision:
5:3b737b1cedf5
Parent:
4:1249c317e7f3
--- a/main.cpp	Sun Feb 18 13:33:50 2018 +0000
+++ b/main.cpp	Sun Apr 01 11:48:39 2018 +0000
@@ -1,9 +1,7 @@
 #include "mbed.h"
-#include "MODSERIAL.h"
 #include <string>
 #include <ctype.h>
 
-
 // E45-TTL-100 RADIO------KL25Z
 // AUX--------------------PTD4
 // M1---------------------PTA12
@@ -15,38 +13,30 @@
 // https://quadmeup.com/wp-content/uploads/2017/09/E45-TTL-100_Datasheet_EN_v1.2.pdf
 
 Ticker timer;
-MODSERIAL pc(USBTX, USBRX, 512);    // tx, rx of the pc, (512 char buffer)
-MODSERIAL e45(PTE22, PTE23, 512);   // tx, rx of the E45 radio (512 char buffer)
+Serial pc(USBTX, USBRX);    // tx, rx of the pc
+Serial e45(PTE22, PTE23);   // tx, rx of the E45 radio
+
 InterruptIn aux(PTD4);              // AUX the E45 radio
 DigitalOut m1(PTA12,PullUp);        // M1 the E45 radio
 DigitalOut m0(PTA4, PullUp);        // M0 the E45 radio
-DigitalOut myled(LED_BLUE);         // KL25x BLUE led
+DigitalOut myled(LED_RED);          // KL25Z RED led
 
-int ping=1;      // this number bounces between radios and is incremented
+int ping=1;      // this number bounces between radios 
+bool send_something_flag= 0;         // Send flag
 
 void flank_up()
 {
-    myled=1;    //Rising Edge Detected
+    myled=1;        //Rising Edge Detected
 }
 
 void flank_down()
 {
-    myled=0;    //Falling Edge Detected
+    myled=0;        //Falling Edge Detected
 }
 
-void timer_func()        // Send something every 3 seconds
+void timer_func()   // Send something every 3 seconds
 {
-    if (myled == 1)  {   // AUX is high (Buffer empty), send something
-        wait_ms(3);
-
-        ping++;         // Increase the value
-        e45.printf("%04d\n\r", ping);
-        while(myled==0) {
-            pc.puts("Wait for end Transmission\n\r");
-            wait_ms(1);
-        }
-        pc.printf("\n\rRadio has sent %04d\n\r", ping);
-    }
+    send_something_flag= 1;  // Set the send Flag
 }
 
 int main()
@@ -58,7 +48,7 @@
     pc.baud(115200);
     e45.baud(9600);                         // Default for E45
     e45.format(8, SerialBase::None, 1);     // Default for E45
-    pc.puts("\n\r\nE45-TTL-100 LORA\n\r");
+    pc.printf("\n\r\nE45-TTL-100 LORA\n\r");
 
     aux.rise(&flank_up);       //Service RISING EDGE Interrupt
     aux.fall(&flank_down);     //Service FALLING EDGE Interrupt
@@ -70,7 +60,7 @@
             count++;
             if (count > 2000000) {  //Kill time
                 count=0;
-                pc.puts("Wait for AUX Rising edge ");
+                pc.printf("Wait for AUX Rising edge ");
             }
         }
     }
@@ -79,20 +69,31 @@
     m1= 0;      //Set transparant mode
     wait_ms(1);
 
-    pc.puts("E45 is now ready to send and receive \n\r");
+    pc.printf("E45 is now ready to send and receive \n\r");
     timer.attach(&timer_func, 3.0);
 
     while(1) {
         if (ping>9999) ping=1;
 
+        if (send_something_flag==1) {
+            if (myled == 1)  {   // AUX is high (Buffer empty), send something
+                wait_ms(3);
+                ping++;          // Increase the value
+                e45.printf("%04d\n\r", ping);
+                while(myled==0) {
+                }
+                send_something_flag=0;
+                pc.printf("\n\rRadio has sent %04d\n\r", ping);
+            }
+        }
+
         if (myled == 0)  {      // AUX is low, Chars received
-            //incoming= "";     // Clear the string
+            incoming= "";     // Clear the string
             while(myled==0) {
                 if (e45.readable()) {
                     c=e45.getc();
                     if (isdigit(c))
                         incoming += c;
-                    //pc.putc(c);   //send to pc
                 } else {            // End transmission
                     if (incoming.length()==4) {
                         ping= atoi(incoming.c_str());