E45_TTL_100, Lora transceiver, tested on KL25Z connection with E45 via RS232. Power 100 mW, 868 MHz, range 2 km
main.cpp@3:19a244789b2b, 2018-02-17 (annotated)
- Committer:
- GerritPathuis
- Date:
- Sat Feb 17 16:24:58 2018 +0000
- Revision:
- 3:19a244789b2b
- Parent:
- 2:329d3f88af27
- Child:
- 4:1249c317e7f3
Waits replaced by loops
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:19a244789b2b | 20 | DigitalOut myled(LED_BLUE); // KL25x BLUE led |
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 | 3:19a244789b2b | 33 | void timer_func() // Send something every 3 seconds |
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 | 0:16ba41275340 | 46 | int main() |
GerritPathuis | 0:16ba41275340 | 47 | { |
GerritPathuis | 3:19a244789b2b | 48 | int count=0; |
GerritPathuis | 3:19a244789b2b | 49 | |
GerritPathuis | 1:2b8fa0144c4f | 50 | pc.baud(115200); |
GerritPathuis | 3:19a244789b2b | 51 | e45.baud(9600); // Default for E45 |
GerritPathuis | 3:19a244789b2b | 52 | e45.format(8, SerialBase::None, 1); // Default for E45 |
GerritPathuis | 2:329d3f88af27 | 53 | pc.puts("\n\r\nE45-TTL-100 LORA\n\r"); |
GerritPathuis | 0:16ba41275340 | 54 | |
GerritPathuis | 0:16ba41275340 | 55 | aux.rise(&flank_up); //Service RISING EDGE Interrupt |
GerritPathuis | 0:16ba41275340 | 56 | aux.fall(&flank_down); //Service FALLING EDGE Interrupt |
GerritPathuis | 0:16ba41275340 | 57 | |
GerritPathuis | 2:329d3f88af27 | 58 | // select mode |
GerritPathuis | 2:329d3f88af27 | 59 | // Transparant Transmission |
GerritPathuis | 3:19a244789b2b | 60 | if (myled ==1) { //Check ready or not |
GerritPathuis | 3:19a244789b2b | 61 | while(myled==0) { //Wait when not yet ready |
GerritPathuis | 3:19a244789b2b | 62 | count++; |
GerritPathuis | 3:19a244789b2b | 63 | if (count > 2000000) { |
GerritPathuis | 3:19a244789b2b | 64 | count=0; |
GerritPathuis | 3:19a244789b2b | 65 | pc.puts("Wait for AUX Rising edge "); |
GerritPathuis | 3:19a244789b2b | 66 | } |
GerritPathuis | 3:19a244789b2b | 67 | } |
GerritPathuis | 3:19a244789b2b | 68 | } |
GerritPathuis | 3:19a244789b2b | 69 | wait_ms(2); |
GerritPathuis | 3:19a244789b2b | 70 | m0= 0; //Set transparant mode |
GerritPathuis | 3:19a244789b2b | 71 | m1= 0; //Set transparant mode |
GerritPathuis | 2:329d3f88af27 | 72 | wait_ms(1); |
GerritPathuis | 0:16ba41275340 | 73 | |
GerritPathuis | 3:19a244789b2b | 74 | pc.puts("E45 is now ready to send and receive \n\r"); |
GerritPathuis | 1:2b8fa0144c4f | 75 | timer.attach(&timer_func, 3.0); |
GerritPathuis | 0:16ba41275340 | 76 | |
GerritPathuis | 0:16ba41275340 | 77 | while(1) { |
GerritPathuis | 1:2b8fa0144c4f | 78 | if (myled == 0) { // AUX is low, Chars received |
GerritPathuis | 1:2b8fa0144c4f | 79 | while(myled==0) { |
GerritPathuis | 1:2b8fa0144c4f | 80 | if (e45.readable()) { |
GerritPathuis | 1:2b8fa0144c4f | 81 | pc.putc(e45.getc()); //send to pc |
GerritPathuis | 1:2b8fa0144c4f | 82 | } |
GerritPathuis | 1:2b8fa0144c4f | 83 | } |
GerritPathuis | 0:16ba41275340 | 84 | } |
GerritPathuis | 0:16ba41275340 | 85 | } |
GerritPathuis | 0:16ba41275340 | 86 | } |
GerritPathuis | 3:19a244789b2b | 87 |