<?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>Help converting some Adafruit Arduino code to embedded C</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/30845/help-converting-some-adafruit-arduino-code-to-embedded-c</link><description>I have some functional code working on an Adafruit nRF52 Feather board which I am trying to change over to run in embedded C on an nRF51 dongle. I am using Adafruit nRF52 feather library in the Arduino IDE. I have pulled out the below code from the Arduino</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 05 Mar 2018 12:01:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/30845/help-converting-some-adafruit-arduino-code-to-embedded-c" /><item><title>RE: Help converting some Adafruit Arduino code to embedded C</title><link>https://devzone.nordicsemi.com/thread/122810?ContentTypeID=1</link><pubDate>Mon, 05 Mar 2018 12:01:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dffd4367-9d36-4924-96fd-90e51939610c</guid><dc:creator>Mttrinh</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Have a look at the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.2.0/ble_sdk_app_nus_eval.html?cp=4_0_0_4_2_2_22" rel="noopener noreferrer" target="_blank"&gt;ble_app_uart example&lt;/a&gt; in the SDK, expecially this function&amp;nbsp;ble_nus_init(&amp;amp;m_nus, &amp;amp;nus_init). You can see how two characteristics are being added(RX and TX).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Help converting some Adafruit Arduino code to embedded C</title><link>https://devzone.nordicsemi.com/thread/122019?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2018 01:15:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d8c1caf-33e2-4422-a35e-0b9322360951</guid><dc:creator>william--</dc:creator><description>&lt;p&gt;Hi Matt, I had gone through the examples and was getting lost with creating multiple characteristics. I had derived the code below to add BLETestChar1 but was not sure what was required to add the additional characteristics and I can not find an example that helps me understand what I am doing. Edit of Arduino code and C function below:&lt;/p&gt;
&lt;p&gt;Arduino Code to create service and 4 characteristics:&lt;/p&gt;
&lt;p&gt;uint8_t BLETestServ1[] = &lt;br /&gt;{ &lt;br /&gt; 0x00, 0x00, 0xaa, 0xa0, 0x00, 0x00, 0x10, 0x00, &lt;br /&gt; 0x80, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, &lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;uint8_t BLETestChar1[] = &lt;br /&gt;{ &lt;br /&gt; 0x00, 0x00, 0xaa, 0xa1, 0x00, 0x00, 0x10, 0x00, &lt;br /&gt; 0x80, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, &lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;uint8_t BLETestChar2[] = &lt;br /&gt;{ &lt;br /&gt; 0x00, 0x00, 0xaa, 0xa2, 0x00, 0x00, 0x10, 0x00, &lt;br /&gt; 0x80, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, &lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;uint8_t BLETestChar3[] = &lt;br /&gt;{ &lt;br /&gt; 0x00, 0x00, 0xaa, 0xa3, 0x00, 0x00, 0x10, 0x00, &lt;br /&gt; 0x80, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, &lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;uint8_t BLETestChar4[] = &lt;br /&gt;{ &lt;br /&gt; 0x00, 0x00, 0xaa, 0xa4, 0x00, 0x00, 0x10, 0x00, &lt;br /&gt; 0x80, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, &lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BLEService myService = BLEService(BLETestServ1);&lt;br /&gt;BLECharacteristic test1 = BLECharacteristic(BLETestChar1);&lt;br /&gt;BLECharacteristic test2 = BLECharacteristic(BLETestChar2);&lt;br /&gt;BLECharacteristic test3 = BLECharacteristic(BLETestChar3);&lt;br /&gt;BLECharacteristic test4 = BLECharacteristic(BLETestChar4);&lt;/p&gt;
&lt;p&gt;void setupBLE(void)&lt;br /&gt;{&lt;br /&gt; &lt;br /&gt; myService.begin();&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; test1.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE | CHR_PROPS_NOTIFY);&lt;br /&gt; test1.setPermission(SECMODE_OPEN, SECMODE_OPEN);&lt;br /&gt; test1.setMaxLen(5);&lt;br /&gt; test1.setStringDescriptor(&amp;quot;&amp;quot;);&lt;br /&gt; test1.begin();&lt;br /&gt; test1.write(&amp;quot;none&amp;quot;);&lt;br /&gt; &lt;br /&gt; test2.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE | CHR_PROPS_NOTIFY);&lt;br /&gt; test2.setPermission(SECMODE_OPEN, SECMODE_OPEN);&lt;br /&gt; test2.setMaxLen(20);&lt;br /&gt; test2.setStringDescriptor(&amp;quot;&amp;quot;);&lt;br /&gt; test2.begin();&lt;br /&gt; test2.write(&amp;quot;none&amp;quot;);&lt;br /&gt; &lt;br /&gt; test3.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE | CHR_PROPS_NOTIFY);&lt;br /&gt; test3.setPermission(SECMODE_OPEN, SECMODE_OPEN);&lt;br /&gt; test3.setMaxLen(20);&lt;br /&gt; test3.setStringDescriptor(&amp;quot;&amp;quot;);&lt;br /&gt; test3.begin();&lt;br /&gt; test3.write(&amp;quot;none&amp;quot;);&lt;/p&gt;
&lt;p&gt;##########################################################################################################&lt;/p&gt;
&lt;p&gt;#define BLETestServ1 {{0x00, 0x00, 0xaa, 0xa0, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}} /// 128b UUID&lt;/p&gt;
&lt;p&gt;#define BLETestChar1 {{0x00, 0x00, 0xaa, 0xa1, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}} /// 128b UUID&lt;br /&gt;#define BLETestChar2 {{0x00, 0x00, 0xaa, 0xa2, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}} /// 128b UUID &lt;br /&gt;#define BLETestChar3 {{0x00, 0x00, 0xaa, 0xa3, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}} /// 128b UUID&lt;/p&gt;
&lt;p&gt;static uint32_t test_char_add(ble_ts_t * p_test_service)&lt;br /&gt;{&lt;br /&gt; uint32_t err_code=0;&lt;br /&gt; ble_uuid_t char_uuid;&lt;br /&gt; ble_uuid128_t service_uuid = BLETestServ1;&lt;br /&gt; char_uuid.uuid = BLETestChar1;&lt;br /&gt; sd_ble_uuid_vs_add(&amp;amp;base_uuid, &amp;amp;char_uuid.type);&lt;br /&gt; &lt;br /&gt; &lt;br /&gt; &lt;br /&gt; ble_gatts_char_md_t char_md;&lt;br /&gt; memset(&amp;amp;char_md, 0, sizeof(char_md));&lt;br /&gt; char_md.char_props.read=1;&lt;br /&gt; char_md.char_props.write=1;&lt;br /&gt; &lt;br /&gt; &lt;br /&gt; ble_gatts_attr_md_t cccd_md;&lt;br /&gt; memset(&amp;amp;cccd_md, 0, sizeof(cccd_md));&lt;br /&gt; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;cccd_md.read_perm);&lt;br /&gt; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;cccd_md.write_perm);&lt;br /&gt; cccd_md.vloc = BLE_GATTS_VLOC_STACK;&lt;br /&gt; char_md.char_props.notify =1;&lt;br /&gt; &lt;br /&gt; ble_gatts_attr_md_t attr_md;&lt;br /&gt; memset(&amp;amp;attr_md, 0, sizeof(attr_md));&lt;br /&gt; attr_md.vloc = BLE_GATTS_VLOC_STACK;&lt;br /&gt; &lt;br /&gt; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;attr_md.read_perm);&lt;br /&gt; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;attr_md.write_perm);&lt;br /&gt; &lt;br /&gt; ble_gatts_attr_t attr_char_value;&lt;br /&gt; memset(&amp;amp;attr_char_value, 0, sizeof(attr_char_value));&lt;br /&gt; attr_char_value.p_uuid = &amp;amp;char_uuid;&lt;br /&gt; attr_char_value.p_attr_md = &amp;amp;attr_md;&lt;br /&gt; &lt;br /&gt; attr_char_value.max_len = 4;&lt;br /&gt; attr_char_value.init_len = 4;&lt;br /&gt; uint8_t value[4] = {0x12,0x34,0x56,0x78};&lt;br /&gt; attr_char_value.p_value = value;&lt;/p&gt;
&lt;p&gt;err_code = sd_ble_gatts_characteristic_add(p_test_service-&amp;gt;service_handle,&lt;br /&gt; &amp;amp;char_md,&lt;br /&gt; &amp;amp;attr_char_value,&lt;br /&gt; &amp;amp;p_test_service-&amp;gt;char_handles);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;br /&gt; &lt;br /&gt; NRF_LOG_INFO(&amp;quot;\r\nService handle: %#x\n\r&amp;quot;, p_test_service-&amp;gt;service_handle);&lt;br /&gt; NRF_LOG_INFO(&amp;quot;Char value handle: %#x\r\n&amp;quot;, p_test_service-&amp;gt;char_handles.value_handle);&lt;br /&gt; NRF_LOG_INFO(&amp;quot;Char cccd handle: %#x\r\n\r\n&amp;quot;, p_test_service-&amp;gt;char_handles.cccd_handle);&lt;/p&gt;
&lt;p&gt;return NRF_SUCCESS;&lt;br /&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Help converting some Adafruit Arduino code to embedded C</title><link>https://devzone.nordicsemi.com/thread/121900?ContentTypeID=1</link><pubDate>Sun, 25 Feb 2018 15:33:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:611d4887-64be-4c16-a496-0cc2dbe65aa2</guid><dc:creator>Matt</dc:creator><description>&lt;p&gt;Looks like a custom &amp;quot;lockScreen&amp;quot; BLE service you have here? Maybe the BLE service and characteristics tutorial is a good starting point:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/tutorials/b/bluetooth-low-energy/posts/ble-characteristics-a-beginners-tutorial"&gt;devzone.nordicsemi.com/.../ble-characteristics-a-beginners-tutorial&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>