[群150178878]nRF51822-新手入门笔记【1】
转自: http://www.eeboard.com/bbs/thread-40359-1-1.html
这是1年前入门时记的笔记,有些问题很简单很入门,不过懒得修改了,使用的是旧版SDK,原理一样,希望对大家有帮助,后面的笔记比较乱,抽空继续整理一下,

为了防止个人理解错误,下面的回答大多都会引用了论坛资料或者链接。
1.如何让设备发起bongding请求
先设置权限BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&dis_init.dis_attr_md.read_perm)
在ios上,除非app试图读取的characteristic收到保护,否则是没有bongding请求发生的。(可参考ble_app_gls例程)

原回答如下:
On iOS, no bonding will occur unless an app tries to read a characteristic that is protected. If you use LightBlue, this app will not do any such reads unless you specifically asks it to. To trigger bonding, you should therefore make sure to navigate the services/characteristics in such way that either a protected read or write is triggered, which again should trigger bonding.

authorization doesn't have anything to do with bonding, it's just a way for the application to know and authorize each read/write.
The protection I mean is the one set with the BLE_GAP_CONN_SEC_* macros. If you try to read any characteristic that is set as for example BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(), this will trigger bonding.

2.如何添加用户自己的128bit UUID?
使用sd_ble_uuid_vs_add(param1, param2)函数添加自己的128bit的service或者UUID,6.0的softdevice固件支持添加最多10个128bitUUID。param1是16byte用户uuid, param2存放softdevice分配的UUIDtype, 从BLE_UUID_TYPE_VENDOR_BEGIN(0x02)开始算,总共能添加10条,以后每一条只需要这个vender uuid type就行.
注意,param1的第13,14byte 不用写也行,写了也没用,后面还需添加。
    /* 范例 */
    ble_uuid128_t  uuid_128bits = {0xD0, 0x00, 0x2D, 0x12, 0x1E, 0x4B, 0x0F, 0xA4, 0x99, 0x4E, 0xCE, 0xB5, 0, 0, 0x05, 0x79};  //中间两个0xF431,这是苹果的    ANCS service base uuid
    ble_uuid_t  ble_uuid;
    uint8_t uuid_128bit_type; //此变量存放softdevice分配的 UUID type

ble_uuid.uuid = 0xF431;
    err_code = sd_ble_uuid_vs_add(&uuid_128bits, uuid_128bit_type);
    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_me->service_handle);

3.如何发现ios的ANCS的service以及characteristic?
(1)使用函数sd_ble_uuid_vs_add()添加central的128bit UUID
(2)使用GATTC相关的函数查找service以及characteristic
   sd_ble_gattc_primary_services_discover()
   sd_ble_gattc_characteristics_discover()

4.如何清除绑定?
在static void bond_manager_init(void)函数中
    // Initialize the Bond Manager
    bond_init_data.flash_page_num_bond     = FLASH_PAGE_BOND;
    bond_init_data.flash_page_num_sys_attr = FLASH_PAGE_SYS_ATTR;
    bond_init_data.evt_handler             = NULL;
    bond_init_data.error_handler           = bond_manager_error_handler;
    bond_init_data.bonds_delete            = true; //此处可以清除绑定

err_code = ble_bondmngr_init(&bond_init_data);
    APP_ERROR_CHECK(err_code);

通过ble_bondmngr_init()函数, 即初始化了绑定参数,又同时清除了之前的绑定

5.APP_BUTTON_INIT 拿来什么用?和普通的引脚初始化有什么不同?
原型: APP_BUTTON_INIT(BUTTONS, BUTTON_COUNT, DETECTION_DELAY, USE_SCHEDULER)
用于​设置特定引脚作为button, USE_SCHEDULER参数决定是否调用button_handle函数
示例:
static void buttons_init(void)
{
    static app_button_cfg_t buttons[] =
    {
        {HR_INC_BUTTON_PIN_NO, false, NRF_GPIO_PIN_PULLUP, button_event_handler},
        {HR_DEC_BUTTON_PIN_NO, false, NRF_GPIO_PIN_PULLUP, button_event_handler}  // Note: This pin is also BONDMNGR_DELETE_BUTTON_PIN_NO
    };

APP_BUTTON_INIT(buttons, sizeof(buttons) / sizeof(buttons[0]), BUTTON_DETECTION_DELAY, false);
}

​该函数底层用到app_timer_create(); 用32.768低功耗定时器来检测按键是否发生.

6.如何保护Flash程序不被读取?
NRF_NVMC->CONFIG = 1; //开启FLASH写权限(写UIRC)
while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
{
    // Do nothing.
}
NRF_UICR->RBPCONF = 0x00000000;
NRF_NVMC->CONFIG = 0;

7.advertising_init()函数中的广播数据中的flag应该怎么设置, Scan Response是否需要设置flag?
flags must be included in advertising data,
and the BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED flag must be set
Advertising Data 必须设置flag, 设置对了其他的广播数据自由选择.
Scan Response Data不需要设置flag否则会出错

8.如何广播128bit UUID?
首先建议在main()函数中添加本次工程需要用到的所有的128bit vender service base uuid, 而且添加时必须放在ble_stack_init()函数后,因为该函数启动了softdevice. (我把它放在all_vs_uuid_add()函数中, 在main()函数中调用)
static void all_vs_uuid_add(void)
{
    uint32_t err_code;
    ble_uuid128_t uuid_128bits = RBL_SHIELD_UUID_BASE; //16byte 数据

err_code = sd_ble_uuid_vs_add(&uuid_128bits, &ble_rbl_shield.uuid_type);
    APP_ERROR_CHECK(err_code);
}
广播的128bit vender service uuid可以放在advertising data中也可以放在scan response data中
static void advertising_init(void)
{
    uint32_t      err_code;
    ble_advdata_t advdata;
    uint8_t       flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    ble_advdata_t srdata;

ble_uuid_t adv_uuids[] =
    {
        {0x0000,   ble_rbl_shield.uuid_type} //BLE_UUID_TYPE_BLE ble_rbl_shield.uuid_type
    };

// Build and set advertising data
    memset(&advdata, 0, sizeof(advdata));

//同时在advertising data和scan response data中广播128bit vs uuid
    advdata.flags.size              = sizeof(flags);
    advdata.flags.p_data            = &flags;
    advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    advdata.uuids_complete.p_uuids  = adv_uuids;

srdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    srdata.uuids_complete.p_uuids  = adv_uuids;

err_code = ble_advdata_set(&advdata, &srdata);
    APP_ERROR_CHECK(err_code);

// Initialize advertising parameters (used when starting advertising)
    memset(&m_adv_params, 0, sizeof(m_adv_params));

m_adv_params.type        = BLE_GAP_ADV_TYPE_ADV_IND;
    m_adv_params.p_peer_addr = NULL;                           // Undirected advertisement
    m_adv_params.fp          = BLE_GAP_ADV_FP_ANY;
    m_adv_params.interval    = APP_ADV_INTERVAL;
    m_adv_params.timeout     = APP_ADV_TIMEOUT_IN_SECONDS;
}

如果遇到添加后程序错误, 那要注意, 因为128bit的uuid已经占了16bytes, 如果这时候你的local name或者你还广播了其他的UUID,超过了31bytes程序是会发生错误的.

9.为什么蓝牙连接上iphone后一会就自动断线了?
这里只说一种情况,  如果蓝牙的最大及最小的连接间隔设置的太小, 就会出现上述情况, 什么都不做但是过会会断线.iphone要求的连接间隔是:
Interval Max * (Slave Latency + 1) ≤ 2 seconds
Interval Min ≥ 20 ms
Interval Min + 20 ms ≤ Interval Max Slave Latency ≤ 4
connSupervisionTimeout ≤ 6 seconds
Interval Max * (Slave Latency + 1) * 3 < connSupervisionTimeout

我们可以定为20ms~40ms

10. 如何通过蓝牙传输大量数据?
询问FAE后得到的回答如下
The easiest way to send large amounts of data is to send them sequentially as notifications.
Add a characteristic that is 20 bytes long and has the notify property. Split your data in 20 byte chunks and call sd_ble_gatts_hvx() repeatedly until you get the BLE_ERROR_NO_TX_BUFFERS back. At that time, wait until you get a BLE_EVT_TX_COMPLETE, at which point you again can send data until you get the BLE_ERROR_NO_TX_BUFFERS. Repeat until all data has been sent.
https://devzone.nordicsemi.com/index.php/dealing-large-data-packet-s-through-ble#reply-1755

有个ble event 宏定义为: BLE_EVT_TX_COMPLETE, 收到这个事件就代表本次传输完毕.另外我们是通过sd_ble_gatts_hvx()把待传输的数据尽可能地添加进tx buffer中去.

11.影响nRF51822(S110固件)数据传输速度的最大因素是什么?

nRF51822-新手入门笔记相关推荐

  1. Pytorch纯新手入门笔记

    Pytorch入门笔记(推荐配合B站up主我是土堆食用) PyTorch深度学习快速入门教程(绝对通俗易懂!)[小土堆] 视频作者:我是土堆 Pytorch入门 P1 命令行中对anaconda不同环 ...

  2. Datawhale 数据挖掘新手入门笔记 -Task5 模型融合

    文章目录 一.前言 二.模型融合目标 三.内容介绍 四.Stacking相关理论介绍 1.什么是stacking 2.如何进行stacking 3.Stacking的方法讲解 五.代码示例 1.回归\ ...

  3. 正则表达式新手入门笔记(一)

    正则表达式 描述了一种字符串匹配的模式,可以用来检查一个串 是否含有某种子串. 将匹配的子串替换 或者从某个串中取出符合某个条件的子串等. 本章节就来写一下入门正则表达式的收获内容. 首先我们先从正则 ...

  4. python新手入门笔记_2020最新Python入门笔记

    Python变量和数据类型 数据类型 print语句 注释 Python的注释以 # 开头,后面的文字直到行尾都算注释 这里要注意注意:不管你是为了Python就业还是兴趣爱好,记住:项目开发经验永远 ...

  5. RISC-V入门笔记(新手必看!)

    目录 什么是RISC-V RISC-V 发展 RISC-V指令集 RISC-V特权架构 RISC-V通用寄存器 RISC-V CSR寄存器 M模式CSR寄存器 S模式CSR寄存器 总结 笔者学习RIS ...

  6. python新手入门英文词汇_Python新手入门基础的英文笔记有哪些

    Python新手入门基础的英文笔记有哪些 发布时间:2020-11-20 11:59:05 来源:亿速云 阅读:88 作者:小新 小编给大家分享一下Python新手入门基础的英文笔记有哪些,希望大家阅 ...

  7. Vue 新手学习笔记:vue-element-admin 之入门开发教程(v4.0.0 之前)

    说实话都是逼出来的,对于前端没干过ES6都不会的人,vue视频也就看了基础的一些 但没办法,接下来做微服务架构,前端就用 vue,这块你负责....说多了都是泪,脚手架框架布了都没看过 干就完事,不过 ...

  8. openGl新手入门学习笔记(二)下载glew,配置glew的环境与glew的初始化

    这里是一个想要入行游戏行业的平平无奇大学生,希望能够通过写博客来巩固自己学的知识. 一.现代OpenGl 在"openGl新手入门学习笔记(一)"里提到了古典openGl(旧版op ...

  9. 蓝桥云课 Python新手入门课 笔记

    Python 新手入门课_Python - 蓝桥云课 目录 Python 新手入门课_Python - 蓝桥云课 实验一  进入编程大门 实验二  认识Linux 实验三  认识Python 实验四 ...

  10. 【FPGA学习笔记】 第一章: PLD/FPGA新手入门

    第一章          PLD/FPGA新手入门 1.       可编程逻辑器件的发展历程 当今社会是数字化的社会,是数字集成电路广泛应用的社会.数字集成电路本身在不断地进行更新换代.它由早期的电 ...

最新文章

  1. FFmpeg通过摄像头实现对视频流进行解码并显示测试代码(旧接口)
  2. IOS 实现滚动文字
  3. 三种编程命名规则(匈牙利法,小驼峰法,大驼峰法)
  4. 手工计算YARN和MapReduce、tez内存配置设置
  5. Python代码模块化!
  6. 谷歌 .dev 顶级域名正式开放
  7. How to recover from root.sh on 11.2 Grid Infrastructure Failed
  8. 是时候给为的 C 盘清理污垢了!一个830KB的神器安全解决烦恼 | C 盘快满了,如何清理 C 盘? | win 10 OS盘清理
  9. Iocomp ActiveX v5 SP6 带OPC -Crack
  10. java 方法注释格式_JAVA注释方法及格式
  11. window新建文本快捷键
  12. 关于vue3 的vue-router.mjs:3434 ReferenceError: parcelRequire is not defined
  13. 云原生 - 自建数据库与云数据库RDS性能优势分析,值不值得购买?
  14. android模拟器 对比,安卓模拟器多开用哪个模拟器好?实测数据对比哪个好用
  15. Untiy的阿拉伯文本适配
  16. 【学习亚马逊AWS IOT体系有感---万物互联(物联网)】
  17. 搜狗浏览器在高速模式下,右键点击才会出现“审查元素”
  18. 机器学习_深度学习毕设题目汇总——人脸B
  19. 关于川大667和972自命题考试的心得
  20. 常用计算机制图软件,常用的电脑画图软件有什么?

热门文章

  1. 软件构造(九) 面向复用的软件构造技术
  2. Ansible剧本使用
  3. 【MongoDB】MacOS安装MongoDB完整收录
  4. 西普实验吧CTF-约瑟夫环
  5. 725 数模 空气污染问题研究 (15 五一 B)
  6. 零基础自学软件测试,第一份外包工作8K,到现在大厂月薪25K*16薪
  7. 【计算机毕业设计】70.毕业设计管理系统源码
  8. 零基础学习数据分析路线,学习到什么程度可以找到工作
  9. Rancher极简service mesh产品Rio安装试玩(基于k3s)
  10. 张艾迪(创始人):艾迪的学校与成长故事