WIFI

Dependencies:   mbed

Fork of SerialPassthroughcjsESP8266 by chris stevens

Committer:
cstevens
Date:
Wed Jun 08 09:14:56 2016 +0000
Revision:
8:34cc66421054
Parent:
7:d78ed22a787d
Child:
9:b1344ca3497d
Commented version with some work done to try to get it working on the kl25z.... not really successful yet

Who changed what in which revision?

UserRevisionLine numberNew 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
cstevens 7:d78ed22a787d 10 RawSerial dev(p28,p27); // 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
cstevens 8:34cc66421054 13 DigitalOut rst(p26); // 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());
sam_grove 5:96cb82af9996 22 }
sam_grove 5:96cb82af9996 23 }
cstevens 7:d78ed22a787d 24 // subroutine to service the serial interrupt on the pc connection
cstevens 7:d78ed22a787d 25 // 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 26 // the esp should echo these straight back to the the pc if all is well
cstevens 7:d78ed22a787d 27 // 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 28 void pc_recv()
sam_grove 5:96cb82af9996 29 {
cstevens 6:dc4c165f6b53 30 char c;
sam_grove 5:96cb82af9996 31 led4 = !led4;
sam_grove 5:96cb82af9996 32 while(pc.readable()) {
cstevens 6:dc4c165f6b53 33 c=pc.getc();
cstevens 6:dc4c165f6b53 34 dev.putc(c);
cstevens 6:dc4c165f6b53 35 //pc.putc(c); // echo back
cstevens 7:d78ed22a787d 36 if(c==13) {dev.putc(10); // send the linefeed to complement the carriage return generated by return key on the pc
cstevens 6:dc4c165f6b53 37 pc.putc(10);
cstevens 6:dc4c165f6b53 38 }
mbedAustin 0:59bec1fd956e 39 }
mbedAustin 0:59bec1fd956e 40 }
mbedAustin 4:ba9100d52e48 41
mbedAustin 4:ba9100d52e48 42 int main()
mbedAustin 4:ba9100d52e48 43 {
cstevens 6:dc4c165f6b53 44 rst=0;
cstevens 6:dc4c165f6b53 45 wait(1);
cstevens 8:34cc66421054 46 rst=1; // send the esp8266 reset
cstevens 6:dc4c165f6b53 47 wait(1);
cstevens 8:34cc66421054 48 pc.printf("ok off we go....\n\r");
cstevens 8:34cc66421054 49
cstevens 8:34cc66421054 50 pc.baud(115200); // NB maybe this should go before this
cstevens 6:dc4c165f6b53 51 dev.baud(115200);
mbedAustin 4:ba9100d52e48 52
cstevens 8:34cc66421054 53 pc.attach(&pc_recv, Serial::RxIrq); // attach the two interrupt services
sam_grove 5:96cb82af9996 54 dev.attach(&dev_recv, Serial::RxIrq);
cstevens 6:dc4c165f6b53 55
cstevens 6:dc4c165f6b53 56
sam_grove 5:96cb82af9996 57
mbedAustin 4:ba9100d52e48 58 while(1) {
cstevens 8:34cc66421054 59 sleep(); // so for KL25z this is probably wrong.... but not yet tested 07-06-2016
mbedAustin 4:ba9100d52e48 60 }
mbedAustin 4:ba9100d52e48 61 }