当前位置:网站首页>Bc35 NB module at instruction development summary
Bc35 NB module at instruction development summary
2022-07-28 11:03:00 【tutu-hu】
List of articles
One .BC35 NB Module introduction
BC35-G It's a high performance 、 Low power consumption NB-IoT modular , Support the six frequency bands listed in the following table . adopt NB-IoT Radio communication protocol (3GPP Rel. 14),BC35-G The module can establish communication with the infrastructure of the network operator .
Power supply :
VBAT Supply voltage range :3.1V~4.2V
Typical supply voltage :3.6V
Transmitting power :
23dBm±2dB
A serial port :
Main serial port : be used for AT Command communication and data transmission , The baud rate supported is 4800bps、9600bps( Default )、57600bps、115200bps、230400bps and 460800bps, For firmware upgrade , The baud rate supported is 115200bps and 921600bps
Debug serial port : For software debugging , Only baud rate is supported 921600bps
Network protocol characteristics :
Support IPv4/IPv6/UDP/CoAP/LwM2M/Non-IP/DTLS/TCP/MQTT agreement
Antenna interface :
50Ω Characteristic impedance
Two .TCP Data transmission process
1. The module is powered on ----->2. Module networking ----->3. establish TCP Connect ----->4.TCP send data ----->5. Wait for the data to be returned and processed ----->6. The module is powered off .
Detailed procedure flow :
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 nb_printf(char* fmt,...)
{
u16 i;
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
}
//NB_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* nb_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 NB_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 nb_send_cmd(u8 *data,u8 *ack,u16 waittime)
{
waittime=waittime*100;
nb_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(nb_send_check_cmd(ack))
{
//printf("%s ack: %s\r\n",data,(u8*)ack);
Feed_Dog(); // feed a dog
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
}
// towards NB_MODULE Send the specified data , And read the return parameter value
//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 nb_send_cmd_return(u8 *data,u8 *ack,u16 waittime,u8 *parameter)
{
nb_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(100);
if(USART1_IDLE_FLAG) // Received the expected response result
{
if(nb_send_check_cmd(ack))
{
*parameter=USART1_RX_BUF[2];
printf("%s ack: %s\r\n",data,(u8*)ack);
Feed_Dog(); // feed a dog
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
}
2. Module networking
/** * @brief NB Module networking * Reference manual :p160 Manual network connection * * @param void * * @return 0: Successful connection * 1: The connection fails */
u8 NB_Connect_To_Internet(void)
{
u8 i=0;
for(i=0;i<3;i++)
if(nb_send_cmd((u8 *)"AT+NRB",(u8 *)"REBOOT_CAUSE_APPLICATION_AT",100)==0)break;
if(i==3)
{
printf(" Module restart failed ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf(" Module restart succeeded ...\r\n\r\n");
for(i=0;i<3;i++)
if(nb_send_cmd((u8 *)"AT+NBAND=5",(u8 *)"OK",10)==0)break;
if(i==3)
{
printf(" Failed to set frequency band ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf(" Set frequency band successfully ...\r\n\r\n");
for(i=0;i<3;i++)
if(nb_send_cmd((u8 *)"AT+CFUN=1",(u8 *)"OK",40)==0)break;
if(i==3)
{
printf(" Failed to set the maximum function mode ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf(" Set the maximum function mode successfully ...\r\n\r\n");
i=0;
for(i=0;i<3;i++)
if(nb_send_cmd((u8 *)"AT+CEDRXS=0,5",(u8 *)"OK",10)==0)break;
if(i==3)
{
printf(" Close module eDRX Function failed ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf(" Close module eDRX Function success ...\r\n\r\n");
for(i=0;i<3;i++)
if(nb_send_cmd((u8 *)"AT+CGATT=1",(u8 *)"OK",20)==0)break;
if(i==3)
{
printf(" Failed to attach the network ...\r\n\r\n");
return 1; // Failure , return 1
}
else printf(" Successfully attached to the network ...\r\n\r\n");
for(i=0;i<10;i++)
if(nb_send_cmd((u8 *)"AT+CGATT?",(u8 *)"+CGATT:1",20)==0)break;
if(i==10)
{
printf(" Network connection failed ...\r\n\r\n");
return 1;
}
else
printf(" Network connection successful ...\r\n\r\n");
return 0;
}
3. establish TCP Connect
/** * @brief establish TCP 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: Send successfully * 1: fail in send */
u8 NB_TCP_Connect(const u8* ip,const u8* port,u8* socket)
{
u8 i=0;
u8 p[50];
for(i=0;i<3;i++)
if(nb_send_cmd_return((u8 *)"AT+NSOCR=STREAM,6,0,1",(u8 *)"OK",100,socket)==0)break;
if(i<3)printf(" establish socket success ...\r\n\r\n");
else
{
printf(" establish socket Failure ...\r\n\r\n");
return 1;
}
*socket=*socket-48;
printf("tcp_socket=%d\r\n",*socket);
sprintf((char*)p,"AT+NSOCO=%d,%s,%s",*socket,ip,port);
for(i=0;i<3;i++)
if(nb_send_cmd((u8 *)p,(u8 *)"OK",100))break;
if(i<3)printf("TCP Successful connection ...\r\n\r\n");
else
{
printf("TCP The connection fails ...\r\n\r\n");
return 1;
}
return 0;
}
4.TCP send data
/** * @brief TCP send data * * @param socket: Socket size * data: Data sent * len: Length of data sent * * @return 0: Send successfully * 1: fail in send */
u8 tx_buffer[2000]={
0}; // Define the final send data buffer
u8 p[2000]; // Encapsulated into the final frame format to be sent
u8 NB_TCP_Send_Data(u8 socket,u8* data,u16 len)
{
u8 i=0;
HexArrayToString(data,(char*)USART1_TX_BUF,len); // First, convert the original data into a string
HexArrayToString(USART1_TX_BUF,(char*)tx_buffer,2*len); // Let's talk about string conversion ASCII code
sprintf((char*)p,"AT+NSOSD=%d,%d,%s,%s,%s",socket,2*len,(char*)tx_buffer,"0x100","101");
memset(USART1_TX_BUF,0,sizeof(USART1_TX_BUF));// Empty cache , Because nb_send_cmd() You also need to use USART1_TX_BUF, So it needs to be emptied
memset(tx_buffer,0,sizeof(tx_buffer)); // Empty cache , Because nb_send_cmd() You also need to use USART1_TX_BUF, So it needs to be emptied
for(i=0;i<3;i++)
if(nb_send_cmd((u8 *)p,(u8 *)"101,1",50)==0)break;
memset(p,0,sizeof(p));// Empty cache
if(i<3)
{
printf("TCP Data sent successfully , And the confirmation is received by the server ...\r\n\r\n");
return 0;
}
else
{
printf("TCP Failed to send data ...\r\n\r\n");
return 1;
}
}
5. Wait for the data to be returned and processed ( Partial procedure )
while(1) // Wait for the countdown of cloud data
{
delay_ms(5); // Time delay 5ms Determine if data is received
if(USART1_IDLE_FLAG) // A serial port 1 Receiving data is over , And NB Module communication
{
/* Determine whether there is data from the server */
str1=nb_send_check_cmd((u8 *)"+NSONMI:");// Judge whether the received data is +NSONMI:
if(str1) // Make sure you receive +NSONMI:
{
receive_socket=*(str1+8)-48; // Get the current socket Number
if(USART1_RX_COUNT-14==1)receive_num=*(str1+10)-48;
else if(USART1_RX_COUNT-14==2)receive_num=(*(str1+10)-48)*10+*(str1+11)-48; // Get the number of bytes currently received
sprintf((char*)q,"%d,%s,%s,%d",receive_socket,IP_address,portnum,receive_num);// Form a package
receive_data_flag=1; // Received data flag position bit
}
/* Judge whether the data from the server is received */
str2=nb_send_check_cmd((u8*)q); // Judge whether the received data is +NSONMI:
if(str2) // Confirm that the data is received
{
HexStrToByte(str2+strlen(q)+1,Receive_Buffer,2*receive_num); // Put the characters as HEX And exist Receive_Buffer in , To be processed
read_data_flag=1; // Data processing flag position bit
}
memset(USART1_RX_BUF,0,sizeof(USART1_RX_BUF));// Empty cache
USART1_RX_COUNT=0; // Clear the number of bytes accepted
USART1_IDLE_FLAG=0; // Idle interrupt flag reset
}
if(receive_data_flag) // Confirm that the module receives data from the server
{
sprintf((char*)p,"AT+NSORF=%d,%d",receive_socket,200);
nb_printf("%s\r\n",p); // Send and receive data instructions
receive_data_flag=0; // Received data flag bit reset
}
/* Data processing is needed */
if(read_data_flag) // Confirm that data processing is required
{
for(i=0;i<receive_num;i++)
printf("%x ",Receive_Buffer[i]);
printf("\r\n");
waittime=4000; // The timing time is resumed after receiving data once
break;
}
}3、 ... and .UDP Data transmission process
1. The module is powered on ----->2. Module networking ----->3. establish UDP Connect ----->4.UDP send data ----->5. Wait for the data to be returned and processed ----->6. The module is powered off .
Detailed procedure flow :
Related support functions :
Same as above TCP Agreement
2. Module networking
Same as above TCP Agreement
3. establish UDP Connect
/** * @brief 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: Send successfully * 1: fail in send */
u8 NB_UDP_Creat_socket(u8* socket)
{
u8 i=0;
for(i=0;i<3;i++)
if(nb_send_cmd_return((u8 *)"AT+NSOCR=DGRAM,17,0,1",(u8 *)"OK",100,socket)==0)break;
if(i<3)
{
printf(" establish socket success ...\r\n\r\n");
*socket=*socket-48;
printf("udp_socket=%d\r\n",*socket);
return 0;
}
else printf(" establish socket Failure ...\r\n\r\n");
return 1;
}
4.UDP send data
/** * @brief UDP send data * * @param socket: Socket size * data: Data sent * len: Length of data sent * * @return 0: Send successfully * 1: fail in send */
u8 NB_UDP_Send_Data(u8 socket,const u8* ip,const u8* port,u8* data,u16 len)
{
u16 i=0;
HexArrayToString(data,(char*)USART1_TX_BUF,len); // First, convert the original data into a string
HexArrayToString(USART1_TX_BUF,(char*)tx_buffer,2*len); // Let's talk about string conversion ASCII code
sprintf((char*)p,"AT+NSOST=%d,%s,%s,%d,%s,%d",socket,ip,port,2*len,(char*)tx_buffer,100);
memset(USART1_TX_BUF,0,sizeof(USART1_TX_BUF));// Empty cache , Because nb_send_cmd() You also need to use USART1_TX_BUF, So it needs to be emptied
memset(tx_buffer,0,sizeof(tx_buffer)); // Empty cache , Because nb_send_cmd() You also need to use USART1_TX_BUF, So it needs to be emptied
for(i=0;i<3;i++)
if(nb_send_cmd((u8 *)p,(u8 *)"100,1",100)==0)break;
memset(p,0,sizeof(p));// Empty cache
if(i<3)
{
printf("UDP Data sent successfully ...\r\n\r\n");
return 0;
}
else
{
printf("UDP Failed to send data ...\r\n\r\n");
return 1;
}
}
5. Wait for the data to be returned and processed
Same as above TCP Agreement 边栏推荐
- 一文学会如何做电商数据分析(附运营分析指标框架)
- Select without the order by clause, the order of the returned results is not reliable
- STM32中的APB2和APB1
- Inventory: 144 free learning websites, the most complete collection of resources in the whole network
- Software designers ask 20 questions before the exam, pay attention!!
- Preliminary understanding of float
- Use the statement object to execute DDL statements to create tables
- 读懂这6本书,学习MySQL更轻松
- RHEL 6.4 安装svn和apache
- 剑指 Offer 06. 从尾到头打印链表
猜你喜欢

Preliminary understanding of float

学会这些分析方法及模型,遇到问题不再没思路

Sword finger offer 35. replication of complex linked list

Advance.ai sailing guide helps enterprises sail to Indonesia and grasp half of the Southeast Asian market

蓝桥杯嵌入式-HAL库-ADC

哈希表的相关知识点

Redis-day01 common sense supplement and redis introduction

Ten questions about low code: tell everything about low code!

蓝桥杯嵌入式-HAL库-SYSTICK

GKCylindersNoiseSource
随机推荐
Blue Bridge Cup embedded Hal library ADC
11_ UE4 advanced_ Change male characters to female characters and modify the animation
剑指 Offer 06. 从尾到头打印链表
02.1.2. logic type bool
为什么传输前要进行编码与调制
Apb2 and apb1 in stm32
Eslint, Eslint中文文档
JSON初步理解
Eslint, eslint Chinese document
Blue Bridge Cup embedded Hal library USART_ TX
Tree Shaking和DCE
The Xiongguan pass is like an iron road, and now we are going to cross it from the beginning
GKVoronoiNoiseSource
Blue Bridge Cup embedded Hal library USART_ RX
GKSpheresNoiseSource
Clo********e: project management notes
BC35 NB模块AT指令开发总结
用 ZEGO Avatar 做一个虚拟人|虚拟主播直播解决方案
内存操作函数memcpy()和memmove()的用法
Ten questions about low code: tell everything about low code!