MBED wifi code from oxford repo
Dependencies: mbed
Fork of SerialPassthroughcjsESP8266 by
main.cpp@10:146515fc16f7, 2016-06-14 (annotated)
- Committer:
- muyiq
- Date:
- Tue Jun 14 14:32:35 2016 +0000
- Revision:
- 10:146515fc16f7
- Parent:
- 9:b1344ca3497d
HI ED HERE IS THE MBED WIFI CODE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cstevens | 7:d78ed22a787d | 1 | /* Simpler prog based on the serial passthrough code to enable a command line driven test of esp8266 |
cstevens | 7:d78ed22a787d | 2 | * wifi modules. |
cstevens | 7:d78ed22a787d | 3 | * NB this uses the mbed sleep() command to form a low power system but on some MCUs this is a problem |
cstevens | 7:d78ed22a787d | 4 | * this works fine on an lpc1768 but not as yet on the KL25Z |
cstevens | 7:d78ed22a787d | 5 | */ |
mbedAustin | 0:59bec1fd956e | 6 | #include "mbed.h" |
mbedAustin | 2:a8dcb07a1d00 | 7 | |
cstevens | 7:d78ed22a787d | 8 | RawSerial pc(USBTX, USBRX); // serial terminal for the pc connection |
cstevens | 8:34cc66421054 | 9 | //RawSerial dev(PTE0,PTE1); // for KL25Z... asuming one can't use the PTA1 version which is the stdio |
muyiq | 10:146515fc16f7 | 10 | RawSerial dev(PTE22,PTE23); // serial uart for connecting to the esp8266 tx,rx NB mbed tx must connect ot esp rx and vice versa |
cstevens | 7:d78ed22a787d | 11 | DigitalOut led1(LED1); // twp leds |
cstevens | 7:d78ed22a787d | 12 | DigitalOut led4(LED4); // to allow visual check of bidirectional comms |
muyiq | 10:146515fc16f7 | 13 | DigitalOut rst(A0); // single digital pin to drive the esp8266 reset line |
mbedAustin | 2:a8dcb07a1d00 | 14 | |
cstevens | 7:d78ed22a787d | 15 | // subroutine to run anytime a serial interrupt arrives from the device |
cstevens | 7:d78ed22a787d | 16 | // this basically passes everything thatthe device produces on to the pc terminal screen |
sam_grove | 5:96cb82af9996 | 17 | void dev_recv() |
mbedAustin | 2:a8dcb07a1d00 | 18 | { |
sam_grove | 5:96cb82af9996 | 19 | led1 = !led1; |
sam_grove | 5:96cb82af9996 | 20 | while(dev.readable()) { |
sam_grove | 5:96cb82af9996 | 21 | pc.putc(dev.getc()); |
cstevens | 9:b1344ca3497d | 22 | //wait_us(1); |
sam_grove | 5:96cb82af9996 | 23 | } |
sam_grove | 5:96cb82af9996 | 24 | } |
cstevens | 7:d78ed22a787d | 25 | // subroutine to service the serial interrupt on the pc connection |
cstevens | 7:d78ed22a787d | 26 | // this is a bit more complex - it takes what the use sends on the pc and copies it on to the device |
cstevens | 7:d78ed22a787d | 27 | // the esp should echo these straight back to the the pc if all is well |
cstevens | 7:d78ed22a787d | 28 | // this also detects the end of command character which is ascii 13 (0x0d) adn adds a linefeed after it =asscii 10 (0x0a) |
sam_grove | 5:96cb82af9996 | 29 | void pc_recv() |
sam_grove | 5:96cb82af9996 | 30 | { |
cstevens | 6:dc4c165f6b53 | 31 | char c; |
sam_grove | 5:96cb82af9996 | 32 | led4 = !led4; |
sam_grove | 5:96cb82af9996 | 33 | while(pc.readable()) { |
cstevens | 6:dc4c165f6b53 | 34 | c=pc.getc(); |
cstevens | 6:dc4c165f6b53 | 35 | dev.putc(c); |
cstevens | 6:dc4c165f6b53 | 36 | //pc.putc(c); // echo back |
cstevens | 7:d78ed22a787d | 37 | if(c==13) {dev.putc(10); // send the linefeed to complement the carriage return generated by return key on the pc |
cstevens | 6:dc4c165f6b53 | 38 | pc.putc(10); |
cstevens | 6:dc4c165f6b53 | 39 | } |
mbedAustin | 0:59bec1fd956e | 40 | } |
mbedAustin | 0:59bec1fd956e | 41 | } |
mbedAustin | 4:ba9100d52e48 | 42 | |
mbedAustin | 4:ba9100d52e48 | 43 | int main() |
mbedAustin | 4:ba9100d52e48 | 44 | { |
cstevens | 6:dc4c165f6b53 | 45 | rst=0; |
cstevens | 6:dc4c165f6b53 | 46 | wait(1); |
cstevens | 8:34cc66421054 | 47 | rst=1; // send the esp8266 reset |
cstevens | 6:dc4c165f6b53 | 48 | wait(1); |
cstevens | 8:34cc66421054 | 49 | pc.printf("ok off we go....\n\r"); |
cstevens | 8:34cc66421054 | 50 | |
cstevens | 8:34cc66421054 | 51 | pc.baud(115200); // NB maybe this should go before this |
cstevens | 6:dc4c165f6b53 | 52 | dev.baud(115200); |
mbedAustin | 4:ba9100d52e48 | 53 | |
cstevens | 8:34cc66421054 | 54 | pc.attach(&pc_recv, Serial::RxIrq); // attach the two interrupt services |
sam_grove | 5:96cb82af9996 | 55 | dev.attach(&dev_recv, Serial::RxIrq); |
cstevens | 6:dc4c165f6b53 | 56 | |
cstevens | 6:dc4c165f6b53 | 57 | |
cstevens | 9:b1344ca3497d | 58 | int i=0; |
mbedAustin | 4:ba9100d52e48 | 59 | while(1) { |
cstevens | 9:b1344ca3497d | 60 | |
cstevens | 9:b1344ca3497d | 61 | (i++)%10; // THIS USED TO BE A SLEEP COMMAND BUT IT WAS CAUSING SOME TROUBLE. |
mbedAustin | 4:ba9100d52e48 | 62 | } |
mbedAustin | 4:ba9100d52e48 | 63 | } |