概述
这里记录下调试EC20模块的初始化过程。
先看初始化代码:
void EC20_Init(void)
{
printf("ATrn");
delay_ms(500);
strx = strstr((const char *)RxBuffer, (const char *)"OK"); //返回OK
while (strx == NULL)
{
Clear_Buffer();
printf("ATrn");
delay_ms(500);
strx = strstr((const char *)RxBuffer, (const char *)"OK"); //返回OK
}
Clear_Buffer();
printf("AT+QGPS?rn");//查询当前状态
delay_ms(500);
strx = strstr((const char *)RxBuffer, (const char *)"+QGPS: 1"); //返回已经上电
if (strx == NULL) //如果没上电就上电,上电就不要重复上电
printf("AT+QGPS=1rn");//对GNSS上电
delay_ms(500);
printf("ATE1rn"); //关闭回显
delay_ms(500);
Clear_Buffer();
printf("AT+CSQrn"); //检查CSQ
delay_ms(500);
printf("ATIrn"); //检查模块的版本号
delay_ms(500);
/
printf("AT+CPIN?rn");//检查SIM卡是否在位
delay_ms(500);
strx = strstr((const char *)RxBuffer, (const char *)"+CPIN: READY"); //查看是否返回ready
while (strx == NULL)
{
Clear_Buffer();
printf("AT+CPIN?rn");
delay_ms(500);
strx = strstr((const char *)RxBuffer, (const char *)"+CPIN: READY"); //检查SIM卡是否在位,等待卡在位,如果卡识别不到,剩余的工作就没法做了
}
Clear_Buffer();
///
printf("AT+CREG?rn");//查看是否注册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?rn");//查看是否注册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?rn");//查看是否注册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?rn");//查看是否注册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?rn");//查看注册到哪个运营商,支持移动 联通 电信
delay_ms(500);
Clear_Buffer();
printf("AT+QICLOSE=0rn");//关闭socket连接
delay_ms(500);
Clear_Buffer();
printf("AT+QICSGP=1,1, 42CMNET 42, 42 42, 42 42,0rn");//接入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=1rn");//去激活
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=1rn");//激活
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?rn");//获取当前卡的IP地址
delay_ms(500);
Clear_Buffer();
printf("AT+QIOPEN=1,0,"TCP","47.92.146.210",10000,0,1rn");//这里是需要登陆的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, 42CMNET 42, 42 42, 42 42,0rn
配置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,1rn
即可通过CMNET接入点,socket0,本地的任意端口,直接吐出模式建立TCP连接。
最后
以上就是成就航空为你收集整理的EC20 AT调试笔记的全部内容,希望文章能够帮你解决EC20 AT调试笔记所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复