我使用 RTL8722 做一個資料傳輸的實驗,環境是用 Arduino IDE + SDK 3.1.0。從PC建立一個TCP連線,發送資料到 RTL8722,收到的資料發給UART,然後經過 HS_UART0 loopback to LP_UART (PA21–PA25, PA22–PA26),再將資料透過網路回傳PC。實驗過程,發現網路傳輸資料一段時間後就會掉封包或連線中斷,實驗的程式碼如下:
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); // UART_LOG (PA7,PA8)
Serial1.begin(115200); // HS_UART0 (PA21,PA22)
Serial2.begin(115200); // LP_UART (PA26,PA25)
}
void loop()
{
bool bShowIP = false;
uint8_t data, rxNet[MY_BUF_SIZE];
IPAddress ip;
int len;
char* password = "password";
WiFiClient myData;
char* ssid = "ASUS";
WiFi.begin(ssid, password);
vTaskDelay(100);
svrData.begin();
for ( ; ; )
{
while (WiFi.status() != WL_CONNECTED) {
bShowIP = false;
vTaskDelay(500);
}
if( !bShowIP ) {
bShowIP = true;
ip = WiFi.localIP();
}
myData = svrData.available(); // listen for incoming clients
while (myData.connected()) {
len = 0;
while (myData.available()) {
rxNet[len++] = myData.read();
}
if (len > 0) {
// Serial.print("FromWifi:");
// Serial.println(len);
Serial1.write(rxNet, len);
Serial1.flush();
}
vTaskDelay(2);
len = 0;
while (Serial2.available()) {
rxNet[len++] = Serial2.read();
}
if (len > 0) {
// Serial.print("FromSerial:");
// Serial.println(len);
Serial2.write(rxNet, len);
Serial2.flush();
myData.write(rxNet, len); // send to wifi
myData.flush();
}
len = 0;
while (Serial1.available()) {
rxNet[len++] = Serial1.read();
}
}
vTaskDelay(25);
}
}