NRF52832 BLE device discovery issue

152 views Asked by At

I've been struggling with a board issue for a week now. I'm using the nRF52835 with an external antenna. I'm trying to run an example after installing the nRF Connect SDK. I've loaded various Bluetooth examples from both the nRF SDK (via Segger IDE) and the nRF Connect SDK, but the device is not being discovered. In my understanding, both examples should work out of the box, but unfortunately, they don't. I've uploaded the projects to the cloud. Link to the files https://drive.google.com/file/d/15gjsuDHun9xgwL13yR_y65k9e1L3tR-k/view?usp=sharing (Versions: NRF SDK 1.7.0, nrf-connect sdk 2.5.0)

When using nRF Connect, I've set the build configuration to the nRF52DK board and tried creating a custom one, but neither option worked. LED examples are working fine. I'm trying to find a BLE device with my phone.

NRF5 SDK code i`m using:

#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

There are 1 answers

0
Sigurd Hellesvik On BEST ANSWER

The Bluetooth Low Energy samples should work out of the box, as you say. And if the LED samples work as expected, it is fair to assume that soldering and programming fine. In this case, there are two main suspects for what went wrong: Either there is something wrong with the hardware of your custom board. Or the software is not properly configured for the hardware.

The first point is the easiest to check. Nordic Semiconductor provide free reviews of schematics and hardware over at https://devzone.nordicsemi.com/, so I suggest that you create a private ticket on that site and ask for a review.

Then if the hardware looks good, it is time to look closer at the software.