Gerrit Pathuis / Mbed 2 deprecated E45_TTL_100

Dependencies:   MODSERIAL mbed

Committer:
GerritPathuis
Date:
Sat Feb 17 10:10:11 2018 +0000
Revision:
2:329d3f88af27
Parent:
1:2b8fa0144c4f
Child:
3:19a244789b2b
Works

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GerritPathuis 0:16ba41275340 1 #include "mbed.h"
GerritPathuis 1:2b8fa0144c4f 2 #include "MODSERIAL.h"
GerritPathuis 0:16ba41275340 3
GerritPathuis 0:16ba41275340 4 // E45-TTL-100 RADIO------KL25Z
GerritPathuis 0:16ba41275340 5 // AUX--------------------PTD4
GerritPathuis 0:16ba41275340 6 // M1---------------------PTA12
GerritPathuis 0:16ba41275340 7 // M0---------------------PTA4
GerritPathuis 0:16ba41275340 8 // RXD--------------------PTE22(TX)
GerritPathuis 0:16ba41275340 9 // TXD--------------------PTE23(RX)
GerritPathuis 1:2b8fa0144c4f 10 // LORA Radio Transmits @ 868 mHz
GerritPathuis 2:329d3f88af27 11 // Expected range 2000m
GerritPathuis 2:329d3f88af27 12 // https://quadmeup.com/wp-content/uploads/2017/09/E45-TTL-100_Datasheet_EN_v1.2.pdf
GerritPathuis 0:16ba41275340 13
GerritPathuis 1:2b8fa0144c4f 14 Ticker timer;
GerritPathuis 2:329d3f88af27 15 MODSERIAL pc(USBTX, USBRX, 512); // tx, rx of the pc, (512 char buffer)
GerritPathuis 2:329d3f88af27 16 MODSERIAL e45(PTE22, PTE23, 512); // tx, rx of the E45 radio (512 char buffer)
GerritPathuis 0:16ba41275340 17 InterruptIn aux(PTD4); // AUX the E45 radio
GerritPathuis 0:16ba41275340 18 DigitalOut m1(PTA12,PullUp); // M1 the E45 radio
GerritPathuis 0:16ba41275340 19 DigitalOut m0(PTA4, PullUp); // M0 the E45 radio
GerritPathuis 0:16ba41275340 20 DigitalOut myled(LED1); // Kl25x led1
GerritPathuis 0:16ba41275340 21
GerritPathuis 0:16ba41275340 22
GerritPathuis 0:16ba41275340 23 void flank_up()
GerritPathuis 0:16ba41275340 24 {
GerritPathuis 0:16ba41275340 25 myled=1; //Rising Edge Detected
GerritPathuis 0:16ba41275340 26 }
GerritPathuis 0:16ba41275340 27
GerritPathuis 0:16ba41275340 28 void flank_down()
GerritPathuis 0:16ba41275340 29 {
GerritPathuis 0:16ba41275340 30 myled=0; //Falling Edge Detected
GerritPathuis 0:16ba41275340 31 }
GerritPathuis 0:16ba41275340 32
GerritPathuis 1:2b8fa0144c4f 33 void timer_func() // Send something every 3s
GerritPathuis 1:2b8fa0144c4f 34 {
GerritPathuis 1:2b8fa0144c4f 35 if (myled == 1) { // AUX is high (Buffer empty), send something
GerritPathuis 1:2b8fa0144c4f 36 wait_ms(3);
GerritPathuis 1:2b8fa0144c4f 37 e45.puts("123");
GerritPathuis 1:2b8fa0144c4f 38 while(myled==0) {
GerritPathuis 1:2b8fa0144c4f 39 pc.puts("Wait for end Transmission\n\r");
GerritPathuis 1:2b8fa0144c4f 40 wait_ms(1);
GerritPathuis 1:2b8fa0144c4f 41 }
GerritPathuis 2:329d3f88af27 42 pc.puts("\n\rRadio has sent 123\n\r");
GerritPathuis 1:2b8fa0144c4f 43 }
GerritPathuis 1:2b8fa0144c4f 44 }
GerritPathuis 1:2b8fa0144c4f 45
GerritPathuis 1:2b8fa0144c4f 46
GerritPathuis 0:16ba41275340 47 int main()
GerritPathuis 0:16ba41275340 48 {
GerritPathuis 1:2b8fa0144c4f 49 pc.baud(115200);
GerritPathuis 1:2b8fa0144c4f 50 e45.baud(9600);
GerritPathuis 2:329d3f88af27 51 pc.puts("\n\r\nE45-TTL-100 LORA\n\r");
GerritPathuis 0:16ba41275340 52
GerritPathuis 0:16ba41275340 53 aux.rise(&flank_up); //Service RISING EDGE Interrupt
GerritPathuis 0:16ba41275340 54 aux.fall(&flank_down); //Service FALLING EDGE Interrupt
GerritPathuis 0:16ba41275340 55
GerritPathuis 2:329d3f88af27 56 // select mode
GerritPathuis 2:329d3f88af27 57 // Transparant Transmission
GerritPathuis 0:16ba41275340 58 m0= 0;
GerritPathuis 0:16ba41275340 59 m1= 0;
GerritPathuis 2:329d3f88af27 60 wait_ms(1);
GerritPathuis 0:16ba41275340 61
GerritPathuis 1:2b8fa0144c4f 62 // wait for E45 to be ready
GerritPathuis 0:16ba41275340 63 while(myled==0) {
GerritPathuis 1:2b8fa0144c4f 64 pc.puts("Wait for E45 reset\n\r");
GerritPathuis 2:329d3f88af27 65 wait_ms(20);
GerritPathuis 0:16ba41275340 66 }
GerritPathuis 1:2b8fa0144c4f 67 wait_ms(2);
GerritPathuis 1:2b8fa0144c4f 68 timer.attach(&timer_func, 3.0);
GerritPathuis 1:2b8fa0144c4f 69 pc.puts("E45 is now ready to send and receive \n\r");
GerritPathuis 0:16ba41275340 70
GerritPathuis 0:16ba41275340 71 while(1) {
GerritPathuis 1:2b8fa0144c4f 72 if (myled == 0) { // AUX is low, Chars received
GerritPathuis 1:2b8fa0144c4f 73 wait_ms(3);
GerritPathuis 1:2b8fa0144c4f 74 while(myled==0) {
GerritPathuis 1:2b8fa0144c4f 75 if (e45.readable()) {
GerritPathuis 1:2b8fa0144c4f 76 pc.putc(e45.getc()); //send to pc
GerritPathuis 1:2b8fa0144c4f 77 }
GerritPathuis 1:2b8fa0144c4f 78 }
GerritPathuis 0:16ba41275340 79 }
GerritPathuis 0:16ba41275340 80 }
GerritPathuis 0:16ba41275340 81 }