Communicates with the WiFi - be very careful when using as it is tempremental.
Dependencies: mbed
main.cpp@0:c600fe917ab1, 2017-05-23 (annotated)
- Committer:
- qdanilc
- Date:
- Tue May 23 16:00:20 2017 +0000
- Revision:
- 0:c600fe917ab1
- Child:
- 1:cd1fe330bc2a
Talks to wifi;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
qdanilc | 0:c600fe917ab1 | 1 | #include "mbed.h" |
qdanilc | 0:c600fe917ab1 | 2 | #include "RawSerial.h" |
qdanilc | 0:c600fe917ab1 | 3 | |
qdanilc | 0:c600fe917ab1 | 4 | |
qdanilc | 0:c600fe917ab1 | 5 | DigitalOut VCCPin (PTC0); //setup the other wifi pins |
qdanilc | 0:c600fe917ab1 | 6 | DigitalOut rstPin (PTC10); |
qdanilc | 0:c600fe917ab1 | 7 | DigitalOut chpdPin (PTC11); |
qdanilc | 0:c600fe917ab1 | 8 | DigitalOut GNDPin (PTC6); |
qdanilc | 0:c600fe917ab1 | 9 | |
qdanilc | 0:c600fe917ab1 | 10 | |
qdanilc | 0:c600fe917ab1 | 11 | RawSerial esp (PTC4, PTC3, 115200); //setup a serial to the Tx = PTC4 and Rx = PTC3 pins at baud rate 115200 |
qdanilc | 0:c600fe917ab1 | 12 | |
qdanilc | 0:c600fe917ab1 | 13 | Serial pc(USBTX, USBRX); |
qdanilc | 0:c600fe917ab1 | 14 | |
qdanilc | 0:c600fe917ab1 | 15 | DigitalOut redLED(LED1); // twp leds |
qdanilc | 0:c600fe917ab1 | 16 | DigitalOut greenLED(LED2); // to allow visual check of bidirectional comms |
qdanilc | 0:c600fe917ab1 | 17 | DigitalOut blueLED(LED3); //to prove it's working |
qdanilc | 0:c600fe917ab1 | 18 | |
qdanilc | 0:c600fe917ab1 | 19 | char input; //character to store inputs/outputs in communication |
qdanilc | 0:c600fe917ab1 | 20 | |
qdanilc | 0:c600fe917ab1 | 21 | |
qdanilc | 0:c600fe917ab1 | 22 | void reset() { //resets the module by turning rst off for 2 seconds then on again |
qdanilc | 0:c600fe917ab1 | 23 | rstPin = 0; |
qdanilc | 0:c600fe917ab1 | 24 | wait(2); |
qdanilc | 0:c600fe917ab1 | 25 | rstPin = 1; |
qdanilc | 0:c600fe917ab1 | 26 | |
qdanilc | 0:c600fe917ab1 | 27 | } |
qdanilc | 0:c600fe917ab1 | 28 | void esp_recv() |
qdanilc | 0:c600fe917ab1 | 29 | { |
qdanilc | 0:c600fe917ab1 | 30 | redLED = !redLED; |
qdanilc | 0:c600fe917ab1 | 31 | while(esp.readable()) { |
qdanilc | 0:c600fe917ab1 | 32 | pc.putc(esp.getc()); |
qdanilc | 0:c600fe917ab1 | 33 | //wait_us(1); |
qdanilc | 0:c600fe917ab1 | 34 | } |
qdanilc | 0:c600fe917ab1 | 35 | } |
qdanilc | 0:c600fe917ab1 | 36 | void pc_recv() |
qdanilc | 0:c600fe917ab1 | 37 | { |
qdanilc | 0:c600fe917ab1 | 38 | char c; |
qdanilc | 0:c600fe917ab1 | 39 | greenLED = !greenLED; |
qdanilc | 0:c600fe917ab1 | 40 | while(pc.readable()) { |
qdanilc | 0:c600fe917ab1 | 41 | c=pc.getc(); |
qdanilc | 0:c600fe917ab1 | 42 | esp.putc(c); |
qdanilc | 0:c600fe917ab1 | 43 | pc.putc(c); // echo back |
qdanilc | 0:c600fe917ab1 | 44 | if(c==13) { |
qdanilc | 0:c600fe917ab1 | 45 | esp.putc(10); // send the linefeed to complement the carriage return generated by return key on the pc |
qdanilc | 0:c600fe917ab1 | 46 | pc.putc(10); |
qdanilc | 0:c600fe917ab1 | 47 | } |
qdanilc | 0:c600fe917ab1 | 48 | } |
qdanilc | 0:c600fe917ab1 | 49 | } |
qdanilc | 0:c600fe917ab1 | 50 | |
qdanilc | 0:c600fe917ab1 | 51 | int main() { |
qdanilc | 0:c600fe917ab1 | 52 | //initialise the pins |
qdanilc | 0:c600fe917ab1 | 53 | |
qdanilc | 0:c600fe917ab1 | 54 | VCCPin = 1; |
qdanilc | 0:c600fe917ab1 | 55 | rstPin = 1; |
qdanilc | 0:c600fe917ab1 | 56 | chpdPin = 1; |
qdanilc | 0:c600fe917ab1 | 57 | GNDPin = 0; |
qdanilc | 0:c600fe917ab1 | 58 | |
qdanilc | 0:c600fe917ab1 | 59 | reset(); //perform an initial reset |
qdanilc | 0:c600fe917ab1 | 60 | |
qdanilc | 0:c600fe917ab1 | 61 | blueLED = 1; //turn on test light |
qdanilc | 0:c600fe917ab1 | 62 | |
qdanilc | 0:c600fe917ab1 | 63 | pc.attach(&pc_recv, Serial::RxIrq); // attach the two interrupt services |
qdanilc | 0:c600fe917ab1 | 64 | esp.attach(&esp_recv, Serial::RxIrq); |
qdanilc | 0:c600fe917ab1 | 65 | |
qdanilc | 0:c600fe917ab1 | 66 | |
qdanilc | 0:c600fe917ab1 | 67 | } |