0

你好,
我們想用手機連Ameba-WiFi做控制,
所以先寫了一支小Sketch測試手機與WiFi連線功能,如下:

#include <WiFi.h>

#define DEBUG 3
#define BUFLEN 256

//-- Ameba Wifi ------------------------------------------------------------------------------------
char ssid[] = "AMEBA_WIFI_TEST";
char pass[] = "12345678";
char channel[] = "6";

WiFiServer WLserver(5001);
WiFiClient WLclient;
IPAddress myIP;

int WLstatus = WL_IDLE_STATUS;
boolean IsWiFiConnected = false; // whether or not the client was connected previously

//----------------------------------------------------------------------------------------------------------------
unsigned char chrRec;

unsigned char RecvString[BUFLEN];
int RecvLen = 0;
boolean IsRecvStrComplete = false;

//----------------------------------------------------------------------------------------------------------------
unsigned long nFetchTime;

//---------------------------------------------------------------------------------------------------------------------------

void setup() {

Serial.begin(9600);
while (!Serial) {
;
}

while ( WLstatus != WL_CONNECTED) {

Serial.print("Attempting to connect to WiFi SSID: ");
Serial.println(ssid);

//WLstatus = WiFi.apbegin(ssid, pass, channel);//Ameba as AP use
WLstatus = WiFi.apbegin(ssid, channel);//換成此無WPA的AP,亦無效

// wait 10 seconds for connection:
delay(10000);// wait 10 second

if( WLstatus == WL_CONNECTED) break;
}

Serial.print("Connected to WiFi SSID: ");
Serial.println(ssid);

WLserver.begin();//Ameba as Server use
myIP = WiFi.localIP();
}

void loop() {

// wait for a new client:
WiFiClient WLclient = WLserver.available();

if (WLclient) {
if (!IsWiFiConnected) {
// clead out the before input buffer:
WLclient.flush();

Serial.println("You have a new client");

IsWiFiConnected = true;
}
if (WLclient.connected()) {
Serial.println("WiF Client Connected");

if(WLclient.available() > 0){
nFetchTime = micros();
Serial.print("Wifi-Rx:[");
}

}

RecvLen = 0;
while (WLclient.connected()){
chrRec = (unsigned char)WLclient.read();
RecvString[RecvLen] = chrRec;

Serial.print(RecvString[RecvLen], HEX);

if ((chrRec == '\n') && (RecvString[RecvLen - 1] == '\r'))
{
IsRecvStrComplete = true;
}

RecvLen++;
RecvString[RecvLen] = '\0'; // Null terminate the string
}
}

delay(1000);
}
上傳後,結果:無法與手機WiFi連線
1.在手機上WiFi列中,無法看到"AMEBA_WIFI_TEST"這個Ameba AP,
2.從Serial-Monitor內容,如下:

<RTL8195A> =========================================================

ROM Version: 0.2

Build ToolChain Version: gcc version 4.8.3 (Realtek ASDK-4.8.3p1 Build 2003)

=========================================================
Check boot type form eFuse
SPI Initial
Image1 length: 0x36cc, Image Addr: 0x10000bc8
Image1 Validate OK, Going jump to Image1
SPI calibration
Find the avaiable window
Baud:2; auto_length:0; Delay start:0; Delay end:63 ===== Enter Image 1 ====
SPI calibration
Find the avaiable window
Baud:1; auto_length:12; Delay start:0; Delay end:63
SDR Controller Init
Test 0: No match addr 0xc9d38 => 0xf != 0xc
Test 0: No match addr 0x1f7c10 => 0x5 != 0xa

load NEW fw 0
Flash Image2:Addr 0xb000, Len 201040, Load to SRAM 0x10006000
Image3 length: 0xbbe0, Image3 Addr: 0x30000000
Img2 Sign: RTKWin, InfaStart @ 0x10006019
===== Enter Image 2 ====
Attempting to connect to WiFi SSID: AMEBA_WIFI_TEST

WIFI is not running
Initializing WIFI ... <--一直卡在這行
--------------------------------------------------------------------------------------------------------------------------

可以看到,一直卡在"Initializing WIFI"這行

可以請各位大大看一下,問題出在哪裡
謝謝~
--------------------------------------------------------------------------------------------------------------------------
使用環境:
開發板: RTL_AMEBA_DEV01_1V0
Arduino IDE: 1.6.8 (換過1.6.7,無效)
Ameba Arduino SDK: 1.0.8 ((換過1.0.7,無效)
DAP Firmware: DAP_FW_Ameba_V10_2_3-2M.bin (直接複製"ram_all.bin"到"MBED"燒錄, 無效)
(換過DAP_FW_Ameba_V8-0-reset.bin,無效 及 換回原始的DAP firmware.bin,無效)
--------------------------------------------------------------------------------------------------------------------------

changson 回答了