Giter Site home page Giter Site logo

mayulin2008 / nrf52832-ble-uart Goto Github PK

View Code? Open in Web Editor NEW

This project forked from langxing08/nrf52832-ble-uart

0.0 1.0 0.0 2.4 MB

Enhanced BLE-UART module with AT command

License: Apache License 2.0

Batchfile 0.01% C 95.69% C++ 3.50% Assembly 0.80%

nrf52832-ble-uart's Introduction

nRF52832-BLE-UART

一、功能概述

本 BLE_UART 模块(以下简称为 BLE_UART )主要功能如下:
  • BLE 和串口数据转发。
    • 模块将从串口接收到的数据通过 BLE 转发出去;
    • 模块将 BLE 接收到的数据通过串口转发出去。
  • 串口 AT 指令配置模块功能。

二、BLE通信

BLE_UART 支持 BLE 4.0/4.1/4.2 通信。
Android 4.3及以后 和 iPhone 4s + iOS 7.0及以后 的智能手机才支持 BLE 4.0,才可以与 BLE_UART 进行通信。  

2.1 广播Advertising

广播数据包包括 Advertising Data 和 Scan Response Data。

2.1.1 Advertising Data

adv

BLE_UART 中 Advertising Data 的 PDU 格式为 ADV_IND。<br>flag 值为 0x06,表示只支持 BLE,不支持 BR/EDR,通用发现模式。<br>Device Name 为设备名称。

2.1.2 Scan Response Data

scan

Scan Response Data 中包括服务 UUID,为 128 位自定义 UUID。

2.2 服务Service

profile

BLE_UART 的 profile 中包含 4 个首要服务(Primary Service),包括Generic Access Service、Generic Attribute Service、Nordic UART Service 和 Device Information Service。

2.2.1 Generic Access Service

该服务中包括Device Name、Appearance、Peripheral Preferred Connection Parameters和Central Address Resolution 4个特征值。
服务的UUID和各个特征值的权限及UUID详见下图。

access

Device Name 特征值为设备名称。
Appearance 特征值为外观特性,本模块没有设置该值,默认值为0。
Peripheral Preferred Connection Parameters 特征值为周边设备推荐的连接参数,本模块默认值为连接间隔10ms - 30ms,从机延迟0,监督超时72*10=720ms。该连接参数也是iOS默认的连接参数。
Central Address Resolution 特征值为是否支持**设备私有设备地址解析,BLE_UART 默认值为支持。

2.2.2 Generic Attribute Service

attribute

该服务为空。

2.2.3 Nordic UART Service

该服务不是SIG定义的标准服务,是用户自定义服务。服务UUID和各特征值的权限及UUID见下图。该服务中包含RX和TX 2个特征值。

uart

  • RX特征值用于将**设备通过BLE write到本模块的数据通过串口转发出去。BLE每包write最多支持 ATT_MTU(默认值为23,可通过ATT_MTU_UPDATED事件协商更改) - 3 个字节,如果**设备需要发送的数据超过20字节,需要**设备分包后再write,否则会导致write失败,甚至可能导致模块重启。
  • TX特征值用于将模块串口接收到的数据通过BLE以notify方式转发出去,每包最多 ATT_MTU - 3 个字节,如果串口接收到的数据超过 ATT_MTU - 3 个字节,则模块自动按照 ATT_MTU - 3 个字节分包发送。另外,如果串口接收到的数据为AT指令,则模块会进行相应的操作,并返回执行结果。注意:必须使能Notification才能将数据从本模块notify给**设备。

三、串口通信

模块上电默认串口配置:115200bps,8位数据位,1位停止位,无校验位,无流控。
串口每帧最多接收256字节,超过ATT_MTU(默认值为23,可通过ATT_MTU_UPDATED事件协商更改)-3个字节自动分包,支持不定帧长度,支持任意字符结尾。接收完一个字符后3ms不再接收到新的字符,则认为本帧结束。

四、串口AT指令

BLE_UART 支持的 AT 指令如下表所示。
命令 说明
AT 测试串口通信
AT+RESET 复位模块
AT+MAC 查询模块MAC地址
AT+VER 查询模块版本信息
AT+STATUS 查询模块BLE连接状态
AT+DISCON 断开BLE连接
AT+BAUD 配置串口波特率
AT+TXPW 配置射频发射功率
AT+ADV 配置广播间隔
AT+CON 配置连接参数
所有AT指令(包括命令和响应)必须"AT"作为开头,以回车新行(<CR><LF>)结尾,为描述方便,文档中<CR><LF>被有意忽略了。

4.1 AT 测试串口通信

查询命令 响应 命令参数说明 响应参数说明
AT? AT:<status> <status> 执行结果:
OK - 串口通信正常

4.2 AT+RESET 复位模块

设置命令 响应 命令参数说明 响应参数说明
AT+RESET AT+RESET:<status> <status> 执行结果:
OK - 复位模块成功

4.3 AT+MAC 查询模块MAC地址

查询命令 响应 命令参数说明 响应参数说明
AT+MAC? AT+MAC:<MAC address> <MAC address> 模块MAC地址(16进制字符串,12 Bytes)

4.4 AT+VER 查询模块版本信息

查询命令 响应 命令参数说明 响应参数说明
AT+VER? AT+VER:<HW version>,<FW version>,<SW version> <HW version> 硬件版本
<FW version> 协议栈固件版本
<SW version> 应用软件版本

4.5 AT+STATUS 查询模块BLE连接状态

查询命令 响应 命令参数说明 响应参数说明
AT+STATUS? AT+STATUS:<status> <status> BLE连接状态:
1 - 已连接,
0 - 未连接或断开连接

4.6 AT+DISCON 断开BLE连接

设置命令 响应 命令参数说明 响应参数说明
AT+DISCON AT+DISCON:<status> <status> 断开BLE连接执行结果:
OK - 执行成功,
FAIL - 执行失败,
ERP - 参数错误

4.7 AT+BAUD 配置串口波特率

设置命令 响应 命令参数说明 响应参数说明
AT+BAUD=<level> AT+DISCON:<status> <level> 波特率:
0 - 4800bps,
1 - 9600bps,
2 - 19200bps,
3 - 38400bps,
4 - 57600bps,
5 - 115200bps,
6 - 230400bps,
7 - 460800bps,
8 - 921600bps
<status> 设置串口波特率执行结果:
OK - 执行成功,
FAIL - 执行失败,
ERP - 参数错误

4.8 AT+TXPW 配置射频发射功率TX Power

设置命令 响应 命令参数说明 响应参数说明
AT+TXPW=<level> AT+TXPW:<status> <level> 发射功率:
0 - -40dBm,
1 - -20dBm,
2 - -16dBm,
3 - -12dBm,
4 - -8dBm,
5 - -4dBm,
6 - 0dBm,
7 - +3dBm,
8 - +4dBm
<status> 设置发射功率执行结果:
OK - 执行成功,
FAIL - 执行失败,
ERP - 参数错误

4.9 AT+ADV 配置广播间隔

设置命令 响应 命令参数说明 响应参数说明
AT+ADV=<adv_interval> AT+ADV:<status> <adv_interval> 广播间隔:单位0.625ms,
最小值0x0020,最大值0x4000
<status> 设置广播间隔执行结果:
OK - 执行成功,
FAIL - 执行失败,
ERP - 参数错误

4.10 AT+CON 配置连接参数

设置命令 响应 命令参数说明 响应参数说明
AT+CON=<min_connect_interval>,
<max_connect_interval>,<slave_latency>,
<conn_sup_timeout>
AT+CON:<status> <min_connect_interval> 最小连接间隔:单位1.25ms,6 ≤ min_connect_interval ≤ max_connect_interval
<max_connect_interval> 最大连接间隔:单位1.25ms,min_connect_interval ≤ max_connect_interval ≤ 0x0C80
<slave_latency> 从机延迟:最大值499
<conn_sup_timeout>监督超时:单位10ms,1 ≤ conn_sup_timeout ≤ 3200
注意:(1 + slave_latency) * (max_connect_interval) < conn_sup_timeout
<status> 设置连接参数执行结果:
OK - 执行成功,
FAIL - 执行失败,
ERP - 参数错误

nrf52832-ble-uart's People

Contributors

langxing08 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.