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

GATT read requests fail for many characteristics with nRF Connect SDK

Hello everyone,

I hope that you are all doing well during those hard times...

I am writing a code for a nRF52840. The connection is successfully established with a cycling powermeter. Three services are sucessfully discovered, according to the Cycling Power Profile from Bluetooth SIG. Then the characteristics of these profiles are also discovered. Finally, after releasing all the discovery data, I am trying to read the values of the characteristics or subscribe to notifications on some characteristics. 

Subscribing and reading both work fine as long as I am only doing 1 or 2 requests. But as soon as I am trying to read more than two characteristics (or subscribing to one and reading more than 1 characteristic), it crashes and causes a reset of the board : 

Reset logfile

My configuration is the following one : 

- zephyr pointed on tag zephyr-v2.2.0

- nRF Connect SDK pointed on v1.2.0 

I declared the bt_gatt_read_params and bt_gatt_subscribe_params struct statically as global variables : 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
// READ, SUBSCRIBE, GATT parameters
static struct bt_gatt_subscribe_params cp_measurement_subscribe_params = {
.value = BT_GATT_CCC_NOTIFY
};
static struct bt_gatt_read_params cp_features_read_params = {
.handle_count = 1,
.single.offset = 0
};
static struct bt_gatt_read_params cp_sensor_location_read_params = {
.handle_count = 1,
.single.offset = 0
};
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

They are global and filled with parameters from the discovery of services : 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Cycling power service discovered
void cp_service_found_cb(struct bt_gatt_dm *disc, void *context)
{
printk("\n[SERVICE] : Cycling Power service 0x1818 discovered succesfully.\n");
bt_gatt_dm_data_print(disc);
// Get characteristic for CP Measurement
const struct bt_gatt_attr* cp_measurement_characteristic = bt_gatt_dm_char_by_uuid(disc, BT_UUID_CP_MEASUREMENT_CHAR);
if (!cp_measurement_characteristic) {
printk("Missing CP characteristic for CP Measurement\n");
}
const struct bt_gatt_attr* cp_measurement_descriptor = bt_gatt_dm_desc_by_uuid(disc, cp_measurement_characteristic, BT_UUID_CP_MEASUREMENT_CHAR);
if (!cp_measurement_descriptor) {
printk("Missing CP descriptor for CP Measurement\n");
}
const struct bt_gatt_attr* cp_measurement_gatt_ccc_descriptor = bt_gatt_dm_desc_by_uuid(disc, cp_measurement_characteristic, BT_UUID_GATT_CCC);
if (!cp_measurement_gatt_ccc_descriptor) {
printk("Missing GATT CCC descriptor for CP Measurement\n");
}
// Fill subscribe params to CP Measurement
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

And finally they are used like that after all the services and characteristics have been discovered : 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Subscribe to characteristic notifications
int gatt_subscribe_to_notifications(struct bt_gatt_subscribe_params* params)
{
// Subscribe to characteristic
int err = bt_gatt_subscribe(conn_cpp_collector, params);
if (err) {
printk("Subscribe failed (err %d)\n", err);
}
return err;
}
// Read descriptor of a characteristic
int gatt_read_characteristic(struct bt_gatt_read_params* read_params)
{
// Read it !
int err = bt_gatt_read(conn_cpp_collector, read_params);
if(err) {
printk("Failed to read characteristic, err: %d\n", err);
}
return err;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

My prj.conf file looks like that : 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#########################################################################################
# Basics
#########################################################################################
# default configuration for the device
CONFIG_NCS_SAMPLES_DEFAULTS=y
# LEDs and buttons
CONFIG_DK_LIBRARY=y
# Enable c new library
CONFIG_NEWLIB_LIBC=y
#########################################################################################
# Memory
#########################################################################################
# nRF52840 HW properties : 1024 kB = 1MB as flash and 256 kB for SRAM
CONFIG_FLASH_SIZE=1024
CONFIG_SRAM_SIZE=256
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

If needed, I could provide more log files or code.

I hope that I was clear enough and that someone can explain me what I am doing wrong :-)

Cheers,

Sellig