//-------------------ESP8266_Init -------------- // initializes the module as a client // Inputs: baud rate: tested with 9600 and 115200 // Outputs: none void ESP8266_Init(uint32_t baud){ ESP8266_InitUART(baud,true); // baud rate, no echo to UART0 ESP8266_EnableRXInterrupt(); SearchLooking = false; SearchFound = false; ServerResponseSearchLooking = 0; // not looking for "+IPD" ServerResponseSearchFinished = 0; EnableInterrupts(); // step 1: AT+RST reset module printf("ESP8266 Initialization:\n\r"); ESP8266_EchoResponse = true; // debugging if(ESP8266_Reset()==0){ printf("Reset failure, could not reset\n\r"); ErrorScreenInit(1); while(1){}; } // ESP8266SendCommand("AT+UART_CUR=115200,8,1,0,0\r\n"); // UART_InChar(); // ESP8266_InitUART(115200,true); // step 2: AT+CWMODE=1 set wifi mode to AP mode (host) if(ESP8266_SetWifiMode(3)==0){ printf("SetWifiMode, could not set mode2\n\r"); ErrorScreenInit(2); while(1){}; } // step 3: AT+CWJAP="ValvanoAP","12345678" connect to access point if(ESP8266_JoinAccessPoint(SSID_NAME,PASSKEY)==0){ printf("JoinAccessPoint error, could not join AP\n\r"); ErrorScreenInit(3); while(1){}; } // optional step: AT+CIFSR check to see our IP address // if(ESP8266_GetIPAddress()==0){ // data streamed to UART0, OK // printf("GetIPAddress error, could not get IP address\n\r"); while(1){}; // } //// optional step: AT+CIPMUX==0 set mode to single socket // if(ESP8266_SetConnectionMux(0)==0){ // single socket // printf("SetConnectionMux error, could not set connection mux\n\r"); while(1){}; // } // optional step: AT+CWLAP check to see other AP in area // if(ESP8266_ListAccessPoints()==0){ // printf("ListAccessPoints, could not list access points\n\r"); while(1){}; // } // step 4: AT+CIPMODE=0 set mode to not data mode if(ESP8266_SetDataTransmissionMode(0)==0){ printf("SetDataTransmissionMode, could not make connection\n\r"); ErrorScreenInit(4); while(1){}; } ESP8266_InputProcessingEnabled = false; // not a server }
int main2(void){ char data; DisableInterrupts(); PLL_Init(Bus80MHz); // LED_Init(); Output_Init(); // UART0 as a terminal printf("\n\r-----------\n\rSystem starting at 9600 baud...\n\r"); ESP8266_InitUART(9600,true); ESP8266_EnableRXInterrupt(); EnableInterrupts(); ESP8266SendCommand("AT+RST\r\n"); data = UART_InChar(); while(1){ // echo data back and forth data = UART_InCharNonBlock(); if(data){ ESP8266_PrintChar(data); } } }