標(biāo)題: NRF51822藍(lán)牙串口源碼分享 [打印本頁]

作者: zcw3726040    時間: 2018-10-1 19:36
標(biāo)題: NRF51822藍(lán)牙串口源碼分享
NRF51822 藍(lán)牙串口


單片機源程序如下:
  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. }
復(fù)制代碼

所有資料51hei提供下載:
BLE實驗4:藍(lán)牙串口.zip (14.5 MB, 下載次數(shù): 34)



作者: cnc2020    時間: 2018-12-15 18:39
good topic




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1