当前位置:网站首页>Ec20/ec25 4G module at instruction development summary
Ec20/ec25 4G module at instruction development summary
2022-07-28 11:03:00 【tutu-hu】
List of articles
One .EC25/20 4G Module introduction
EC25 It is a series of with diversity receiving function LTE-FDD/LTE-TDD/WCDMA/GSM Wireless communication module .
1. Power supply :
VBAT Supply voltage range :3.3V~4.3V
Typical supply voltage :3.8V
2. Network protocol characteristics :
Support TCP/UDP/PPP/FTP/FTPS/HTTP/HTTPS/NTP/PING/
QMI/NITZ/SMTP/SSL/MQTT/CMUX/SMTPS/MMS*/FILE* agreement
Support PAP (Password Authentication Protocol) and CHAP (Challenge Handshake Authentication Protocol) agreement .
3. Main serial port :
be used for AT Command transmission and data transmission .
The maximum baud rate is 921600bps, The default is 115200bps( It can be done by AT Instruction configuration modifies baud rate ).
Support RTS and CTS Hardware flow control .
4. Switch on and reset :
Turn it on : You can pull it down PWRKEY At least 500ms Turn on the module .
To turn it off : adopt PWRKEY Pin control module shutdown .
send out AT+QPOWD Command shutdown .
Reset :RESET_N Pin can be used for module reset . Pull it down RESET_N Pin 150ms~460ms After that, the module can be reset .
Two .AT Summary of instructions
1. Universal AT Instructions
AT: Test instruction , return OK.
ATE0: Close back display , return OK.
AT+CCLK?: Get network time , See the reference manual for the return format .( Note that the time returned here is the local time of the base station , You may need to convert it to Beijing time )
AT+QCCID: obtain SIM Card number . See the reference manual for the return format .
AT+CSQ: Get the signal strength , return 0-31, return 99 For no signal .
AT+QPOWD: Module shutdown .
2. establish TCP/UDP Connection correlation AT Instructions
AT+CPIN?: Judge SIM Whether the state is normal , Normal return READY.
AT+CREG?: Check whether the network registration is successful , Successfully returns OK.
AT+QICSGP=1,1,“MOBILE”,"","",1: To configure TCP/IP Environmental Science , Successfully returns OK.
AT+QIACT=1: Activate TCP/IP Environmental Science , Successfully returns OK.
AT+QIOPEN=1,0,“TCP”,“ip”,port,0,2: establish TCP Connect ( Passthrough mode ), among ip and port Replace with the actual network value to be connected . Connection successful return CONNECT.( So far, we have established TCP Connect , Data can be transmitted directly )
AT+QIOPEN=1,2,“UDP SERVICE”,“127.0.0.1”,0,3030,1: establish UDP The server . Successfully returns OK.( So far, it has not been established UDP Connect , You can't send data )
AT+QISEND=2,len,“ip”,port :UDP Prepare to send data instructions , The length of data sent here len, Purpose ip Address and port number port It should be given according to the actual , received ">" Then send the data , Sent successfully received SEND OK.
+++ : sign out TCP Passthrough mode ( Exit transparent transmission after sending data ).
AT+QICLOSE=0/2 : Close the connection ( Here 0/2 Is the connection number , By the previous AT+QIOPEN Command on ).
3、 ... and .TCP Data transmission process
1.POWERKEY Turn it on ----->2. Module networking ----->3. establish TCP Connect ----->4.TCP send data ----->5. Wait for the data to be returned and processed ----->6. Module shutdown (POWERKEY or AT Instructions ).
Detailed procedure :
Related support functions :
// A serial port 1,printf function
// Ensure that no more than... Data is sent at one time USART1_MAX_SEND_LEN byte
void fg_printf(char* fmt,...)
{
u16 i=0;
va_list ap;
va_start(ap,fmt);
vsprintf((char*)USART1_TX_BUF,fmt,ap);
va_end(ap);
i=strlen((const char*)USART1_TX_BUF);// The length of the data sent this time
/* Use serial port register operation to send data */
// for(j=0;j<i;j++)// Loop data
// {
// while((USART1->ISR&0X40)==0); // Cycle to send , Until it's sent
// USART1->TDR=USART1_TX_BUF[j];
// }
/* Serial port is adopted HAL Library functions send data */
// HAL_UART_Transmit(&huart1, (uint8_t*)USART1_TX_BUF,i, 1000); // Send received data
// while(__HAL_UART_GET_FLAG(&huart1, UART_FLAG_TC) != SET); // Wait for the end of sending
/* use DMA Send data by */
HAL_USART1_DMA_TX(&USART1TxDMA_Handler,DMA_FLAG_TC2,&huart1,USART1_TX_BUF,i);// Use DMA send data
memset(USART1_TX_BUF,0,sizeof(USART1_TX_BUF));// Empty cache
}
//4G_MODULE After sending the order , Detect the received response
//str: Expected response results
// Return value :0, Did not get the expected response results
// other , Where to expect the response result (str The location of )
u8* fg_send_check_cmd(u8 *str)
{
char *strx=0;
USART1_RX_BUF[USART1_RX_COUNT]=0;// Add Terminator
strx=strstr((const char*)USART1_RX_BUF,(const char*)str);
return (u8*)strx;
}
// towards 4G_MODULE Send the specified data
//data: Data sent ( There is no need to add carriage return )
//ack: Expected response results , If it is empty , It means that there is no need to wait for a response
//waittime: Waiting time ( Company :100ms)
// Return value :0, Send successfully ( Got the expected response results )
// 1, fail in send
u8 fg_send_cmd(u8 *data,u8 *ack,u16 waittime)
{
waittime=waittime*100;
fg_printf("%s\r\n",data); // What needs to be sent is the command
if(ack&&waittime) // Need to wait for a response
{
while(--waittime) // Wait for the countdown
{
delay_ms(1);
if(USART1_IDLE_FLAG) // Received the expected response result
{
if(fg_send_check_cmd(ack))
{
printf("%s ack: %s\r\n",data,(u8*)ack);
memset(USART1_RX_BUF,0,sizeof(USART1_RX_BUF));// Empty USART1 cache
USART1_IDLE_FLAG=0;
USART1_RX_COUNT=0; // A serial port 1 Accept data reset
return 0; //ack correct , return 1
}
memset(USART1_RX_BUF,0,sizeof(USART1_RX_BUF));// Empty USART1 cache
USART1_IDLE_FLAG=0;
USART1_RX_COUNT=0;// A serial port 1 Accept data reset
}
}
}
return 1; //ack error , return 0
}
//1.4G Turn it on
void FourG_Power_On(void)
{
POWERKEY(1);
delay_ms(600);
POWERKEY(0);
}
//2. Module networking
/** * @brief 4G Module networking * * @param void * * @return 0: Successful connection * 1: The connection fails */
u8 FourG_Connect_To_Internet(void)
{
u8 i=0;
for(i=0;i<3;i++)
if(fg_send_cmd((u8 *)"AT",(u8 *)"OK",100)==0)break;
if(i==3)
{
printf(" Module status is abnormal ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf(" The module status is normal ...\r\n\r\n");
for(i=0;i<3;i++)
if(fg_send_cmd((u8 *)"ATE0",(u8 *)"OK",100)==0)break;
if(i==3)
{
printf(" Failed to close echo ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf(" Closing echo succeeded ...\r\n\r\n");
for(i=0;i<3;i++)
if(fg_send_cmd((u8 *)"AT+CPIN?",(u8 *)"READY",10)==0)break;
if(i==3)
{
printf("SIM Card status is abnormal ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf("SIM The card status is normal ...\r\n\r\n");
for(i=0;i<3;i++)
if(fg_send_cmd((u8 *)"AT+CREG?",(u8 *)"OK",10)==0)break;
if(i==3)
{
printf("CS Network registration failed ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf("CS Network registration successful ...\r\n\r\n");
return 0;
}
//3. establish TCP Connect
/** * @brief 4G Module building TCP Connect * * @param ip: Need to connect ip Address * port: Port to be connected * * @return 0: establish TCP Successful connection * 1: establish TCP The connection fails */
u8 FG_TCP_Connect(const u8* ip,const u8* port)
{
u8 i=0;
char p[50]={
0};
for(i=0;i<3;i++)
if(fg_send_cmd((u8 *)"AT+QICSGP=1,1,\"MOBILE\",\"\",\"\",1",(u8 *)"OK",10)==0)break;
if(i==3)
{
printf(" To configure TCP/IP Environment failure ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf(" To configure TCP/IP Environment success ...\r\n\r\n");
for(i=0;i<3;i++)
if(fg_send_cmd((u8 *)"AT+QIACT=1",(u8 *)"OK",10)==0)break;
if(i==3)
{
printf(" Activate TCP/IP Environment failure ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf(" Activate TCP/IP Environment success ...\r\n\r\n");
sprintf((char*)p,"AT+QIOPEN=1,0,\"TCP\",\"%s\",%s,0,2",ip,port);
for(i=0;i<3;i++)
if(fg_send_cmd((u8 *)p,(u8 *)"CONNECT",10)==0)break;
if(i==3)
{
printf(" Set up TCP Transparent mode failed ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf(" Set up TCP Transparent mode succeeded ...\r\n\r\n");
return 0; // success , return 0
}
//4.TCP send data
/** * @brief TCP send data * * @param data: Data sent * len: Length of data sent * * @return void */
void FG_TCP_Send_Data(u8* data,u16 len)
{
/* use DMA Send data by */
HexArrayToString(data,(char*)USART1_TX_BUF,len); // First, convert the original data into a string
HAL_USART1_DMA_TX(&USART1TxDMA_Handler,DMA_FLAG_TC2,&huart1,USART1_TX_BUF,2*len);// Use DMA send data
memset(USART1_TX_BUF,0,sizeof(USART1_TX_BUF)); // Empty cache
}
//5. Wait for the data to be returned and processed ( Part of the code )
if(USART1_IDLE_FLAG) // A serial port 1 Receiving data is over , And NB Module communication
{
for(i=0;i<USART1_RX_COUNT;i++) // Print out the received data
printf("%x ",USART1_RX_BUF[i]);
printf("\r\n");
memset(USART1_RX_BUF,0,sizeof(USART1_RX_BUF)); // Empty cache , For the next use
USART1_RX_COUNT=0; // Clear the number of bytes accepted
USART1_IDLE_FLAG=0; // Idle interrupt flag reset
}
//6. Module shutdown
//4G To turn it off
void FourG_Power_Off(void)
{
POWERKEY(1);
delay_ms(600);
POWERKEY(0);
// fg_printf("AT+QPOWD\r\n"); // Send shutdown command
}
EC20/25 4G The default serial port baud rate of the module is 115200, Sometimes you need to modify the baud rate , Function as follows :
/** * @brief FG Module set baud rate * * @param void * * @return 0: Set up the success * 1: Setup failed */
u8 FourG_SET_Bund(void)
{
u8 i=0;
for(i=0;i<3;i++)
if(fg_send_cmd((u8 *)"AT",(u8 *)"OK",100)==0)break;
if(i==3)
{
printf(" Module status is abnormal ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf(" The module status is normal ...\r\n\r\n");
for(i=0;i<3;i++)
if(fg_send_cmd((u8 *)"AT+IPR=9600;&W",(u8 *)"OK",50)==0)break; // Set the baud rate to 9600 And permanently stored in the module , The baud rate here can be modified as needed
if(i==3)
{
printf(" Set up 9600 Baud rate failed ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf(" Set up 9600 Baud rate succeeded ...\r\n\r\n");
return 0;
}
Four .UDP Data transmission process
1.POWERKEY Turn it on ----->2. Module networking ----->3. establish UDP Connect ----->4.UDP send data ----->5. Wait for the data to be returned and processed ----->6. Module shutdown (POWERKEY or AT Instructions ).
Detailed procedure :
// Related support functions : ditto TCP
//1.4G Turn it on : ditto TCP
//2. Module networking : ditto TCP
//3. establish UDP Connect
/** * @brief 4G establish UDP Connect * * @param ip: Need to connect ip Address * port: Port to be connected * socket: After the connection is successful, the created socket value * * @return 0:UDP Successful connection * 1:UDP The connection fails */
u8 FG_UDP_Connect(void)
{
u8 i=0;
for(i=0;i<3;i++)
if(fg_send_cmd((u8 *)"AT+QICSGP=1,1,\"MOBILE\",\"\",\"\",1",(u8 *)"OK",10)==0)break;
if(i==3)
{
printf(" To configure TCP/IP Environment failure ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf(" To configure TCP/IP Environment success ...\r\n\r\n");
for(i=0;i<3;i++)
if(fg_send_cmd((u8 *)"AT+QIACT=1",(u8 *)"OK",10)==0)break;
if(i==3)
{
printf(" Activate TCP/IP Environment failure ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf(" Activate TCP/IP Environment success ...\r\n\r\n");
for(i=0;i<3;i++)
if(fg_send_cmd((u8 *)"AT+QIOPEN=1,2,\"UDP SERVICE\",\"127.0.0.1\",0,3030,1",(u8 *)"OK",10)==0)break;
if(i==3)
{
printf(" Set up UDP Transparent mode failed ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf(" Set up UDP Transparent mode succeeded ...\r\n\r\n");
return 0; // success , return 0
}
//4.UDP send data
/** * @brief UDP send data * * @param ip:ip Address * port: Port number * data: Data sent * len: Length of data sent * * @return 0:UDP Send successfully * 1:UDP fail in send */
u8 FG_UDP_Send_Data(const u8* ip,const u8* port,u8* data,u16 len)
{
u8 i=0;
u16 waittime=1000;
char p[50]={
0};
sprintf((char*)p,"AT+QISEND=2,%d,\"%s\",%s",2*len,ip,port);
for(i=0;i<3;i++)
if(fg_send_cmd((u8 *)p,(u8 *)">",10)==0)break;
if(i==3)
{
printf(" Have not received > Failed to send data ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf(" Acknowledge receipt of > Start sending data ....\r\n\r\n");
/* use DMA Send data by */
HexArrayToString(data,(char*)USART1_TX_BUF,len); // First, convert the original data into a string
HAL_USART1_DMA_TX(&USART1TxDMA_Handler,DMA_FLAG_TC2,&huart1,USART1_TX_BUF,2*len);// Use DMA send data
memset(USART1_TX_BUF,0,sizeof(USART1_TX_BUF)); // Empty cache
while(--waittime) // Wait for the countdown
{
delay_ms(1);
if(USART1_IDLE_FLAG) // Received the expected response result
{
if(fg_send_check_cmd((u8 *)"SEND OK"))
{
printf("ack: %s\r\n",(u8*)"SEND OK");
memset(USART1_RX_BUF,0,sizeof(USART1_RX_BUF));// Empty USART1 cache
USART1_IDLE_FLAG=0;
USART1_RX_COUNT=0; // A serial port 1 Accept data reset
return 0; //ack correct , return 0
}
memset(USART1_RX_BUF,0,sizeof(USART1_RX_BUF));// Empty USART1 cache
USART1_IDLE_FLAG=0;
USART1_RX_COUNT=0; // A serial port 1 Accept data reset
}
}
return 1; //ack error , return 1
}
//5. Wait for the data to be returned and processed , because UDP Not through transmission mode , Therefore, we need to process the most received data , You can deal with it yourself
if(USART1_IDLE_FLAG) // A serial port 1 Receiving data is over , And NB Module communication
{
received_length=0;
printf(" The received UDP The data is :%s\r\n",USART1_RX_BUF);
/* Determine whether there is data from the server */
str1=fg_send_check_cmd(portnum); // Judge whether the received data is +NSONMI:
str2=str1+portlen+2; // Get the first address of the data area
while(str2!=&USART1_RX_BUF[USART1_RX_COUNT-2]) // Not to the penultimate
{
str2++; // Receive buffer goes down one position
received_length++; // Number of bytes received plus one
if(received_length>180)break; // If the received data is greater than 180, Then it is judged that the reception is wrong , sign out while() loop
}
printf("received_length=%d\r\n",received_length);
memmove(USART1_RX_BUF,str1+portlen+2,received_length);
USART1_RX_COUNT=received_length;
USART1_RX_BUF[USART1_RX_COUNT]=0;
for(i=0;i<USART1_RX_COUNT;i++)
printf("%x ",USART1_RX_BUF[i]);
printf("\r\n");
}
//6. Module shutdown : ditto TCP
5、 ... and . summary
4G As the mainstream communication mode nowadays, communication has a very wide range of applications , Moving away from the company's EC20/25 As the mainstream 4G Communication modules are widely used , In addition, this module also has many other powerful functions , Such as low power consumption mode ,GNSS Positioning function , You can develop it yourself .TCP/UDP As a mainstream transmission protocol , This article provides a detailed development process , As a reference .
边栏推荐
- Semeval 2022 | introducing knowledge into ner system, aridamo academy won the best paper award
- Make a virtual human with zego avatar | virtual anchor live broadcast solution
- 内存操作函数memcpy()和memmove()的用法
- The 10th Landbridge cup embedded electronic provincial competition
- GKNoiseSource
- GKVoronoiNoiseSource
- Do data analysis, do you still not understand RFM analysis method (model)?
- 蓝桥杯嵌入式-HAL库-USART_TX
- Problems needing attention when VC links static libraries
- CTF skill tree - file upload
猜你喜欢

蓝桥杯电子类嵌入式第十届省赛

Blue Bridge Cup embedded Hal library systick

Blue Bridge Cup embedded Hal library USART_ RX

I use the applet container to improve the efficiency of mobile R & D by 5 times!

蓝桥杯嵌入式-HAL库-USART_RX

MySQL Architecture Principle

这里有一份超实用Excel快捷键合集(常用+八大类汇总)

哈希表的相关知识点

Learn these analysis methods and models, and no longer have no ideas when encountering problems

用 ZEGO Avatar 做一个虚拟人|虚拟主播直播解决方案
随机推荐
19. Delete the penultimate node of the linked list
Causes and solutions of invalid ROM table
蓝桥杯嵌入式-HAL库-ADC
Use the statement object to execute DDL statements to create tables
Inventory: exciting data visualization chart
EC20/EC25 4G模块AT指令开发总结
GKCylindersNoiseSource
Nodejs: mongodb simple fuzzy + paging query instance
理解Oracle的几个概念
If you don't climb mountains, you don't know the height of the sky; If you don't face deep streams, you don't know the thickness of the earth
cortex-M4与cortex-A7内核启动流程分析
c语言实现float型数据转成BCD数据
I use the applet container to improve the efficiency of mobile R & D by 5 times!
Pyqt5 rapid development and practice 4.12 calendar and time
Eslint, Eslint中文文档
float浮动初步理解
The blogs of excellent programmers at home and abroad are all here, please check it
Arduino基础知识
C语言使用二重指针实现简单工厂模式(多态)
Start from scratch blazor server (2) -- consolidate databases