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

Error while configuring cccd metadata, in ble-characteristics-a-beginners-tutorial

I'm using nRF52840 with SDK15.0.0

Following this tutorial : https://devzone.nordicsemi.com/tutorials/b/bluetooth-low-energy/posts/ble-characteristics-a-beginners-tutorial

AT STEP 2.H my module is Advertising i can connect and then see the service and its characteristics write and read with nRF connect app.

Then at  next  step :STEP 3.A, i add : 

		BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
		BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
		cccd_md.vloc                = BLE_GATTS_VLOC_STACK;
		char_md.p_cccd_md           = &cccd_md;
		char_md.char_props.notify   = 1;

Here is problem : there is err_code 0x07 in return from sd_ble_gatts_characteristic_add, and no more advertising.

if i comment APP_ERROR_CHECK where err_code = 0x07, i can see my module advertising but i don't see the service and its characteritics

I tryed to use solutions file, but i get same problem...

Parents Reply
  • Hi Geoffroy,

    Please don't change the header files. It would make it impossible for you to keep track of which values you are using then. The correct values are

    /** @defgroup BLE_GATTS_VLOCS GATT Value Locations
     * @{ */
    #define BLE_GATTS_VLOC_INVALID       0x00  /**< Invalid Location. */
    #define BLE_GATTS_VLOC_STACK         0x01  /**< Attribute Value is located in stack memory, no user memory is required. */
    #define BLE_GATTS_VLOC_USER          0x02  /**< Attribute Value is located in user memory. This requires the user to maintain a valid buffer through the lifetime of the attribute, since the stack
                                                    will read and write directly to the memory using the pointer provided in the APIs. There are no alignment requirements for the buffer. */

    If you want the attribute data stored in the stack memory you set

    	cccd_md.vloc                = BLE_GATTS_VLOC_STACK;

    instead of having to set it to 0x01.

    If you want the attribute data stored in user memory you set

    	cccd_md.vloc                = BLE_GATTS_VLOC_USER;

    instead of having to set it to 0x02.

    Does this makes sense? You are not suppose to change the header files, just use them for reference.

    When you changed the macro for BLE_GATTS_VLOCK_STACK to 0x02, you were actually defining the attribute value location to be BLE_GATTS_VLOCK_USER.

    As you can read from the comments in the header file if you choose BLE_GATTS_VLOCK_USER the attribute value is located in user memory, but this requires the user to mantain a valid buffer through the lifetime of the attribute and you need to store the data in the buffer yourself, so this was why the example was not working.

    Best regards,

    Marjeris

Children
Related