nrf51822 --- 修改蓝牙名字

1.目的

   修改蓝牙的名字

2.分析

  蓝牙名字最长设置为20个字节,超过20个字节为无效

3.平台:

协议栈版本:SDK10.0.0

编译软件:keil 5.14

硬件平台:nrf51822最小系统

例子:SDK 10.0.0\examples\ble_peripheral\ble_app_uart\pca10028\s110\arm4

4.步骤

首先,要知道设置名字的API :


在ble_gap.h

   /**@brief Set GAP device name.
 *
 * @param[in] p_write_perm Write permissions for the Device Name characteristic, see @ref ble_gap_conn_sec_mode_t.
 * @param[in] p_dev_name Pointer to a UTF-8 encoded, non NULL-terminated string.
 * @param[in] len Length of the UTF-8, non NULL-terminated string pointed to by p_dev_name in octets (must be smaller or equal than @ref BLE_GAP_DEVNAME_MAX_LEN).
 *
 * @retval ::NRF_SUCCESS GAP device name and permissions set successfully.
 * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
 * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
 */
SVCALL(SD_BLE_GAP_DEVICE_NAME_SET, uint32_t, sd_ble_gap_device_name_set(ble_gap_conn_sec_mode_t const *p_write_perm, uint8_t const *p_dev_name, uint16_t len));

static void SetDeviceName(unsigned char *name ,unsigned char size)
{
 uint32_t                err_code;
//  uint8_t namebuffer[10] = {'a','b','c','d'};
        ble_gap_conn_sec_mode_t sec_mode;
      BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);

      err_code = sd_ble_gap_device_name_set(&sec_mode,
                                               (const uint8_t *)name,
size);
    APP_ERROR_CHECK(err_code);
    advertising_init();
}

 sd_ble_gap_device_name_set()返回 NRF_SUCCESS  表示成功。

 


你可能感兴趣的:(nordic,nrf51822,蓝牙4.0)