I have trouble developing BLE devices with Nordic NRF5280 and SDK 15.3.
I have a device that uses a custom BLE service, And when using nRF Connect on the mobile phone, all BLE services and characteristic values can be listed.
But when using a central NRF52840 on SDK 15.3, the characteristic value UUID returned by the db discovery event BLE_GATTC_EVT_CHAR_DISC_RSP event is all 0.
This is the screen on the phone, and 0xF6D6 is the customized BLE service UUID.

I set BLE_GATT_DB_MAX_CHARS to 14, because I know there are 13 characteristic values of the Bluetooth service to be read.
I started to explore the custom BLE service (0xFD6D) in the BLE_GAP_EVT_CONNECTED event.
ret_code_t app_ble_db_discovery_start(app_ble_db_disc_t * pDisc)
{
// Initialize the service discovery database
ret_code_t err_code = ble_db_discovery_init(app_db_disc_handler);
if (err_code != NRF_SUCCESS)
{
APP_DISC_INFO("ble_db_discovery_init(), err = %s." , nrf_strerror_get(err_code));
return err_code;
}
// Register the UUIDs to be explored in order
for (uint8_t i = 0; i < pDisc->count; i++)
{
err_code = ble_db_discovery_evt_register(&pDisc->uuid[i]);
if (err_code != NRF_SUCCESS)
{
APP_DISC_ERR("ble_db_discovery_evt_register(), uuid[%d], err = 0x04X", i, err_code);
}
else
APP_DISC_INFO("ble_db_discovery_evt_register(), uuid[%d]: 0x%04X", i, pDisc->uuid[i].uuid);
}
// Save the function handles for processing search events and the total number of services that started exploration
m_service_count = pDisc->count;
APP_DISC_INFO("db discovery start, service count = %d.", m_service_count);
// Start service exploration, and return whether the startup is successful
memset(&m_db_disc, 0x00, sizeof(m_db_disc));
err_code = ble_db_discovery_start(&m_db_disc, pDisc->conn_handle);
if (err_code != NRF_SUCCESS)
{
APP_DISC_INFO("ble_db_discovery_start(), conn_handle = 0x%04X, err = %s." , pDisc->conn_handle, nrf_strerror_get(err_code));
}
return err_code;
}
I inserted a debug message in the function on_characteristic_discovery_rsp() in ble_db_discovery.c.
The modified code is as follows:
/**@brief Function for handling characteristic discovery response.
*
* @param[in] p_db_discovery Pointer to the DB Discovery structure.
* @param[in] p_ble_gattc_evt Pointer to the GATT Client event.
*/
static void on_characteristic_discovery_rsp(ble_db_discovery_t * p_db_discovery,
ble_gattc_evt_t const * p_ble_gattc_evt)
{
uint32_t err_code;
ble_gatt_db_srv_t * p_srv_being_discovered;
bool perform_desc_discov = false;
if (p_ble_gattc_evt->conn_handle != p_db_discovery->conn_handle)
{
return;
}
p_srv_being_discovered = &(p_db_discovery->services[p_db_discovery->curr_srv_ind]);
if (p_ble_gattc_evt->gatt_status == BLE_GATT_STATUS_SUCCESS)
{
ble_gattc_evt_char_disc_rsp_t const * p_char_disc_rsp_evt;
p_char_disc_rsp_evt = &(p_ble_gattc_evt->params.char_disc_rsp);
// Find out the number of characteristics that were previously discovered (in earlier
// characteristic discovery responses, if any).
uint8_t num_chars_prev_disc = p_srv_being_discovered->char_count;
// Find out the number of characteristics that are currently discovered (in the
// characteristic discovery response being handled).
uint8_t num_chars_curr_disc = p_char_disc_rsp_evt->count;
// Check if the total number of discovered characteristics are supported by this module.
if ((num_chars_prev_disc + num_chars_curr_disc) <= BLE_GATT_DB_MAX_CHARS)
{
// Update the characteristics count.
p_srv_being_discovered->char_count += num_chars_curr_disc;
NRF_LOG_WARNING("%s(): Update the characteristics count = %d.", __FUNCTION__, p_srv_being_discovered->char_count)
}
else
{
// The number of characteristics discovered at the peer is more than the supported
// maximum. This module will store only the characteristics found up to this point.
p_srv_being_discovered->char_count = BLE_GATT_DB_MAX_CHARS;
NRF_LOG_WARNING("Not enough space for characteristics associated with "
"service 0x%04X !", p_srv_being_discovered->srv_uuid.uuid);
NRF_LOG_WARNING("Increase BLE_GATT_DB_MAX_CHARS to be able to store more "
"characteristics for each service!");
}
uint32_t i;
uint32_t j;
for (i = num_chars_prev_disc, j = 0; i < p_srv_being_discovered->char_count; i++, j++)
{
NRF_LOG_WARNING("%s (): char[%d] UUID: 0x%04X.", __FUNCTION__, i, p_ble_gattc_evt->params.char_disc_rsp.chars[j].uuid.uuid);
p_srv_being_discovered->charateristics[i].characteristic =
p_char_disc_rsp_evt->chars[j];
p_srv_being_discovered->charateristics[i].cccd_handle = BLE_GATT_HANDLE_INVALID;
p_srv_being_discovered->charateristics[i].ext_prop_handle = BLE_GATT_HANDLE_INVALID;
p_srv_being_discovered->charateristics[i].user_desc_handle = BLE_GATT_HANDLE_INVALID;
p_srv_being_discovered->charateristics[i].report_ref_handle = BLE_GATT_HANDLE_INVALID;
}
ble_gattc_char_t * p_last_known_char;
p_last_known_char = &(p_srv_being_discovered->charateristics[i - 1].characteristic);
// If no more characteristic discovery is required, or if the maximum number of supported
// characteristic per service has been reached, descriptor discovery will be performed.
if ( !is_char_discovery_reqd(p_db_discovery, p_last_known_char)
|| (p_srv_being_discovered->char_count == BLE_GATT_DB_MAX_CHARS))
{
perform_desc_discov = true;
}
else
{
// Update the current characteristic index.
p_db_discovery->curr_char_ind = p_srv_being_discovered->char_count;
// Perform another round of characteristic discovery.
err_code = characteristics_discover(p_db_discovery, p_ble_gattc_evt->conn_handle);
if (err_code != NRF_SUCCESS)
{
p_db_discovery->discovery_in_progress = false;
discovery_error_evt_trigger(p_db_discovery, err_code, p_ble_gattc_evt->conn_handle);
m_pending_user_evts[0].evt.evt_type = BLE_DB_DISCOVERY_AVAILABLE;
m_pending_user_evts[0].evt.conn_handle = p_ble_gattc_evt->conn_handle;
return;
}
}
}
else
{
// The previous characteristic discovery resulted in no characteristics.
// descriptor discovery should be performed.
perform_desc_discov = true;
}
if (perform_desc_discov)
{
bool raise_discov_complete;
p_db_discovery->curr_char_ind = 0;
err_code = descriptors_discover(p_db_discovery,
&raise_discov_complete,
p_ble_gattc_evt->conn_handle);
if (err_code != NRF_SUCCESS)
{
p_db_discovery->discovery_in_progress = false;
discovery_error_evt_trigger(p_db_discovery, err_code, p_ble_gattc_evt->conn_handle);
m_pending_user_evts[0].evt.evt_type = BLE_DB_DISCOVERY_AVAILABLE;
m_pending_user_evts[0].evt.conn_handle = p_ble_gattc_evt->conn_handle;
return;
}
if (raise_discov_complete)
{
// No more characteristics and descriptors need to be discovered. Discovery is complete.
// Send a discovery complete event to the user application.
NRF_LOG_DEBUG("Discovery of service with UUID 0x%x completed with success"
" on connection handle 0x%x.",
p_srv_being_discovered->srv_uuid.uuid,
p_ble_gattc_evt->conn_handle);
discovery_complete_evt_trigger(p_db_discovery, true, p_ble_gattc_evt->conn_handle);
on_srv_disc_completion(p_db_discovery, p_ble_gattc_evt->conn_handle);
}
}
}
When i run this, The Debug message by using NRF_LOG_WARNING("%s (): char[%d] UUID: 0x%04X.", __FUNCTION__, i, p_ble_gattc_evt->params.char_disc_rsp.chars[j].uuid.uuid) is as follows:
------------------------------------------------------------------------------------------------------- <info> ble_s: ble_evt_handler(): BLE Connected role: Central, handle 0x0. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 1. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[0] UUID: 0x0000. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 2. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[1] UUID: 0x0000. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 3. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[2] UUID: 0x0000. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 4. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[3] UUID: 0x0000. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 5. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[4] UUID: 0x0000. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 6. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[5] UUID: 0x0000. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 7. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[6] UUID: 0x0000. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 8. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[7] UUID: 0x0000. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 9. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[8] UUID: 0x0000. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 10. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[9] UUID: 0x0000. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 11. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[10] UUID: 0x0000. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 12. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[11] UUID: 0x0000. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 13. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[12] UUID: 0x0000. <info> APP_DISC: app_db_disc_handler(): BLE on db disc for peripheral, handle: 0x0000. ------------------------------------------------------------------------------------------------------- <info> APP_DISC: app_db_disc_handler(): Service UUID[1]: 0xFD6D disc complete(0) <info> ble_c: ble_on_db_disc_evt(): discovery complete, Use service index: 2. <info> ble_c: ble_on_db_disc_evt(): num of characteristic: 13. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x0000. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x0000. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x0000. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x0000. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x0000. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x0000. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x0000. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x0000. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x0000. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x0000. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x0000. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x0000. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x0000. <info> ble_c: ble_on_db_disc_evt(): Service discovered at peer. <info> ble_c: ble_on_db_disc_evt(): Service handle address: 0x0007A4E5, index = 0.
In addition, I also tried to search for other customized services (0x18EF), and the characteristics of the 0x18EF service are listed correctly.
------------------------------------------------------------------------------------------------------- <info> ble_s: ble_evt_handler(): BLE Connected role: Central, handle 0x0. <info> ble_s: gatt_evt_handler(): ATT MTU updated to 23 bytes on connection 0x0 (response). <info> ble_s: gatt_evt_handler(): DLE:Data length updated to 27 on connection 0x0. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 1. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[0] UUID: 0x2AC0. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 2. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[1] UUID: 0x2AC1. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 3. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[2] UUID: 0x2AC2. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 4. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[3] UUID: 0x2AC3. <warning> ble_db_disc: on_characteristic_discovery_rsp(): Update the characteristics count = 5. <warning> ble_db_disc: on_characteristic_discovery_rsp (): char[4] UUID: 0x2AC4. <info> APP_DISC: app_db_disc_handler(): BLE on db disc for peripheral, handle: 0x0000. ------------------------------------------------------------------------------------------------------- <info> APP_DISC: app_db_disc_handler(): Service UUID[2]: 0x18EF disc complete(0) <info> ble_c: ble_on_db_disc_evt(): discovery complete, Use service index: 0. <info> ble_c: ble_on_db_disc_evt(): num of characteristic: 5. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x2AC0. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x2AC1. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x2AC2. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x2AC3. <info> ble_c: ble_on_db_disc_evt(): Characteristic Uuid: 0x2AC4. <info> ble_c: ble_on_db_disc_evt(): Service discovered at peer. <info> ble_c: ble_on_db_disc_evt(): Service handle address: 0x0007A4E5, index = 0.
My question is why NRF52840 can't get the characteristic value UUID of Bluetooth service 0xFD6D like nRF Connect on mobile phone?
please help me.