You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NRF52835 BLE设备无法被发现的技术问题求助

nRF52835开发板BLE设备无法被手机发现的问题

我被一块搭载外置天线的nRF52835开发板的问题困扰了一周。安装nRF Connect SDK后,我尝试运行蓝牙示例程序:

  • 通过Segger IDE加载nRF SDK 1.7.0的示例
  • 直接使用nRF Connect SDK 2.5.0的示例

但设备始终无法被手机发现,我认为这些示例应该开箱即用,但实际并非如此。我在nRF Connect里把构建配置设为nRF52DK开发板,也试过自定义配置,都没用。LED示例能正常运行,现在我想让手机搜到这个BLE设备。

以下是我使用的NRF5 SDK代码:

#include <stdint.h>
#include <string.h>
#include "nordic_common.h"
#include "nrf.h"
#include "nrf_sdm.h"
#include "app_error.h"
#include "ble.h"
#include "ble_err.h"
#include "ble_hci.h"
#include "ble_srv_common.h"
#include "ble_advdata.h"
#include "ble_advertising.h"
#include "ble_bas.h"
#include "ble_hrs.h"
#include "ble_dis.h"
#include "ble_conn_params.h"
#include "sensorsim.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "nrf_sdh_soc.h"
#include "app_timer.h"
#include "bsp_btn_ble.h"
#include "peer_manager.h"
#include "peer_manager_handler.h"
#include "fds.h"
#include "nrf_ble_gatt.h"
#include "nrf_ble_lesc.h"
#include "nrf_ble_qwr.h"
#include "ble_conn_state.h"
#include "nrf_pwr_mgmt.h"

#include "ble_stack_config.h"

#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"


APP_TIMER_DEF(led_timer_id);                                  /**< Battery timer. */
#define LED_TIMER_INTERVAL    APP_TIMER_TICKS(500)

void led_timer_handler (void* p_context)
{
    ret_code_t err_code;
    uint8_t buff [20];
    static uint8_t count;

    bsp_board_led_invert(3);

    sprintf (buff, "led_invert %d\n", count);

    uint16_t length = strlen (buff);
                        err_code = ble_nus_data_send(&m_nus, buff, &length, m_conn_handle);
                        if ((err_code != NRF_ERROR_INVALID_STATE) &&
                            (err_code != NRF_ERROR_RESOURCES) &&
                            (err_code != NRF_ERROR_NOT_FOUND))
                        {
                            APP_ERROR_CHECK(err_code);
                        }

    count ++;
}
/**@brief Function for the Timer initialization.
 *
 * @details Initializes the timer module. This creates and starts application timers.
 */
static void timers_init(void)
{
    ret_code_t err_code;

    // Initialize timer module.
    err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);

    // Create timers.
    err_code = app_timer_create(&led_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                led_timer_handler);
    APP_ERROR_CHECK(err_code);

}



/**@brief Function for starting application timers.
 */
static void application_timers_start(void)
{
    ret_code_t err_code;

    // Start application timers.
    err_code = app_timer_start(led_timer_id, LED_TIMER_INTERVAL, NULL);
    APP_ERROR_CHECK(err_code);
}




/**@brief Function for initializing buttons and leds.
 *
 * @param[out] p_erase_bonds  Will be true if the clear bonding button was pressed to wake the application up.
 */
static void buttons_leds_init()
{
    ret_code_t err_code;
    bsp_event_t startup_event;

    err_code = bsp_init(BSP_INIT_LEDS, bsp_event_handler);
    APP_ERROR_CHECK(err_code);

    err_code = bsp_btn_ble_init(NULL, &startup_event);
    APP_ERROR_CHECK(err_code);

}


/**@brief Function for initializing the nrf log module.
 */
static void log_init(void)
{
    ret_code_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();
}


/**@brief Function for initializing power management
 */
static void power_management_init(void)
{
    ret_code_t err_code;
    err_code = nrf_pwr_mgmt_init();
    APP_ERROR_CHECK(err_code);
}


/**@brief Function for handling the idle state (main loop).
 *
 * @details If there is no pending log operation, then sleep until next the next event occurs.
 */
static void idle_state_handle(void)
{
    ret_code_t err_code;

    err_code = nrf_ble_lesc_request_handler();
    APP_ERROR_CHECK(err_code);

    if (NRF_LOG_PROCESS() == false)
    {
        nrf_pwr_mgmt_run();
    }
}


/**@brief Function for application main entry.
 */
int main(void)
{
    //bool erase_bonds;

    // Initialize.
    log_init();
    timers_init();
    buttons_leds_init();
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    advertising_init();
    services_init();

    conn_params_init();
    peer_manager_init();

    // Start execution.
    NRF_LOG_INFO("Whitelist connection example started.");
    application_timers_start();
    advertising_start();

    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}

排查与解决方案

1. 硬件与天线检查

  • 确认外置天线连接:检查天线座与开发板的连接是否牢固,可更换已知正常的天线测试
  • 验证射频引脚:确保nRF52835的ANT1/ANT2引脚未被误用作其他功能,硬件匹配网络(巴伦、电容电阻)无损坏

2. 软件配置修正

开发板配置匹配

你使用的是自定义nRF52835开发板,不能直接套用nRF52DK的配置:

  • 在nRF Connect SDK中创建自定义BSP,或修改现有配置,确保:
    • 射频引脚映射与硬件一致
    • 启用外部32MHz晶振(保证射频稳定性,内部RC精度不足可能导致广播异常)
    • 电源管理配置未禁用射频模块

广播参数验证

从日志Whitelist connection example started.推测,示例可能默认启用了白名单模式,此时仅已绑定设备能发现你的设备:

  • 修改advertising_init(),禁用白名单,或在初始化时调用pm_peers_delete_all()清除绑定信息
  • 确认广播数据中包含可发现标志:BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE,确保设备处于通用可发现模式
  • 检查广播间隔设置(推荐范围20ms~1000ms),间隔过大可能导致手机扫描遗漏

代码问题修复

你的代码中存在未定义变量:m_nus、m_conn_handle,调用ble_nus_data_send()会导致运行时异常,干扰广播流程:

  • 补全NUS服务的初始化代码,或直接删除这部分无关逻辑

3. 调试手段

  • 使用nRF Connect for Mobile的扫描日志功能,查看是否有未命名的BLE广播包(可能设备名称未配置但广播已启动)
  • 启用Segger RTT日志,查看advertising_start()、ble_stack_init()等函数的返回值,确认广播是否成功启动
  • 运行官方射频测试示例,验证发射功率、接收灵敏度是否达标,排除射频硬件故障

4. SDK版本统一

nRF SDK 1.7.0与nRF Connect SDK 2.5.0架构差异较大,建议统一使用最新稳定版nRF Connect SDK,避免版本混用导致的兼容性问题

内容的提问来源于stack exchange,提问作者m3iz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 08:24:59