找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2630|回复: 1
收起左侧

NRF51822蓝牙串口源码分享

[复制链接]
ID:404708 发表于 2018-10-1 19:36 | 显示全部楼层 |阅读模式
NRF51822 蓝牙串口
0.png

单片机源程序如下:
  1. /* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */

  12. #include <stdint.h>
  13. #include "app_error.h"
  14. #include "ble_dtm_app.h"
  15. #include "ble_serialization.h"
  16. #include "nrf_error.h"
  17. #include "ser_config.h"
  18. #include "ser_hal_transport.h"
  19. #include "ser_sd_transport.h"


  20. static uint32_t dtm_init_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  21. {
  22.     uint32_t result_code;

  23.     const uint32_t err_code = ble_dtm_init_rsp_dec(p_buffer, length, &result_code);
  24.     APP_ERROR_CHECK(err_code);

  25.     return result_code;
  26. }


  27. uint32_t ble_dtm_init(app_uart_stream_comm_params_t * p_uart_comm_params)
  28. {
  29.     if (p_uart_comm_params == NULL)
  30.     {
  31.         return NRF_ERROR_NULL;
  32.     }
  33.    
  34.     uint32_t err_code = NRF_SUCCESS;
  35.     uint32_t index = 0;
  36.    
  37.     uint8_t * p_tx_buf = NULL;
  38.     uint32_t tx_buf_len = 0;

  39.     err_code = ser_hal_transport_tx_pkt_alloc(&p_tx_buf, (uint16_t *)&tx_buf_len);
  40.     if (err_code != NRF_SUCCESS)
  41.     {
  42.         return err_code;
  43.     }

  44.     p_tx_buf[index++] = SER_PKT_TYPE_DTM_CMD;
  45.     tx_buf_len -= SER_PKT_TYPE_SIZE;

  46.     err_code = ble_dtm_init_req_enc(p_uart_comm_params, &(p_tx_buf[SER_PKT_TYPE_SIZE]), &tx_buf_len);
  47.     if (err_code == NRF_SUCCESS)
  48.     {
  49.         tx_buf_len += SER_PKT_TYPE_SIZE;

  50.         err_code = ser_sd_transport_cmd_write(p_tx_buf, tx_buf_len, dtm_init_rsp_dec);
  51.         if (err_code != NRF_SUCCESS)
  52.         {
  53.             err_code = NRF_ERROR_INTERNAL;
  54.         }
  55.     }
  56.     else
  57.     {
  58.         err_code = NRF_ERROR_INTERNAL;
  59.     }

  60.     return err_code;
  61. }
复制代码

所有资料51hei提供下载:
BLE实验4:蓝牙串口.zip (14.5 MB, 下载次数: 34)
回复

使用道具 举报

ID:68875 发表于 2018-12-15 18:39 | 显示全部楼层
good topic
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表