This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

sd_ble_gatts_characteristic_add error: NRF_ERROR_INVALID_PARAM

I'm using a nRF51422 with the s310 stack. I copied code for adding a custom service that was working with a s110 stack, and tried to add a service to the BLE in the s310. (in case you're wondering I'm using a PCA1*3 board with a nRF51422 chip). When I call sd_ble_gatts_service_add it returns a NRF_ERROR_INVALID_PARAM errror.

I'm still a novice when it comes to BLE, I'm still trying to sift through all the parameters. I'm hoping someone can look at me code and tell me where the error is coming from. Thanks in advance. Here's the code:

static uint32_t tilt_custom_name_add(ble_tilt_t * p_tilt, const ble_tilt_init_t * p_tilt_init)
{
    uint32_t            err_code;
    ble_gatts_char_md_t char_md;
    ble_gatts_attr_t    attr_char_value;
    ble_uuid_t          ble_uuid;
    ble_gatts_attr_md_t attr_md;
		ble_gatts_attr_md_t cccd_md;
	  char *							initial_cust_name = "TMB_name";
	
		memset(&cccd_md, 0, sizeof(cccd_md));

		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_USER;


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

    char_md.char_props.read   = 1;
    char_md.char_props.write  = 1;
		char_md.char_props.write_wo_resp 	= 1;
	
		char_md.char_user_desc_max_size = 9;//`CUSTOM_NAME_SZ;
	  char_md.char_user_desc_size = strlen(initial_cust_name);
    char_md.p_char_user_desc    = (uint8_t *)initial_cust_name;

    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;
		
//		#define BLE_UUID_TYPE_UNKNOWN       0x00 /**< Invalid UUID type. */
//		#define BLE_UUID_TYPE_BLE           0x01 /**< Bluetooth SIG UUID (16-bit). */
//		#define BLE_UUID_TYPE_VENDOR_BEGIN  0x02 /**< Vendor UUID types start at this index (128-bit). */
		
		ble_uuid.type = p_tilt->uuid_type;
		ble_uuid.uuid = TMB_UUID_GAP_CHARACTERISTIC_CUST_NAME;

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

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
    attr_md.vloc       = BLE_GATTS_VLOC_USER;//`BLE_GATTS_VLOC_STACK;
    attr_md.rd_auth    = 0;
    attr_md.wr_auth    = 0;
    attr_md.vlen       = 0;
   
    
    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  = strlen(initial_cust_name);
    attr_char_value.init_offs = 0;
    attr_char_value.max_len   = CUSTOM_NAME_SZ;
    attr_char_value.p_value   = (uint8_t *)initial_cust_name;

    err_code = sd_ble_gatts_characteristic_add(p_tilt->service_handle, &char_md,
                                               &attr_char_value,
                                               &p_tilt->tilt_cust_name_handles);
    if (err_code != NRF_SUCCESS)
			{
					return err_code;
			}
    return NRF_SUCCESS;
}

Any help or suggestions on where to look would be appreciated. Any question ask and I try to respond quickly.

Thanks, Clint

Related