当前文档版本为 NDK-v0.6.0,您可以访问当前页面的 开发中 版本以获取最近可能的更新。

BLE Central and Peripheral

1 功能概述

此项目演示蓝牙主从一体功能,其实就是整合了ble_central以及ble_peripheral_hr功能。

  • 作为主机:可以直接扫描和连接ble_peripheral_enc示例,可以直接下载ble_peripheral_enc到另外一块EVB板上。

  • 作为从机:其实就是一个ble_peripheral_hr例程,可以使用手机nrf_connect app与其相连。

作为主机和从机的功能可以同时使用。

2 环境要求

  • board: pan107x evb

  • uart(option): 用来显示串口log(波特率921600,选项8n1

3 编译和烧录

例程位置:<home>\nimble\samples\bluetooth\ble_cent_prph\keil_107x

使用keil进行打开项目进行编译烧录。

4 演示说明

  1. 烧录完成后,如果空中有ble_peripheral_enc存在,则会主动连接上 。同时使用nrf connect 扫描发发现cent_prph设备,连接上后会出现heartrate service服务。

    • 主机log如下:

    
    [15:32:17.967]Try to load HW calibration data.. DONE.
    - Chip Type         : 0x80
    - Chip CP Version   : None
    - Chip FT Version   : 8
    - Chip MAC Address  : D0000C0CBBF5
    - Chip Flash UID    : 32313334320EAC834330FFFFFFFFFFFF
    - Chip Flash Size   : 1024 KB
    LL Spark Controller Version:b0e99c4
    
    [15:32:18.011]ble_store_config_num_our_secs:0
    ble_store_config_num_peer_secs:0
    ble_store_config_num_cccds:0
    blehr_advertise
    
    [15:32:19.216]Connection established handle=0 our_ota_addr_type=0 our_ota_addr=06:05:04:03:06:06 our_id_addr_type=0 our_id_addr=06:05:04:03:06:06 peer_ota_addr_type=0 peer_ota_addr=06:05:04:03:02:01 peer_id_addr_type=0 peer_id_addr=06:05:04:03:02:01 conn_itvl=40 conn_latency=0 supervision_timeout=256 encrypted=0 authenticated=0 bonded=0
    /*作为主机连接slave设备*/
    [15:32:21.923]Service discovery complete; status=0 conn_handle=0
    
    [15:32:22.021]Read complete; status=0 conn_handle=0 attr_handle=12 value=0x00
    Write complete; status=270 conn_handle=0 attr_handle=22
    
    [15:32:22.073]Subscribe complete; status=0 conn_handle=0 attr_handle=20
    
    [15:32:27.516]connection established; status=0
    /*作为从机被手机主机连接*/
    [15:32:30.908]subscribe event; cur_notify=1
     value handle; val_handle=3
    
    
    • 从机ble_peripheral_enclog如下:


[15:32:15.447] Try to load HW calibration data.. DONE.
- Chip Type         : 0x80
- Chip CP Version   : None
- Chip FT Version   : 7
- Chip MAC Address  : D0000C06FB6E
- Chip Flash UID    : 31373237304A23094330FFFFFFFFFFFF
- Chip Flash Size   : 1024 KB
LL Spark Controller Version:b0e99c4

[15:32:15.491] ble_store_config_num_our_secs:0
ble_store_config_num_peer_secs:0
ble_store_config_num_cccds:0
registered service 0x1800 with handle=1
registering characteristic 0x2a00 with def_handle=2 val_handle=3
registering characteristic 0x2a01 with def_handle=4 val_handle=5
registered service 0x1801 with handle=6
registering characteristic 0x2a05 with def_handle=7 val_handle=8
registered service 0x1811 with handle=10
registering characteristic 0x2a47 with def_handle=11 val_handle=12
registering characteristic 0x2a46 with def_handle=13 val_handle=14
registering characteristic 0x2a48 with def_handle=16 val_handle=17
registering characteristic 0x2a45 with def_handle=18 val_handle=19
registering characteristic 0x2a44 with def_handle=21 val_handle=22
registered service 59462f12-9543-9999-12c8-58b459a2712d with handle=23
registering characteristic 33333333-2222-2222-1111-111100000000 with def_handle=24 val_handle=25
registering descriptor 34343434-2323-2323-1212-121201010101 with handle=27
Device Address: 01 02 03 04 05 06


[15:32:19.216] connection established; status=0 handle=1 our_ota_addr_type=0 our_ota_addr=01 02 03 04 05 06
 our_id_addr_type=0 our_id_addr=01 02 03 04 05 06
 peer_ota_addr_type=0 peer_ota_addr=06 06 03 04 05 06
 peer_id_addr_type=0 peer_id_addr=06 06 03 04 05 06
 conn_itvl=40 conn_latency=0 supervision_timeout=256 encrypted=0 authenticated=0 bonded=0


[15:32:22.021] subscribe event; conn_handle=1 attr_handle=19 reason=1 prevn=0 curn=1 previ=0 curi=0

  1. 具体app功能实现可以参考BLE CentralBLE Peripheral ENC的文档。

  2. 多连接相关:

    • 对于controller层,:指示origin controller多连接资源的宏CONFIG_BT_CTLR_MAX_NUM_OF_STATES; 指示spark controller多连接资源的宏CONFIG_BT_CTLR_MAX_MST_CONNCONFIG_BT_CTLR_MAX_SLV_CONN.

    • 对于host层:MYNEWT_VAL_BLE_MAX_CONNECTIONS会影响host层的连接资源数量。

5 RAM/Flash资源使用情况

PAN107x:

RAM Size:37.84 k
Flash Size: 129.54k