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连接。

  • 6
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值