Hi.I had been confused with parameters of sd_ble_gatts_characteristic_add( ).If I set parameters like that:
static uint8_t ast_notify_char;
..............................
{
..............................
attr_md.read_perm = p_ast_init->notify_ast_attr_md.read_perm;
attr_md.write_perm = p_ast_init->notify_ast_attr_md.write_perm;
attr_md.vloc = BLE_GATTS_VLOC_USER;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 1;
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 = 1;
attr_char_value.init_offs = 0;
attr_char_value.max_len = 20;
attr_char_value.p_value = &ast_notify_char;
return sd_ble_gatts_characteristic_add(p_ast->service_handle,
&char_md,
&attr_char_value,
&p_ast->notify_ast_handles);
}
I found RAM overflow after I had called notify_character( ) for sending 19 bytes.But if I set parameters like that it won't happen.
static uint8_t ast_notify_char[20];
...................................
{
...............................
attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = 20;
attr_char_value.init_offs = 0;
attr_char_value.max_len = 20;
attr_char_value.p_value = ast_notify_char;
.........................
}
uint32_t notify_character( uint16_t notify_len, uint8_t *notifyTemp )
{
uint32_t err_code;
if( ast_app_handle.conn_handle != BLE_CONN_HANDLE_INVALID )
{
ble_gatts_hvx_params_t notify_params;
notify_params.handle = ast_app_handle.notify_ast_handles.value_handle;
notify_params.offset = 0;
notify_params.type = BLE_GATT_HVX_NOTIFICATION;
notify_params.p_len = ¬ify_len;
notify_params.p_data = notifyTemp;
err_code = sd_ble_gatts_hvx( ast_app_handle.conn_handle, ¬ify_params );
}
else
{
err_code = NRF_ERROR_INVALID_STATE;
}
return err_code;
}