<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Long Write from central SD130 and SDK11</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/20653/long-write-from-central-sd130-and-sdk11</link><description>How to send more than 20 bytes from central to peripheral ?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 21 Mar 2017 05:20:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/20653/long-write-from-central-sd130-and-sdk11" /><item><title>RE: Long Write from central SD130 and SDK11</title><link>https://devzone.nordicsemi.com/thread/80526?ContentTypeID=1</link><pubDate>Tue, 21 Mar 2017 05:20:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce2db2e4-69e1-4be3-a17c-2109461e79b3</guid><dc:creator>Jackxl</dc:creator><description>&lt;p&gt;Solution is long write and this is example of necessary part:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void on_ble_evt(ble_evt_t * p_ble_evt)
    {

case BLE_EVT_USER_MEM_REQUEST:          
            mem_block.len = QUEUED_WRITE_BUFFER_SIZE;
            mem_block.p_mem = &amp;amp;queued_write_buffer[0];
            err_code = sd_ble_user_mem_reply(m_deufol.conn_handle, &amp;amp;mem_block);
						//simple_uart_putstring(&amp;quot;User mem request \r\n&amp;quot;);
            break;
        
        case BLE_EVT_USER_MEM_RELEASE:
						
            if ((p_ble_evt-&amp;gt;evt.common_evt.params.user_mem_release.mem_block.p_mem == mem_block.p_mem)&amp;amp;&amp;amp;(p_ble_evt-&amp;gt;evt.common_evt.params.user_mem_release.mem_block.len == mem_block.len))
            {
                //memory released do nothing. 
								//simple_uart_putstring(&amp;quot;User mem released \r\n&amp;quot;);
            }
						break;
case BLE_GATTC_EVT_WRITE_RSP:
					if(m_deufol.conn_handle != BLE_CONN_HANDLE_INVALID)
					{
						uint8_t temp_data[BYTE_NUMBER];						
						if(p_ble_evt-&amp;gt;evt.gattc_evt.params.write_rsp.handle == m_deufol.char_identification.handle 
								&amp;amp;&amp;amp; m_deufol.char_identification.uuid.uuid == BLE_DEUFOL_COMMON_CHAR_UUID)
						{
							if(p_ble_evt-&amp;gt;evt.gattc_evt.gatt_status == BLE_GATT_STATUS_ATTERR_PREPARE_QUEUE_FULL)
							{
								ble_gattc_write_params_t write_params;	
								write_params.handle = m_deufol.common_handles.value_handle;
								write_params.len = 0;
								write_params.write_op = BLE_GATT_OP_EXEC_WRITE_REQ;
								write_params.offset = 0;
								write_params.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE;
								write_params.p_value = NULL;
								err_code = sd_ble_gattc_write(m_deufol.conn_handle, &amp;amp;write_params);
								rsp_counter = 0;
							}
							else
							{
								if(p_ble_evt-&amp;gt;evt.gattc_evt.params.write_rsp.write_op == BLE_GATT_OP_PREP_WRITE_REQ)
								{								
									rsp_counter++;
									if(p_ble_evt-&amp;gt;evt.gattc_evt.gatt_status != BLE_GATT_STATUS_ATTERR_PREPARE_QUEUE_FULL)
									{									
										ble_gattc_write_params_t write_params;	
										write_params.handle = m_deufol.common_handles.value_handle;
										write_params.len = BYTE_NUMBER;								
										write_params.write_op = BLE_GATT_OP_PREP_WRITE_REQ;
										write_params.offset = rsp_counter * BYTE_NUMBER;
										write_params.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE;
										for(uint8_t index = 0;index &amp;lt; BYTE_NUMBER;index++)
											temp_data[index] = write_array[rsp_counter * BYTE_NUMBER + index];
										write_params.p_value = temp_data;
										err_code = sd_ble_gattc_write(m_deufol.conn_handle, &amp;amp;write_params);
										
									}	
								}
							}
						}
					}
					break;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;call this function first:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint32_t send_data(ble_deufol_t * p_deufol,uint16_t length,uint8_t * write_array)
{	
	uint8_t temp_data[BYTE_NUMBER];
	for(uint8_t a = 0;a&amp;lt;BYTE_NUMBER;a++)
		temp_data[a] = write_array[a];
	ble_gattc_write_params_t write_params;	
	write_params.handle = p_deufol-&amp;gt;common_handles.value_handle;
	write_params.len = length;
	write_params.write_op = BLE_GATT_OP_PREP_WRITE_REQ;
	write_params.offset = 0;
	write_params.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE;
	write_params.p_value = data;
	err_code = sd_ble_gattc_write(p_deufol-&amp;gt;conn_handle, &amp;amp;write_params);
	return err_code;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Count of sending data is depend on QUEUED_WRITE_BUFFER_SIZE. This value has to be larger than sending data.
BYTE_NUMBER = 18&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>