EC20 AT調試筆記

這裏記錄下調試EC20模塊的初始化過程。
先看初始化代碼:

void  EC20_Init(void)
{
    printf("AT\r\n");
    delay_ms(500);
    strx = strstr((const char *)RxBuffer, (const char *)"OK"); //返回OK
    while (strx == NULL)
    {
        Clear_Buffer();
        printf("AT\r\n");
        delay_ms(500);
        strx = strstr((const char *)RxBuffer, (const char *)"OK"); //返回OK
    }
    Clear_Buffer();
    printf("AT+QGPS?\r\n");//查詢當前狀態
    delay_ms(500);
    strx = strstr((const char *)RxBuffer, (const char *)"+QGPS: 1"); //返回已經上電
    if (strx == NULL) //如果沒上電就上電,上電就不要重複上電
        printf("AT+QGPS=1\r\n");//對GNSS上電
    delay_ms(500);
    printf("ATE1\r\n"); //關閉回顯
    delay_ms(500);
    Clear_Buffer();
    printf("AT+CSQ\r\n"); //檢查CSQ
    delay_ms(500);
    printf("ATI\r\n"); //檢查模塊的版本號
    delay_ms(500);
    /////////////////////////////////
    printf("AT+CPIN?\r\n");//檢查SIM卡是否在位
    delay_ms(500);
    strx = strstr((const char *)RxBuffer, (const char *)"+CPIN: READY"); //查看是否返回ready
    while (strx == NULL)
    {
        Clear_Buffer();
        printf("AT+CPIN?\r\n");
        delay_ms(500);
        strx = strstr((const char *)RxBuffer, (const char *)"+CPIN: READY"); //檢查SIM卡是否在位,等待卡在位,如果卡識別不到,剩餘的工作就沒法做了
    }
    Clear_Buffer();
    ///////////////////////////////////
    printf("AT+CREG?\r\n");//查看是否註冊GSM網絡
    delay_ms(500);
    strx = strstr((const char *)RxBuffer, (const char *)"+CREG: 0,1"); //返回正常
    extstrx = strstr((const char *)RxBuffer, (const char *)"+CREG: 0,5"); //返回正常,漫遊
    while (strx == NULL && extstrx == NULL)
    {
        Clear_Buffer();
        printf("AT+CREG?\r\n");//查看是否註冊GSM網絡
        delay_ms(500);
        strx = strstr((const char *)RxBuffer, (const char *)"+CREG: 0,1"); //返回正常
        extstrx = strstr((const char *)RxBuffer, (const char *)"+CREG: 0,5"); //返回正常,漫遊
    }
    Clear_Buffer();
    /////////////////////////////////////
    printf("AT+CGREG?\r\n");//查看是否註冊GPRS網絡
    delay_ms(500);
    strx = strstr((const char *)RxBuffer, (const char *)"+CGREG: 0,1"); //,這裏重要,只有註冊成功,纔可以進行GPRS數據傳輸。
    extstrx = strstr((const char *)RxBuffer, (const char *)"+CGREG: 0,5"); //返回正常,漫遊
    while (strx == NULL && extstrx == NULL)
    {
        Clear_Buffer();
        printf("AT+CGREG?\r\n");//查看是否註冊GPRS網絡
        delay_ms(500);
        strx = strstr((const char *)RxBuffer, (const char *)"+CGREG: 0,1"); //,這裏重要,只有註冊成功,纔可以進行GPRS數據傳輸。
        extstrx = strstr((const char *)RxBuffer, (const char *)"+CGREG: 0,5"); //返回正常,漫遊
    }
    Clear_Buffer();
    printf("AT+COPS?\r\n");//查看註冊到哪個運營商,支持移動 聯通 電信
    delay_ms(500);
    Clear_Buffer();
    printf("AT+QICLOSE=0\r\n");//關閉socket連接
    delay_ms(500);
    Clear_Buffer();
    printf("AT+QICSGP=1,1,\042CMNET\042,\042\042,\042\042,0\r\n");//接入APN,無用戶名和密碼
    delay_ms(500);
    strx = strstr((const char *)RxBuffer, (const char *)"OK"); //開啓成功
    while (strx == NULL)
    {
        delay_ms(500);
        strx = strstr((const char *)RxBuffer, (const char *)"OK"); ////開啓成功
    }
    Clear_Buffer();
    printf("AT+QIDEACT=1\r\n");//去激活
    delay_ms(500);
    strx = strstr((const char *)RxBuffer, (const char *)"OK"); //開啓成功
    while (strx == NULL)
    {
        delay_ms(500);
        strx = strstr((const char *)RxBuffer, (const char *)"OK"); //開啓成功
    }
    Clear_Buffer();
    printf("AT+QIACT=1\r\n");//激活
    delay_ms(500);
    strx = strstr((const char *)RxBuffer, (const char *)"OK"); //開啓成功
    while (strx == NULL)
    {
        delay_ms(500);
        strx = strstr((const char *)RxBuffer, (const char *)"OK"); //開啓成功
    }
    Clear_Buffer();
    printf("AT+QIACT?\r\n");//獲取當前卡的IP地址
    delay_ms(500);
    Clear_Buffer();
    printf("AT+QIOPEN=1,0,\"TCP\",\"47.92.146.210\",10000,0,1\r\n");//這裏是需要登陸的IP號碼,採用直接吐出模式
    delay_ms(500);
    strx = strstr((const char *)RxBuffer, (const char *)"+QIOPEN: 0,0"); //檢查是否登陸成功
    while (strx == NULL)
    {
        strx = strstr((const char *)RxBuffer, (const char *)"+QIOPEN: 0,0"); //檢查是否登陸成功
        delay_ms(100);

    }
    delay_ms(500);
    Clear_Buffer();
}

這是串口助手抓到的EC20模塊返回來的數據:

RDY

OK

+QGPS: 0

OK

OK

OK
AT+CSQ
+CSQ: 99,99

OK
ATI
Quectel
EC20F
Revision: EC20CEFILGR06A05M1G

OK
AT+CPIN?
+CPIN: READY

OK
AT+CREG?
+CREG: 0,2

****************
此處包含無數條重複的,可能是因爲第一次開機,
OK
AT+CREG?
+CREG: 0,2
****************

OK
AT+CREG?
+CREG: 0,2

OK
AT+CREG?
+CREG: 0,1

OK
AT+CGREG?
+CGREG: 0,1

OK
AT+COPS?
+COPS: 0,0,"CHINA MOBILE",7

OK
AT+QICLOSE=0
OK
AT+QICSGP=1,1,"CMNET","","",0
OK
AT+QIDEACT=1
OK
AT+QIACT=1
OK
AT+QIACT?
+QIACT: 1,1,1,"10.104.80.212"

OK
AT+QIOPEN=1,0,"TCP","47.92.146.210",10000,0,1
OK

+QIOPEN: 0,0

以下是參考移遠的手冊,截取的關於上述使用的指令的說明:

AT+QGPS Operate GPS Session

Turn on GNSS engine, current <gnssmode> only supports Standalone GNSS. When <fixcount> is 0, GNSS engine will position continuously, you can terminate the session by AT+QGPSEND. When <fixcount> is not 0, and the actual fix times reach to the specified value, GNSS engine will terminate automatically.
在這裏插入圖片描述
在這裏插入圖片描述
這裏用到了GNSS的狀態查詢AT+QGPS?,因爲多次上電會報錯,所以先查詢內部GPS開啓情況,再開啓。

AT+CSQ Signal Quality Report

AT+CSQ indicates the received signal strength <rssi> and the channel bit error rate <ber>.
在這裏插入圖片描述
在這裏插入圖片描述
這個指令聽說是用來查詢信號強度和誤碼率,這裏可能是因爲還未註冊,所以返回的都是99。

ATI Display Product Identification Information

The ATI command delivers a product information text.
在這裏插入圖片描述
這個指令用於查詢模塊的版本型號。

AT+CPIN Enter PIN

AT+CPIN is used to enter a password or query whether or not the module requires a password which is necessary before it can be operated (SIM PIN, SIM PUK, PH-SIM PIN, etc.).
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
這個指令用於查詢SIM卡的密碼類型。實際測試,如果沒有插卡,會返回如下消息,所以這個指令可以用來檢測SIM卡是否存在。

AT+CPIN?
+CME ERROR: 10

AT+CREG Network Registration

AT+CREG returns the network registration status. The write command sets whether or not to present URC.

在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
手冊上這裏區分了CDMA和非CDMA,博主對這一塊不太熟悉,但是看後面的參數,好像CDMA包含了非CDMA的各種情況。

n 含義
0 關閉網絡註冊的主動上報結果碼
1 打開網絡註冊的主動上報結果碼
2 打開網絡註冊和位置信息的主動上報結果碼
stat 含義 CDMA支持
0 未註冊,終端當前並未在搜尋新的運營商 支持
1 已註冊本地網絡 支持
2 未註冊,終端正在搜尋基站 支持
3 註冊被拒絕 不支持
4 未知錯誤 不支持
5 已註冊,註冊到漫遊網絡 不支持

這裏需要關注的是1和5兩種情況。

AT+CGREG Network Registration Status

The AT+CGREG command queries the network registration status and controls the presentation of an unsolicited result code +CGREG: <stat> when <n>=1 and there is a change in the MT‟s GPRS network registration status in GERAN/UTRAN, or unsolicited result code +CGREG: <stat>[,[<lac>],[<ci>],[<Act> ],[<rac>]] when <n>=2 and there is a change of the network cell in GERAN/UTRAN
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
這個指令和上面的指令差不多,但前者是僅註冊網絡,後者註冊是GPRS或者4G上網功能;個人理解就是第一個註冊成功了之後手機上可以顯示中國移動,第二個註冊成功了手機上會有4G的圖標。

AT+COPS Operator Selection

AT+COPS returns the current operators and their status and allows to set automatic or manual network selection.
在這裏插入圖片描述
在這裏插入圖片描述
這個指令用於查詢運營商,如+COPS: 0,0,"CHINA MOBILE",7代表自動註冊,GB2312類型的運營商,中國移動“CHINA MOBILE”,E-UTRAN代表4G接入。

AT+QICLOSE Close Socket Service

Close the specified socket service by AT+QICLOSE. Depending on the Network, it will take at most 10 seconds (default value, host could modify the time with <timeout>) to return OK or ERROR after executing AT+QICLOSE. Before the response is returned, other AT commands cannot be executed.
在這裏插入圖片描述
在這裏插入圖片描述
指令用於關閉socket連接。

AT+QICSGP Configure Context

Configure the <APN>, <username>, <password> and other contexts by AT+QICSGP. The QoS of the context can be configured by AT+CGQMIN, AT+CGEQMIN, AT+CGQREQ and AT+CGEQREQ.
在這裏插入圖片描述
在這裏插入圖片描述
這裏通過AT+QICSGP=1,1,\042CMNET\042,\042\042,\042\042,0\r\n配置1號接入點爲CMNET進行聯網。

AT+QIDEACT Deactivate PDP Context

AT+QIDEACT will deactivate the specific context <contextID> and close all TCPIP connections set up in this context. Depending on the Network, it may take at most 40 seconds to return OK or ERROR after executing AT+QIDEACT. Before the response is returned, other AT commands cannot be executed

在這裏插入圖片描述
AT+QIDEACT=1將CMNET上的所有連接全部斷開。

AT+QIACT Activate PDP Context

Before activating context by AT+QIACT, host should configure the context by AT+QICSGP. After activation, the IP address can be queried by AT+QIACT?. The range of <contextID> is 1-16, but the maximum number of context which can be activated at the same time is 3. Depending on the Network, it may take at most 150 seconds to return OK or ERROR after executing AT+QIACT. Before the response is returned, other AT commands cannot be executed.
在這裏插入圖片描述
在這裏插入圖片描述
AT+QIACT=1將激活接入點CMNET,允許連接。
AT+QIACT?指令還可以查詢獲取的IP地址。

AT+QIOPEN Start Socket Service

Start a socket service by AT+QIOPEN. The service type can be specified by the parameter <service_type>. The data access mode (buffer access mode, direct push access mode and transparent access mode) can be specified by parameter <access_mode>. The URC “+QIOPEN” indicates whether the socket service is started successfully.
在這裏插入圖片描述
在這裏插入圖片描述
通過AT+QIOPEN=1,0,\"TCP\",\"47.92.146.210\",10000,0,1\r\n即可通過CMNET接入點,socket0,本地的任意端口,直接吐出模式建立TCP連接。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章