Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include <string> 00003 #include <ctype.h> 00004 00005 // E45-TTL-100 RADIO------KL25Z 00006 // AUX--------------------PTD4 00007 // M1---------------------PTA12 00008 // M0---------------------PTA4 00009 // RXD--------------------PTE22(TX) 00010 // TXD--------------------PTE23(RX) 00011 // LORA Radio Transmits @ 868 mHz 00012 // Expected range 2000m 00013 // https://quadmeup.com/wp-content/uploads/2017/09/E45-TTL-100_Datasheet_EN_v1.2.pdf 00014 00015 Ticker timer; 00016 Serial pc(USBTX, USBRX); // tx, rx of the pc 00017 Serial e45(PTE22, PTE23); // tx, rx of the E45 radio 00018 00019 InterruptIn aux(PTD4); // AUX the E45 radio 00020 DigitalOut m1(PTA12,PullUp); // M1 the E45 radio 00021 DigitalOut m0(PTA4, PullUp); // M0 the E45 radio 00022 DigitalOut myled(LED_RED); // KL25Z RED led 00023 00024 int ping=1; // this number bounces between radios 00025 bool send_something_flag= 0; // Send flag 00026 00027 void flank_up() 00028 { 00029 myled=1; //Rising Edge Detected 00030 } 00031 00032 void flank_down() 00033 { 00034 myled=0; //Falling Edge Detected 00035 } 00036 00037 void timer_func() // Send something every 3 seconds 00038 { 00039 send_something_flag= 1; // Set the send Flag 00040 } 00041 00042 int main() 00043 { 00044 int count=0; 00045 string incoming; 00046 char c; 00047 00048 pc.baud(115200); 00049 e45.baud(9600); // Default for E45 00050 e45.format(8, SerialBase::None, 1); // Default for E45 00051 pc.printf("\n\r\nE45-TTL-100 LORA\n\r"); 00052 00053 aux.rise(&flank_up); //Service RISING EDGE Interrupt 00054 aux.fall(&flank_down); //Service FALLING EDGE Interrupt 00055 00056 // select mode 00057 // Transparant Transmission 00058 if (myled ==1) { //Check ready or not 00059 while(myled==0) { //Wait when not yet ready 00060 count++; 00061 if (count > 2000000) { //Kill time 00062 count=0; 00063 pc.printf("Wait for AUX Rising edge "); 00064 } 00065 } 00066 } 00067 wait_ms(2); 00068 m0= 0; //Set transparant mode 00069 m1= 0; //Set transparant mode 00070 wait_ms(1); 00071 00072 pc.printf("E45 is now ready to send and receive \n\r"); 00073 timer.attach(&timer_func, 3.0); 00074 00075 while(1) { 00076 if (ping>9999) ping=1; 00077 00078 if (send_something_flag==1) { 00079 if (myled == 1) { // AUX is high (Buffer empty), send something 00080 wait_ms(3); 00081 ping++; // Increase the value 00082 e45.printf("%04d\n\r", ping); 00083 while(myled==0) { 00084 } 00085 send_something_flag=0; 00086 pc.printf("\n\rRadio has sent %04d\n\r", ping); 00087 } 00088 } 00089 00090 if (myled == 0) { // AUX is low, Chars received 00091 incoming= ""; // Clear the string 00092 while(myled==0) { 00093 if (e45.readable()) { 00094 c=e45.getc(); 00095 if (isdigit(c)) 00096 incoming += c; 00097 } else { // End transmission 00098 if (incoming.length()==4) { 00099 ping= atoi(incoming.c_str()); 00100 pc.printf("incoming value %4d \n\r", ping); 00101 incoming= ""; // Clear the string 00102 } 00103 } 00104 } 00105 } 00106 } 00107 }
Generated on Tue Jul 19 2022 04:52:33 by
1.7.2