Communicates with the WiFi - be very careful when using as it is tempremental.

Dependencies:   mbed

Revision:
1:cd1fe330bc2a
Child:
2:0b9ca0830cd3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/initiateWifi.cpp	Wed May 24 15:42:41 2017 +0000
@@ -0,0 +1,64 @@
+#include "mbed.h"
+#include "RawSerial.h"
+
+    //setup the other wifi pins
+DigitalOut rstPin (PTE29);
+DigitalOut chpdPin (PTE23);
+
+
+RawSerial esp (PTC4, PTC3, 115200); //setup a serial to the  (board) Tx = PTC4 and  Rx = PTC3 pins at baud rate 115200
+
+Serial pc(USBTX, USBRX, 115200);
+
+DigitalOut redLED(LED1); // twp leds  
+DigitalOut greenLED(LED2); // to allow visual check of bidirectional comms
+DigitalOut blueLED(LED3);  //to prove it's working
+
+char input; //character to store inputs/outputs in communication
+
+
+void reset() {   //resets the module by turning rst off for 2 seconds then on again
+    rstPin = 0;
+    wait(2);
+    rstPin = 1;
+    pc.printf("Reset complete\r\n");
+    
+}
+void esp_recv()
+{
+    redLED = !redLED;
+    while(esp.readable()) {
+        pc.putc(esp.getc());
+        //wait_us(1);
+    }
+}
+void pc_recv()
+{
+    char c;
+    greenLED = !greenLED;
+    while(pc.readable()) {
+        c=pc.getc();
+        esp.putc(c);
+        //pc.putc(c); // echo back
+        if(c==13) {
+            esp.putc(10); // send the linefeed to complement the carriage return generated by return key on the pc
+            pc.putc(10); //ie makes enter perform as expected
+        }
+    }
+}
+
+int initiateWifi() {
+    
+    //initialise the pins
+    rstPin = 1;
+    chpdPin = 1;
+    
+    reset();    //perform an initial reset
+    
+    blueLED = 1; //turn on test light
+
+    pc.attach(&pc_recv, Serial::RxIrq); // attach the two interrupt services
+    esp.attach(&esp_recv, Serial::RxIrq);
+    
+
+}
\ No newline at end of file