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.
Diff: main.cpp
- Revision:
- 1:2b8fa0144c4f
- Parent:
- 0:16ba41275340
- Child:
- 2:329d3f88af27
diff -r 16ba41275340 -r 2b8fa0144c4f main.cpp
--- a/main.cpp Sun Feb 11 19:24:21 2018 +0000
+++ b/main.cpp Sat Feb 17 09:44:56 2018 +0000
@@ -1,4 +1,5 @@
#include "mbed.h"
+#include "MODSERIAL.h"
// E45-TTL-100 RADIO------KL25Z
// AUX--------------------PTD4
@@ -6,10 +7,11 @@
// M0---------------------PTA4
// RXD--------------------PTE22(TX)
// TXD--------------------PTE23(RX)
-// Radio Transmits @ 868 mHz
+// LORA Radio Transmits @ 868 mHz
-Serial pc(USBTX, USBRX, 115200); // tx, rx of the pc
-Serial e45(PTE22, PTE23, 9600); // tx, rx of the E45 radio
+Ticker timer;
+MODSERIAL pc(USBTX, USBRX, 512); // tx, rx of the pc
+MODSERIAL e45(PTE22, PTE23, 512); // 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
@@ -19,17 +21,32 @@
void flank_up()
{
myled=1; //Rising Edge Detected
- pc.puts("myled=1\n\r");
}
void flank_down()
{
myled=0; //Falling Edge Detected
- pc.puts("myled=0\n\r");
}
+void timer_func() // Send something every 3s
+{
+ //pc.puts("Try to send\n\r");
+ if (myled == 1) { // AUX is high (Buffer empty), send something
+ wait_ms(3);
+ e45.puts("123");
+ while(myled==0) {
+ pc.puts("Wait for end Transmission\n\r");
+ wait_ms(1);
+ }
+ pc.puts("Radio has sent 123\n\r");
+ }
+}
+
+
int main()
{
+ pc.baud(115200);
+ e45.baud(9600);
pc.puts("\n\r\nE45-TTL-100 LORA test \n\r");
aux.rise(&flank_up); //Service RISING EDGE Interrupt
@@ -39,22 +56,24 @@
m0= 0;
m1= 0;
+ // wait for E45 to be ready
while(myled==0) {
- pc.puts("Wait for Rising edge\n\r");
- wait(0.2);
+ pc.puts("Wait for E45 reset\n\r");
+ wait_ms(1);
}
- pc.puts("E45 is now ready \n\r");
+ wait_ms(2);
+ timer.attach(&timer_func, 3.0);
+ pc.puts("E45 is now ready to send and receive \n\r");
while(1) {
-
// indicate status aux
- if (myled == 0) { //Status not ready
- pc.puts("Kill time \n\r");
- wait(0.2); //Kill time
- } else {
- wait_ms(2);
- e45.puts("Hello world\n\r"); //
- pc.puts("Radio has sent Hello World\n\r");
+ if (myled == 0) { // AUX is low, Chars received
+ wait_ms(3);
+ while(myled==0) {
+ if (e45.readable()) {
+ pc.putc(e45.getc()); //send to pc
+ }
+ }
}
}
}