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@1:2b8fa0144c4f, 2018-02-17 (annotated)
- Committer:
- GerritPathuis
- Date:
- Sat Feb 17 09:44:56 2018 +0000
- Revision:
- 1:2b8fa0144c4f
- Parent:
- 0:16ba41275340
- Child:
- 2:329d3f88af27
This seems to work better
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 | 0:16ba41275340 | 11 | |
| GerritPathuis | 1:2b8fa0144c4f | 12 | Ticker timer; |
| GerritPathuis | 1:2b8fa0144c4f | 13 | MODSERIAL pc(USBTX, USBRX, 512); // tx, rx of the pc |
| GerritPathuis | 1:2b8fa0144c4f | 14 | MODSERIAL e45(PTE22, PTE23, 512); // tx, rx of the E45 radio |
| GerritPathuis | 0:16ba41275340 | 15 | InterruptIn aux(PTD4); // AUX the E45 radio |
| GerritPathuis | 0:16ba41275340 | 16 | DigitalOut m1(PTA12,PullUp); // M1 the E45 radio |
| GerritPathuis | 0:16ba41275340 | 17 | DigitalOut m0(PTA4, PullUp); // M0 the E45 radio |
| GerritPathuis | 0:16ba41275340 | 18 | DigitalOut myled(LED1); // Kl25x led1 |
| GerritPathuis | 0:16ba41275340 | 19 | |
| GerritPathuis | 0:16ba41275340 | 20 | |
| GerritPathuis | 0:16ba41275340 | 21 | void flank_up() |
| GerritPathuis | 0:16ba41275340 | 22 | { |
| GerritPathuis | 0:16ba41275340 | 23 | myled=1; //Rising Edge Detected |
| GerritPathuis | 0:16ba41275340 | 24 | } |
| GerritPathuis | 0:16ba41275340 | 25 | |
| GerritPathuis | 0:16ba41275340 | 26 | void flank_down() |
| GerritPathuis | 0:16ba41275340 | 27 | { |
| GerritPathuis | 0:16ba41275340 | 28 | myled=0; //Falling Edge Detected |
| GerritPathuis | 0:16ba41275340 | 29 | } |
| GerritPathuis | 0:16ba41275340 | 30 | |
| GerritPathuis | 1:2b8fa0144c4f | 31 | void timer_func() // Send something every 3s |
| GerritPathuis | 1:2b8fa0144c4f | 32 | { |
| GerritPathuis | 1:2b8fa0144c4f | 33 | //pc.puts("Try to send\n\r"); |
| GerritPathuis | 1:2b8fa0144c4f | 34 | if (myled == 1) { // AUX is high (Buffer empty), send something |
| GerritPathuis | 1:2b8fa0144c4f | 35 | wait_ms(3); |
| GerritPathuis | 1:2b8fa0144c4f | 36 | e45.puts("123"); |
| GerritPathuis | 1:2b8fa0144c4f | 37 | while(myled==0) { |
| GerritPathuis | 1:2b8fa0144c4f | 38 | pc.puts("Wait for end Transmission\n\r"); |
| GerritPathuis | 1:2b8fa0144c4f | 39 | wait_ms(1); |
| GerritPathuis | 1:2b8fa0144c4f | 40 | } |
| GerritPathuis | 1:2b8fa0144c4f | 41 | pc.puts("Radio has sent 123\n\r"); |
| GerritPathuis | 1:2b8fa0144c4f | 42 | } |
| GerritPathuis | 1:2b8fa0144c4f | 43 | } |
| GerritPathuis | 1:2b8fa0144c4f | 44 | |
| GerritPathuis | 1:2b8fa0144c4f | 45 | |
| GerritPathuis | 0:16ba41275340 | 46 | int main() |
| GerritPathuis | 0:16ba41275340 | 47 | { |
| GerritPathuis | 1:2b8fa0144c4f | 48 | pc.baud(115200); |
| GerritPathuis | 1:2b8fa0144c4f | 49 | e45.baud(9600); |
| GerritPathuis | 0:16ba41275340 | 50 | pc.puts("\n\r\nE45-TTL-100 LORA test \n\r"); |
| GerritPathuis | 0:16ba41275340 | 51 | |
| GerritPathuis | 0:16ba41275340 | 52 | aux.rise(&flank_up); //Service RISING EDGE Interrupt |
| GerritPathuis | 0:16ba41275340 | 53 | aux.fall(&flank_down); //Service FALLING EDGE Interrupt |
| GerritPathuis | 0:16ba41275340 | 54 | |
| GerritPathuis | 0:16ba41275340 | 55 | // set mode, Transmission open |
| GerritPathuis | 0:16ba41275340 | 56 | m0= 0; |
| GerritPathuis | 0:16ba41275340 | 57 | m1= 0; |
| GerritPathuis | 0:16ba41275340 | 58 | |
| GerritPathuis | 1:2b8fa0144c4f | 59 | // wait for E45 to be ready |
| GerritPathuis | 0:16ba41275340 | 60 | while(myled==0) { |
| GerritPathuis | 1:2b8fa0144c4f | 61 | pc.puts("Wait for E45 reset\n\r"); |
| GerritPathuis | 1:2b8fa0144c4f | 62 | wait_ms(1); |
| GerritPathuis | 0:16ba41275340 | 63 | } |
| GerritPathuis | 1:2b8fa0144c4f | 64 | wait_ms(2); |
| GerritPathuis | 1:2b8fa0144c4f | 65 | timer.attach(&timer_func, 3.0); |
| GerritPathuis | 1:2b8fa0144c4f | 66 | pc.puts("E45 is now ready to send and receive \n\r"); |
| GerritPathuis | 0:16ba41275340 | 67 | |
| GerritPathuis | 0:16ba41275340 | 68 | while(1) { |
| GerritPathuis | 0:16ba41275340 | 69 | // indicate status aux |
| GerritPathuis | 1:2b8fa0144c4f | 70 | if (myled == 0) { // AUX is low, Chars received |
| GerritPathuis | 1:2b8fa0144c4f | 71 | wait_ms(3); |
| GerritPathuis | 1:2b8fa0144c4f | 72 | while(myled==0) { |
| GerritPathuis | 1:2b8fa0144c4f | 73 | if (e45.readable()) { |
| GerritPathuis | 1:2b8fa0144c4f | 74 | pc.putc(e45.getc()); //send to pc |
| GerritPathuis | 1:2b8fa0144c4f | 75 | } |
| GerritPathuis | 1:2b8fa0144c4f | 76 | } |
| GerritPathuis | 0:16ba41275340 | 77 | } |
| GerritPathuis | 0:16ba41275340 | 78 | } |
| GerritPathuis | 0:16ba41275340 | 79 | } |