This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Custome BLE Service - nRF52840 SDK 16

Hi everyone,

I am using the nRF52840 and SDK 16. Following THIS tutorial was able to create my BLE custom service and see my service with the custom UUID.

The problem is when I am trying to advertise the UUID. When I add my service (BLE_UUID_OUR_SERVICE) into m_adv_uuids[] my device is not discoverable at all and the debug terminal returns a Fatal error

static ble_uuid_t m_adv_uuids[] = /**< Universally unique service identifiers. */
    {
        {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE},
        {BLE_UUID_OUR_SERVICE, BLE_UUID_TYPE_VENDOR_BEGIN}
        };

This is the .h file

#ifndef IMU_SERVICE
#define IMU_SERVICE


#include <stdint.h>
#include "ble.h"
#include "ble_srv_common.h"

#define BLE_UUID_OUR_BASE_UUID {0x3c, 0xad, 0x14, 0x15, 0x59, 0xa2, 0x40, 0xb2, 0xb6, 0x46, 0xe9, 0xdc, 0x19, 0x1c, 0xfe, 0x86} //128bit base UUID
#define BLE_UUID_OUR_SERVICE 0xABCD



typedef  struct{

uint16_t service_handle;

}ble_os_t;


void our_service_init(ble_os_t *p_our_service);


#endif

This is my .c file

#include "IMU_Service.h"
#include "SEGGER_RTT.h"
#include "app_error.h"
#include "ble_srv_common.h"
#include <stdint.h>
#include <string.h>

void our_service_init(ble_os_t *p_our_service) {

  uint32_t err_code;
  ble_uuid_t service_uuid;                                       // Create a variable to hold our 16bit UUID
  ble_uuid128_t base_uuid = BLE_UUID_OUR_BASE_UUID;                       // Create a variable to hold our 128bit UUID and assign the variable
  service_uuid.uuid = BLE_UUID_OUR_SERVICE;                               // Assign our 16bit UUID to the variable
  err_code = sd_ble_uuid_vs_add(&base_uuid, &service_uuid.type); // Add your custom base UUID (vendor specific) to the BLE stack's table
  APP_ERROR_CHECK(err_code);

  //The sd_ble_gatts_service_add() function will create a table containing our services and the service_handle is simply an index pointing to our particular service in the table.
  err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, // We specify the we want a primary service
      &service_uuid,                                               // Pointer to our 16bit service UUID
      &p_our_service->service_handle);
  APP_ERROR_CHECK(err_code);

  SEGGER_RTT_WriteString(0, "Executing our_service_init().\n");
  SEGGER_RTT_printf(0, "Service UUID: 0x%#04x\n", service_uuid.uuid);
  SEGGER_RTT_printf(0, "Service UUID type: 0x%#02x\n", service_uuid.type);
  SEGGER_RTT_printf(0, "Service handle: 0x%#04x\n", p_our_service->service_handle);
}

Also, I configured the RAM size and start address for the new service. I have also set the NRF_SDH_BLE_VS_UUID_COUNT 1

Do I miss something?

Parents Reply Children
No Data
Related