<?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>Sending 2-bytes value from Central to Peripheral</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14989/sending-2-bytes-value-from-central-to-peripheral</link><description>Hey, 
 I would like to send data from Central to Peripheral. I follow by ble_app_uart example, however I need to send a float type variable, so I split it to the total and fractional part. 
 For example,
my variable is 3.14. I call ble_nus_c_string_send</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 06 Jul 2016 22:47:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14989/sending-2-bytes-value-from-central-to-peripheral" /><item><title>RE: Sending 2-bytes value from Central to Peripheral</title><link>https://devzone.nordicsemi.com/thread/57201?ContentTypeID=1</link><pubDate>Wed, 06 Jul 2016 22:47:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b8c4639f-e698-43d9-a353-dfe853c1fbf6</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;Mark the answer as accepted in that case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending 2-bytes value from Central to Peripheral</title><link>https://devzone.nordicsemi.com/thread/57200?ContentTypeID=1</link><pubDate>Wed, 06 Jul 2016 18:03:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb566def-a446-427c-a14f-e08ba0c34e66</guid><dc:creator>octopus</dc:creator><description>&lt;p&gt;Thanks, now it works as expected&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending 2-bytes value from Central to Peripheral</title><link>https://devzone.nordicsemi.com/thread/57199?ContentTypeID=1</link><pubDate>Wed, 06 Jul 2016 15:29:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0047cbde-06a4-475e-8ea9-067949cfd10d</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;You don&amp;#39;t have to split the float up if you don&amp;#39;t want to.  You could send all four bytes of the float in one go.  After all &lt;code&gt;ble_nus_string_send()&lt;/code&gt; can send 20 bytes in one go.  The way I would do it is bit masking so you cover up and isolate three bytes while putting one byte of the float into the array to send.  So do this:&lt;/p&gt;
&lt;p&gt;Set up your array to send &lt;code&gt;uint8_t data_to_send_array[4] = { 0 }&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Next get your &lt;code&gt;float_value&lt;/code&gt; and do this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;data_to_send_array[0] = (float_value &amp;amp; 0xFF000000) &amp;gt;&amp;gt; 24;
data_to_send_array[1] = (float_value &amp;amp; 0x00FF0000) &amp;gt;&amp;gt; 16;
data_to_send_array[2] = (float_value &amp;amp; 0x0000FF00) &amp;gt;&amp;gt; 8;
data_to_send_array[3] = (float_value &amp;amp; 0x000000FF);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then call &lt;code&gt;ble_nus_string_send(&amp;amp;m_nus, data_to_send_array , 4)&lt;/code&gt; and you will be good.&lt;/p&gt;
&lt;p&gt;Else if you want to split the bifurcate your float into separate values apply the same principle above to each byte size of the new values.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>