<?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>nRF51822 ADC and S110</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/6230/nrf51822-adc-and-s110</link><description>Hi,
I am new to BLE development and I am currently using nRF51822 with the soft device S110. I am using the example ble_app_hrs that includes the ADC converter. I would like advertise the analog data (from pin 2) and be able to see it on the Master Control</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 31 Mar 2015 09:44:10 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/6230/nrf51822-adc-and-s110" /><item><title>RE: nRF51822 ADC and S110</title><link>https://devzone.nordicsemi.com/thread/21817?ContentTypeID=1</link><pubDate>Tue, 31 Mar 2015 09:44:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ec8d3cf7-7dfa-4471-93cf-24693b3585a0</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;This was just meant to be a very quick example on how to advertise a variable value. It doesn&amp;#39;t really have anything to do with the battery level other than timing. In other words, the ADC values will be updated and stored in your advertising packet every time the (simulated) battery value is updated. I only did this so I didn&amp;#39;t have to create a new timer and to save time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51822 ADC and S110</title><link>https://devzone.nordicsemi.com/thread/21816?ContentTypeID=1</link><pubDate>Fri, 27 Mar 2015 21:52:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:153aad63-a74f-439f-8e20-121b7441ff7b</guid><dc:creator>Xenia</dc:creator><description>&lt;p&gt;Thank you so much for the sample code. I was able to use it. My only question is that now that I am advertising the ADC data  shouldn&amp;#39;t I be able to see it on the Master Control Panel under the  Battery Level Value ? The value shown on the Batter Level Value is still the one as before and not the ADC value. Does&amp;#39;t advertising mean that is sending the data and the Master Control Panel be able to read it ?&lt;/p&gt;
&lt;p&gt;Thank you for the help.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51822 ADC and S110</title><link>https://devzone.nordicsemi.com/thread/21815?ContentTypeID=1</link><pubDate>Thu, 26 Mar 2015 11:29:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aeb800fb-318d-4796-a9c5-b17cdb8fcbc9</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;If I understand you correctly you want to show your ADC value in the advertising packet instead of (or in addition to) in a service?&lt;/p&gt;
&lt;p&gt;To show your ADC value in the advertising packet you can use the manufacturer specific field in. You can do this by modifying your advertising_init() function to something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void advertising_init(void)
{
    uint32_t      err_code;
    // NORDIC. Moved some variables to make them accessible in all functions
    uint8_t       flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

    ble_uuid_t adv_uuids[] =
    {
        {BLE_UUID_HEART_RATE_SERVICE,         BLE_UUID_TYPE_BLE},
        {BLE_UUID_BATTERY_SERVICE,            BLE_UUID_TYPE_BLE},
        {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}
    };

    // NORDIC Prepare the Manufacturer specific data packet
    adc_data.company_identifier           = 0x0059; // Nordics company ID
    adc_data.data.p_data                  = &amp;amp;adc;
    adc_data.data.size                    = sizeof(adc);
    
    // Build and set advertising data.
    memset(&amp;amp;advdata, 0, sizeof(advdata));

    advdata.name_type               = BLE_ADVDATA_FULL_NAME;
    advdata.include_appearance      = true;
    advdata.flags.size              = sizeof(flags);
    advdata.flags.p_data            = &amp;amp;flags;
    advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    advdata.uuids_complete.p_uuids  = adv_uuids;
    // NORDIC add Manufacturer specific data packet
    advdata.p_manuf_specific_data   = &amp;amp;adc_data;  

    err_code = ble_advdata_set(&amp;amp;advdata, NULL);
    APP_ERROR_CHECK(err_code);

    // Initialize advertising parameters (used when starting advertising).
    memset(&amp;amp;m_adv_params, 0, sizeof(m_adv_params));

    m_adv_params.type        = BLE_GAP_ADV_TYPE_ADV_IND;
    m_adv_params.p_peer_addr = NULL;                           // Undirected advertisement.
    m_adv_params.fp          = BLE_GAP_ADV_FP_ANY;
    m_adv_params.interval    = APP_ADV_INTERVAL;
    m_adv_params.timeout     = APP_ADV_TIMEOUT_IN_SECONDS;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now you need to update your adc values. I found a quick and dirty solution by just modifying the ADC_IRQHandler(void) to update the adc value:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void ADC_IRQHandler(void)
{
    /* Clear dataready event */
    NRF_ADC-&amp;gt;EVENTS_END = 0;	
    // NORDIC adc value is updated here
    adc = NRF_ADC-&amp;gt;RESULT; 
    nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT2, adc); /* Write ADC result to port 2 */
    nrf_gpio_pin_toggle(LED_1);
    NRF_ADC-&amp;gt;TASKS_STOP = 1;//Use the STOP task to save current. Workaround for PAN_028 rev1.5 anomaly 1.
    sd_clock_hfclk_release();//Release the external crystal
}	
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and then I simply updated the ADC value in the advertising packet in battery_level_meas_timeout_handler():&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void battery_level_meas_timeout_handler(void * p_context)
{
    UNUSED_PARAMETER(p_context);
    battery_level_update();

    // NORDIC reinitate the complete advertising. Just copy paste the code form advertise_init() and update the adc value
    uint32_t err_code;
    uint8_t       flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    ble_uuid_t adv_uuids[] =
    {
        {BLE_UUID_HEART_RATE_SERVICE,         BLE_UUID_TYPE_BLE},
        {BLE_UUID_BATTERY_SERVICE,            BLE_UUID_TYPE_BLE},
        {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}
    };
    adc_data.company_identifier           = 0x0059; // Nordics company ID
    adc_data.data.p_data                  = &amp;amp;adc;
    adc_data.data.size                    = sizeof(adc);
    
    // Build and set advertising data.
    memset(&amp;amp;advdata, 0, sizeof(advdata));

    advdata.name_type               = BLE_ADVDATA_FULL_NAME;
    advdata.include_appearance      = true;
    advdata.flags.size              = sizeof(flags);
    advdata.flags.p_data            = &amp;amp;flags;
    advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    advdata.uuids_complete.p_uuids  = adv_uuids;
    // NORDIC add adc value to data packet
    advdata.p_manuf_specific_data   = &amp;amp;adc_data;  

    err_code = ble_advdata_set(&amp;amp;advdata, NULL);
    APP_ERROR_CHECK(err_code);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I have attached my main.c file. It should be copy paste-able into your example code. You can search for &amp;quot;NORDIC&amp;quot; and find all my modifications. &lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/0880.main.c"&gt;main.c&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>