Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf52 DK is On but Not Advertising

Hello, I was successful in using Arduino headers/ libraries to program my nRF52 DK, but now I am attempting to recreate the project in Segger V5.34 for MacOS for potential mass production. I am using the ble_app_template example from the nRF52 SDK 17.0.2 and I am following this tutorial. (The only deviation was that I named the variables differently) I was on Step 4 before issues arrived. However, when I build and run everything, nothing is advertised. I also wanted to add that I am new to Segger, but I understand C pretty well. I have already flashed the S132 SoftDevice (At least, I'm pretty sure) This nRF52 DK was advertising perfectly fine when I used Arduino, so the board works. There just seems to be an issue with my code or configurations, because when I hit 'Build and Run' the board is on but nothing happens. It's also worth mentioning that the PWM examples work perfectly fine. Thank you for all the examples, by the way. They're very helpful. Thanks in advance!

from main.src

int main(void)
{
    bool erase_bonds;

    // Initialize.
    log_init();
    timers_init();
    buttons_leds_init(&erase_bonds);
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init(); //Services comes first, just like the tutorial
    advertising_init();
    conn_params_init();
    peer_manager_init();

    // Start execution.
    NRF_LOG_INFO("Template example started.");
    application_timers_start();

    advertising_start(erase_bonds);

    
    NRF_LOG_INFO("Lig started.");
   

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

ble_cus.h

// from ble_cus.c
#include "sdk_common.h"
#include "ble_srv_common.h"
#include "ble_cus.h"
#include <string.h>
#include "nrf_gpio.h"
#include "boards.h"
#include "nrf_log.h"

/**@brief Function for initializing the Custom Service.
 *
 * @param[out]  p_cus       Custom Service structure. This structure will have to be supplied by
 *                          the application. It will be initialized by this function, and will later
 *                          be used to identify this particular service instance.
 * @param[in]   p_cus_init  Information needed to initialize the service.
 *
 * @return      NRF_SUCCESS on successful initialization of service, otherwise an error code.
 */
uint32_t ble_cus_init(ble_cus_t * p_cus, const ble_cus_init_t * p_cus_init);


/**@brief Function for adding the Custom Value characteristic.
 *
 * @param[in]   p_cus        Custom Service structure.
 * @param[in]   p_cus_init   Information needed to initialize the service.
 *
 * @return      NRF_SUCCESS on success, otherwise an error code.
 */
static uint32_t LED_char_add(ble_cus_t * p_cus, const ble_cus_init_t * p_cus_init)
{
    uint32_t            err_code;
    ble_gatts_char_md_t char_md;
    ble_gatts_attr_md_t cccd_md;
    ble_gatts_attr_t    attr_char_value;
    ble_uuid_t          ble_uuid;
    ble_gatts_attr_md_t attr_md;
    memset(&char_md, 0, sizeof(char_md));

    char_md.char_props.read   = 1;
    char_md.char_props.write  = 1;
    char_md.char_props.notify = 0; 
    char_md.p_char_user_desc  = NULL;
    char_md.p_char_pf         = NULL;
    char_md.p_user_desc_md    = NULL;
    char_md.p_cccd_md         = NULL; 
    char_md.p_sccd_md         = NULL;

    memset(&attr_md, 0, sizeof(attr_md));

    attr_md.read_perm  = p_cus_init->LED_char_attr_md.read_perm;
    attr_md.write_perm = p_cus_init->LED_char_attr_md.write_perm;
    attr_md.vloc       = BLE_GATTS_VLOC_STACK;
    attr_md.rd_auth    = 0;
    attr_md.wr_auth    = 0;
    attr_md.vlen       = 0;

     ble_uuid.type = p_cus->uuid_type;
    ble_uuid.uuid = LedCharUUID;

    memset(&attr_char_value, 0, sizeof(attr_char_value));

    attr_char_value.p_uuid    = &ble_uuid;
    attr_char_value.p_attr_md = &attr_md;
    attr_char_value.init_len  = sizeof(uint8_t);
    attr_char_value.init_offs = 0;
    attr_char_value.max_len   = sizeof(uint8_t);
    err_code = sd_ble_gatts_characteristic_add(p_cus->service_handle, &char_md,
                                               &attr_char_value,
                                               &p_cus->LED_value_handles);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    return NRF_SUCCESS;
}



uint32_t ble_cus_init(ble_cus_t * p_cus, const ble_cus_init_t * p_cus_init)
{
    if (p_cus == NULL || p_cus_init == NULL)
    {
        return NRF_ERROR_NULL;
    }

    uint32_t   err_code;
    ble_uuid_t ble_uuid;

    //Initialize service structure
p_cus->conn_handle               = BLE_CONN_HANDLE_INVALID;

ble_uuid128_t base_uuid = {LigService_UUID_BASE};
err_code =  sd_ble_uuid_vs_add(&base_uuid, &p_cus->uuid_type);
VERIFY_SUCCESS(err_code);

ble_uuid.type = p_cus->uuid_type;
ble_uuid.uuid = LigServiceUUID;

err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_cus->service_handle);
if (err_code != NRF_SUCCESS)
{
    return err_code;
}
//Add custom characteristic
return LED_char_add(p_cus, p_cus_init);
}

ble_cus.c

//From ble_cus.h
#include <stdint.h>
#include <stdbool.h>
#include "ble.h"
#include "ble_srv_common.h"

#define LigService_UUID_BASE         {0xBC, 0x8A, 0xBF, 0x45, 0xCA, 0x05, 0x50, 0xBA, \
                                          0x40, 0x42, 0xB0, 0x00, 0xC9, 0xAD, 0x64, 0xF3}

#define LigServiceUUID               0x1400
#define LedCharUUID            0x1401
//#define ColorCharUUID            0x1402

/**@brief   Macro for defining a ble_cus instance.
 *
 * @param   _name   Name of the instance.
 * @hideinitializer
 */
#define BLE_CUS_DEF(_name)                                                                          \
static ble_cus_t _name;    

/**@brief Custom Service init structure. This contains all options and data needed for
 *        initialization of the service.*/
typedef struct
{
    uint8_t                       initial_LED_value;           /**< Initial custom value */
    ble_srv_cccd_security_mode_t  LED_char_attr_md;     /**< Initial security level for Custom characteristics attribute */
} ble_cus_init_t;

/**@brief Custom Service structure. This contains various status information for the service. */
struct ble_cus_s
{
    uint16_t                      service_handle;                 /**< Handle of Custom Service (as provided by the BLE stack). */
    ble_gatts_char_handles_t      LED_value_handles;           /**< Handles related to the Custom Value characteristic. */
    uint16_t                      conn_handle;                    /**< Handle of the current connection (as provided by the BLE stack, is BLE_CONN_HANDLE_INVALID if not in a connection). */
    uint8_t                       uuid_type; 
};

// Forward declaration of the ble_cus_t type.
typedef struct ble_cus_s ble_cus_t;

services_init() in main.c

static void services_init(void)
{
   /* YOUR_JOB: Add code to initialize the services used by the application.*/
    ret_code_t                         err_code;
    ble_cus_init_t                     cus_init;

     // Initialize CUS Service init structure to zero.
    memset(&cus_init, 0, sizeof(cus_init));
	
    err_code = ble_cus_init(&m_cus, &cus_init);
    APP_ERROR_CHECK(err_code);	
    
}

Parents
  • Hello jasonterance,

    Thank you for all the examples, by the way. They're very helpful. Thanks in advance!

    No problem at all, I am happy to hear that you have found the examples very helpful!

    However, when I build and run everything, nothing is advertised.

    Could you elaborate on this a bit further? Are you seeing anything output to your logger backend when you run the program?
    Does the device reset at any point, or does it seem unresponsive / stuck when you run your program?
    Could you also verify for me that you have defined DEBUG in your preprocessor defines, like shown in the included image?

    This will produce a detailed error message to the logger output in the case that an error code != NRF_SUCCESS is passed to an APP_ERROR_CHECK, instead of just resetting the device right away(which is the default error handling).

    I suspect that something might have gone wrong during your services declaration, and that the device thus never gets passed that part in your code. If this is the case you should see an output to your logger backend when this occurs.

    I have already flashed the S132 SoftDevice (At least, I'm pretty sure)

    The SDK examples for SES are all configured to flash the SoftDevice as well, so I too would think that this is covered since you are using the BLE template example as your foundation.

    Looking forward to resolving this issue together!

    Best regards,
    Karl

Reply
  • Hello jasonterance,

    Thank you for all the examples, by the way. They're very helpful. Thanks in advance!

    No problem at all, I am happy to hear that you have found the examples very helpful!

    However, when I build and run everything, nothing is advertised.

    Could you elaborate on this a bit further? Are you seeing anything output to your logger backend when you run the program?
    Does the device reset at any point, or does it seem unresponsive / stuck when you run your program?
    Could you also verify for me that you have defined DEBUG in your preprocessor defines, like shown in the included image?

    This will produce a detailed error message to the logger output in the case that an error code != NRF_SUCCESS is passed to an APP_ERROR_CHECK, instead of just resetting the device right away(which is the default error handling).

    I suspect that something might have gone wrong during your services declaration, and that the device thus never gets passed that part in your code. If this is the case you should see an output to your logger backend when this occurs.

    I have already flashed the S132 SoftDevice (At least, I'm pretty sure)

    The SDK examples for SES are all configured to flash the SoftDevice as well, so I too would think that this is covered since you are using the BLE template example as your foundation.

    Looking forward to resolving this issue together!

    Best regards,
    Karl

Children
No Data
Related