<?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>Can only write two bytes when length says 7 bytes</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/5525/can-only-write-two-bytes-when-length-says-7-bytes</link><description>I&amp;#39;m trying to write 7 bytes (0x01 02 03 04 05 06 07) to my nrf51 Dongle with my own custom service running based on the Battery Service. 
 The problem is that I can only access the first two bytes 0x01 and 0x02 in the memory. But the length when I read</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 11 Feb 2015 08:22:50 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/5525/can-only-write-two-bytes-when-length-says-7-bytes" /><item><title>RE: Can only write two bytes when length says 7 bytes</title><link>https://devzone.nordicsemi.com/thread/19323?ContentTypeID=1</link><pubDate>Wed, 11 Feb 2015 08:22:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dbb892bd-83e1-4c32-a3b0-f7195233da05</guid><dc:creator>michaeld</dc:creator><description>&lt;p&gt;That was indeed the problem thank you very much for helping me! This is how I solved it now:&lt;/p&gt;
&lt;p&gt;The on_write function is like this now:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void on_write(ble_sens_t * p_sens, ble_evt_t * p_ble_evt)
{		
   ble_gatts_evt_write_t * p_evt_write = &amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.write; 
	 if(p_evt_write-&amp;gt;handle == p_sens-&amp;gt;config_handle.value_handle || p_evt_write-&amp;gt;handle == p_sens-&amp;gt;step_data_handle.value_handle)
	 {
			p_sens-&amp;gt;evt_handler(p_sens, p_evt_write);
	 }    
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The evt_handler function is like this now:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void evt_handler(ble_sens_t * p_sens, ble_gatts_evt_write_t  * p_evt_write)
{	
 if (p_evt_write-&amp;gt;handle == p_sens-&amp;gt;config_handle.value_handle )
   {			  
			m_config.toggle_settings = p_evt_write-&amp;gt;data[0];
		 	m_config.seconds = p_evt_write-&amp;gt;data[1];
		 	m_config.minutes = p_evt_write-&amp;gt;data[2];
		 	m_config.hours = p_evt_write-&amp;gt;data[3];
		 	m_config.day = p_evt_write-&amp;gt;data[4];
		 	m_config.month = p_evt_write-&amp;gt;data[5];
		 	m_config.year = p_evt_write-&amp;gt;data[6];	    
	 }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And the handler typedef is like this now:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;typedef void (*ble_sens_evt_handler_t) (ble_sens_t * p_sens, ble_gatts_evt_write_t * evt_write);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can only write two bytes when length says 7 bytes</title><link>https://devzone.nordicsemi.com/thread/19322?ContentTypeID=1</link><pubDate>Tue, 10 Feb 2015 17:00:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:875dffd7-5e4f-4556-8ae8-26bf8c01bb54</guid><dc:creator>Alex</dc:creator><description>&lt;p&gt;p_evt_write in on_write() is already pointer and you are passing pointer of the pointer to p_sens-&amp;gt;evt_handler(). It is difficult to see from second part of the code how p_evt_write defined. If you call  p_sens-&amp;gt;evt_handler(p_sens, p_evt_write); without *, then inside the handler data can be accessible p_evt_write-&amp;gt;data[0] but need to define p_evt_write correctly as well&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>