STM32&AT指令NBIOT模组
#include "nbiot.h"
#include "string.h"
#include "stdlib.h"
#include "led.h"
#include "beep.h" /*********************************************************************************
*********************启明欣欣 STM32F407应用开发板(高配版)*************************
**********************************************************************************
*资源源于网络 代码由阿正修改
*QQ群:476840321
* *
**********************************************************************************
*********************************************************************************/ u8 receive_str6[USART6_REC_NUM]; //接收缓存数组,最大USART_REC_LEN个字节
u8 uart_byte_count6=;
//定义结构体用来存储接收数据
typedef struct {
char USART_BUFF[];
int USART_Length;
int flag;
}Usart_Struct; Usart_Struct struct_usart6;
/****************************************************************************
* 名 称: void uart1_init(u32 bound)
* 功 能:USART6初始化
* 入口参数:bound:波特率
* 返回参数:无
* 说 明:
****************************************************************************/
void uart6_init(u32 bound)
{ //GPIO端口设置
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE); //使能GPIOA时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6,ENABLE);//使能USART1时钟
//串口1对应引脚复用映射
GPIO_PinAFConfig(GPIOC,GPIO_PinSource6,GPIO_AF_USART6); //GPIOA9复用为USART1
GPIO_PinAFConfig(GPIOC,GPIO_PinSource7,GPIO_AF_USART6); //GPIOA10复用为USART1
//USART1端口配置
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; //GPIOA9与GPIOA10
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //复用功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //速度50MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽复用输出
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
GPIO_Init(GPIOC,&GPIO_InitStructure); //初始化PA9,PA10
//USART1 初始化设置
USART_InitStructure.USART_BaudRate = bound;//波特率设置
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
USART_InitStructure.USART_StopBits = USART_StopBits_1; //一个停止位
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
USART_Init(USART6, &USART_InitStructure); //初始化串口1
USART_Cmd(USART6, ENABLE); //使能串口1 USART_ClearFlag(USART6, USART_FLAG_TC); USART_ITConfig(USART6, USART_IT_RXNE, ENABLE); //开启相关中断
//Usart1 NVIC 配置
NVIC_InitStructure.NVIC_IRQChannel = USART6_IRQn; //串口1中断通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=;//抢占优先级3
NVIC_InitStructure.NVIC_IRQChannelSubPriority =; //子优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器、
} /*******************************************************************************
* 发送字节
*******************************************************************************/
void uart6_send_char(u8 temp)
{
USART_SendData(USART6,(u8)temp);
while(USART_GetFlagStatus(USART6,USART_FLAG_TXE)==RESET);
} /*******************************************************************************
* 发送字符串
*******************************************************************************/
void uart6_send_buff(u8 buf[],u32 len)
{
u32 i;
for(i=;i<len;i++)
uart6_send_char(buf[i]);
// 可设置换行符 NB串口AT指令不需要换行
// uart2_send_char('\r');
// uart2_send_char('\n'); }
void USART6_IRQHandler(void)
{
uint8_t ch;
#ifdef SYSTEM_SUPPORT_OS
OSIntEnter();
#endif
if(USART_GetITStatus(USART6,USART_IT_RXNE) != RESET)
{
USART_ClearITPendingBit(USART6,USART_IT_RXNE);
ch = USART_ReceiveData(USART6);
struct_usart6.USART_BUFF[struct_usart6.USART_Length++] = ch;
struct_usart6.flag = ;
}
if( USART_GetITStatus( USART6, USART_IT_IDLE ) == SET )
{
USART_ClearITPendingBit(USART6,USART_IT_IDLE);
struct_usart6.flag = ;
ch = USART_ReceiveData(USART6);
}
#ifdef SYSTEM_SUPPORT_OS
OSIntExit();
#endif } /*******************************************************************************
* 发送字符串 并解析返回值是否正确
* cmd为传入值 reply 为校验返回值 wait 为延时
*******************************************************************************/
int NBiot_SendCmd(char* cmd, char* reply, int wait)
{
struct_usart6.USART_Length = ;
printf("[NBiot_SendCmd] %s\r\n", cmd); uart6_send_buff((u8*)cmd, strlen(cmd)); delay_ms(wait); if (strcmp(reply, "") == ) //返回值为空
{
return ;
} if (struct_usart6.USART_Length != ) //返回值不为空
{
struct_usart6.USART_BUFF[struct_usart6.USART_Length] = '\0'; if (strstr((char*)struct_usart6.USART_BUFF, reply))
{
printf("\r\n%s+++YES\r\n", struct_usart6.USART_BUFF); return ;
}
else if (strstr((char*)struct_usart6.USART_BUFF, "ERROR"))
{
printf("ERROR...\r\n"); delay_ms(); return ;
}
else
{
printf("\r\n%s+++NO\r\n", struct_usart6.USART_BUFF); return ;
}
}
}
int NBiot_Init()
{
int ret = ;
ret = NBiot_SendCmd("admin#AT+VER","OK", ); //询问版本号作为初始化
if (!ret)
{
printf("Cannot initialize NBIOT module");
return ;
}
return ret;
}
STM32&AT指令NBIOT模组的更多相关文章
- 利尔达NB-IOT模组Coap数据AT+NMGS发送时返回-513的原因
1. 利尔达NB-IOT模组使用AT+NMGS发送数据,返回-513的问题,大致有3种可能性,在硬件上,模组的射频电路分为A型和B型模组,所以烧写固件的时候,也要分为A和B型固件,如果烧写反了,那么R ...
- NB-IOT模组指令AT+NMSTATUS和AT+CGPADDR对比
1. AT+NMSTATUS,这个指令是用来查询模块在IOT平台的注册情况.注册指的是lwm2m协议里面的注册机制,详细可以参考lwm2m协议. 2. AT+MREGSWT,设置重启之后,自动启动注册 ...
- 海思NB-IOT模组在平台上注册
1. 添加设备,网页测试平台 https://develop.ct10649.com:8093/#/applications/1_lq7clNExjnGvPvGMG8w7_oYn4a/products ...
- 最全的NB-IoT芯片厂商、模组厂商信息
NB-IoT作为LPWAN(低功耗广域网)的新兴技术,因为具有低功耗.低成本.广覆盖.海量节点等优势,并且在授权频段可以与2G.3G无缝连接而被运营商所青睐且接受.特别是到了2017年,据统计全球有5 ...
- [原创]移远RM500U-CN模组驱动移植
1. 简介 中国广电正式放号了,为了支持广电700MHz的5G基站,需要换用新的5G模组.移远通信的RM500U模组正好可以满足我们的使用要求; 我们选用该模组的原因:双卡单待 支持SIM卡热插拔 支 ...
- NFC模组,开发NFC功能 仅仅要几条指令的事情
特点:实现NFC透明传输.内置NFC协议栈,支持UART串口直接读写,用于门禁能够同一时候兼容手机和卡片开门,还能实现动态密钥,读到的NFC数据自己主动串口输出,会串口就能开发NFC,不须要研究LLC ...
- 中国移动推出NB-IoT/eMTC/GSM多模通信模组Qualcomm调制解调器支持
亚洲电子消费展(CES Asia)在上海举行.期间,中国移动正式推出NB-IoT/eMTC/GSM三模通信模组A9500.该通信模组采用Qualcomm MDM9206 LTE IoT调制解调器,具有 ...
- 摄像头模组 PDAF对焦(Phase Detection Auto Focus)
本文主要是最近看的两个文档的总结,相对零散的笔记,包括<imx298 software reference PDAF>与<PDAF Truly>. 1.PDAF功能的实现需要使 ...
- 第五部分 linux系统管理员 开机流程 模组管理 与loader
第五部分 linux系统管理员 开机流程 模组管理 与loader 开机流程分析 cmos保存电脑硬件的参数 bios 基本的输入输出系统 读取硬件的软件 MBR master bo ...
随机推荐
- 数据结构之 图论---bfs(邻接表)
数据结构实验之图论二:基于邻接表的广度优先搜索遍历 Time Limit: 1000MS Memory limit: 65536K 题目描述 给定一个无向连通图,顶点编号从0到n-1,用广度优先搜索( ...
- hdu 2066 一个人的旅行 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2066 题目意思:给出T条路,和草儿家相邻的城市编号,以及草儿想去的地方的编号.问从草儿家到达草儿想去的 ...
- 【摘抄】u3d|unity学习教程与方法
小编,因为下面这句话,还是决定,只摘链接地址(来自百度经验): http://jingyan.baidu.com/article/19192ad820f17be53e570715.html 经验内容仅 ...
- JAVA RTTI
基础类可接收我们发给派生类的任何消息,因为两者拥有完全一致的接口.我们要做的全部事情就是从派生上溯造型,而且永远不需要回过头来检查对象的准确类型是什么.所有细节都已通过多态性获得了完美的控制. 但经过 ...
- Ruby attr_reader , attr_writer, attr_accessor方法
attr_reader方法------读取实例变量 attr_writer方法------改写实例变量 attr_accessor方法-----读写实例变量 class Person attr_rea ...
- 查看mysql状态
命令:mysqladmin -uroot -p -h172.16.0.20 status Uptime: 14317755 Threads: 61 Questions: 187732924 Sl ...
- H.264(MPEG-4 AVC)级别(Level)、DPB 与 MaxDpbMbs 详解(转载)
转自:http://www.cnblogs.com/zyl910/archive/2011/12/08/h264_level.html 对于H.264(MPEG-4 AVC)而言,级别(Level)是 ...
- python __builtins__ int类 (36)
36.'int', 用于将一个字符串或数字转换为整型 class int(object) | int(x=0) -> integer | int(x, base=10) -> intege ...
- IIS7的FTP出错: 451 No mapping for the unicode character exists in the target multi-byte code page
提示:IIS7的FTP出错: 451 No mapping for the unicode character exists in the target multi-byte code page 今天 ...
- Codeforces Round #542(Div. 2) C.Connect
链接:https://codeforces.com/contest/1130/problem/C 题意: 给一个n*n的图,0表示地面,1表示水,给出起点和终点, 现要从起点到达终点,有一次在两个坐标 ...