<?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>DWM1001-DEV with nrf scanning to reduce power consumption</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/79136/dwm1001-dev-with-nrf-scanning-to-reduce-power-consumption</link><description>Hello, 
 I&amp;#39;m working on a project related to DWM1001-DEV at University of Illinois at Urbana-Champaign to build a demo of the product that uses UWB. However, I&amp;#39;m having several troubles with SEGGER. The first and most important is finding an nrf example</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 02 Sep 2021 11:53:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/79136/dwm1001-dev-with-nrf-scanning-to-reduce-power-consumption" /><item><title>RE: DWM1001-DEV with nrf scanning to reduce power consumption</title><link>https://devzone.nordicsemi.com/thread/327781?ContentTypeID=1</link><pubDate>Thu, 02 Sep 2021 11:53:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef6f33c4-cc20-46b7-8f55-9b4db6eecf04</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;There is significant API differences between SDK 17 and SDK 14. You can refer to this code for SDK 14.2. It drops right into the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/ble_sdk_app_nus_c.html"&gt;Nordic UART Service Client example&lt;/a&gt;&amp;nbsp;projects in the SDK:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**
 * Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
 * 
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 * 
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 * 
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 * 
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 * 
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA &amp;quot;AS IS&amp;quot; AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 */
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdbool.h&amp;gt;
#include &amp;quot;nordic_common.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;app_uart.h&amp;quot;
#include &amp;quot;ble_db_discovery.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;
#include &amp;quot;app_util.h&amp;quot;
#include &amp;quot;bsp_btn_ble.h&amp;quot;
#include &amp;quot;ble.h&amp;quot;
#include &amp;quot;ble_gap.h&amp;quot;
#include &amp;quot;ble_hci.h&amp;quot;
#include &amp;quot;nrf_sdh.h&amp;quot;
#include &amp;quot;nrf_sdh_ble.h&amp;quot;
#include &amp;quot;nrf_sdh_soc.h&amp;quot;
#include &amp;quot;nrf_pwr_mgmt.h&amp;quot;
#include &amp;quot;ble_advdata.h&amp;quot;
#include &amp;quot;ble_nus_c.h&amp;quot;
#include &amp;quot;nrf_ble_gatt.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;


#define APP_BLE_CONN_CFG_TAG    1                                       /**&amp;lt; A tag that refers to the BLE stack configuration we set with @ref sd_ble_cfg_set. Default tag is @ref BLE_CONN_CFG_TAG_DEFAULT. */
#define APP_BLE_OBSERVER_PRIO   3                                       /**&amp;lt; Application&amp;#39;s BLE observer priority. You shoulnd&amp;#39;t need to modify this value. */

#define SCAN_INTERVAL           0x00A0                                  /**&amp;lt; Determines scan interval in units of 0.625 millisecond. */
#define SCAN_WINDOW             0x0050                                  /**&amp;lt; Determines scan window in units of 0.625 millisecond. */
#define SCAN_TIMEOUT            0x0000                                  /**&amp;lt; Timout when scanning. 0x0000 disables timeout. */


/** @brief Parameters used when scanning. */
static ble_gap_scan_params_t const m_scan_params =
{
    .active   = 1,
    .interval = SCAN_INTERVAL,
    .window   = SCAN_WINDOW,
    .timeout  = SCAN_TIMEOUT,
    #if (NRF_SD_BLE_API_VERSION &amp;lt;= 2)
        .selective   = 0,
        .p_whitelist = NULL,
    #endif
    #if (NRF_SD_BLE_API_VERSION &amp;gt;= 3)
        .use_whitelist = 0,
    #endif
};


/**@brief Function for asserts in the SoftDevice.
 *
 * @details This function will be called in case of an assert in the SoftDevice.
 *
 * @warning This handler is an example only and does not fit a final product. You need to analyze
 *          how your product is supposed to react in case of Assert.
 * @warning On assert from the SoftDevice, the system can only recover on reset.
 *
 * @param[in] line_num     Line number of the failing ASSERT call.
 * @param[in] p_file_name  File name of the failing ASSERT call.
 */
void assert_nrf_callback(uint16_t line_num, const uint8_t * p_file_name)
{
    app_error_handler(0xDEADBEEF, line_num, p_file_name);
}


/**@brief Function to start scanning. */
static void scan_start(void)
{
    ret_code_t ret;

    ret = sd_ble_gap_scan_start(&amp;amp;m_scan_params);
    APP_ERROR_CHECK(ret);

    ret = bsp_indication_set(BSP_INDICATE_SCANNING);
    APP_ERROR_CHECK(ret);
}


/**@brief Function for handling BLE events.
 *
 * @param[in]   p_ble_evt   Bluetooth stack event.
 * @param[in]   p_context   Unused.
 */
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    ret_code_t            err_code;
    ble_gap_evt_t const * p_gap_evt = &amp;amp;p_ble_evt-&amp;gt;evt.gap_evt;

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_ADV_REPORT:
        {
            ble_gap_evt_adv_report_t const * p_adv_report = &amp;amp;p_gap_evt-&amp;gt;params.adv_report;

            err_code = bsp_indication_set(BSP_INDICATE_IDLE);
            APP_ERROR_CHECK(err_code);
            NRF_LOG_INFO(&amp;quot;Received advertising packet from %02x%02x%02x%02x%02x%02x:&amp;quot;,
                     p_adv_report-&amp;gt;peer_addr.addr[0],
                     p_adv_report-&amp;gt;peer_addr.addr[1],
                     p_adv_report-&amp;gt;peer_addr.addr[2],
                     p_adv_report-&amp;gt;peer_addr.addr[3],
                     p_adv_report-&amp;gt;peer_addr.addr[4],
                     p_adv_report-&amp;gt;peer_addr.addr[5]);
            NRF_LOG_HEXDUMP_INFO(p_adv_report-&amp;gt;data, p_adv_report-&amp;gt;dlen); 
        }break; // BLE_GAP_EVT_ADV_REPORT


        case BLE_GAP_EVT_TIMEOUT:
            if (p_gap_evt-&amp;gt;params.timeout.src == BLE_GAP_TIMEOUT_SRC_SCAN)
            {
                NRF_LOG_INFO(&amp;quot;Scan timed out.&amp;quot;);
                scan_start();
            }
            break;

        default:
            break;
    }
}


/**@brief Function for initializing the BLE stack.
 *
 * @details Initializes the SoftDevice and the BLE event interrupt.
 */
static void ble_stack_init(void)
{
    ret_code_t err_code;

    err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);

    // Configure the BLE stack using the default settings.
    // Fetch the start address of the application RAM.
    uint32_t ram_start = 0;
    err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &amp;amp;ram_start);
    APP_ERROR_CHECK(err_code);

    // Enable BLE stack.
    err_code = nrf_sdh_ble_enable(&amp;amp;ram_start);
    APP_ERROR_CHECK(err_code);

    // Register a handler for BLE events.
    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
}


/**@brief Function for initializing the nrf log module. */
static void log_init(void)
{
    ret_code_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();
}


int main(void)
{
    log_init();
    ble_stack_init();

    NRF_LOG_INFO(&amp;quot;Beacon scanner started.&amp;quot;);
    scan_start();

    for (;;)
    {
        if (NRF_LOG_PROCESS() == false)
        {
            sd_app_evt_wait();
        }
    }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Note that I just put this together very fast, so it is not perfect in any way. In my test it only ran for a second or two due to too much logging in an environment with many advertising packets. But you can take this as a simple reference and adapt to your needs.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DWM1001-DEV with nrf scanning to reduce power consumption</title><link>https://devzone.nordicsemi.com/thread/327669?ContentTypeID=1</link><pubDate>Wed, 01 Sep 2021 16:31:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1b0351ca-94ad-4a7a-ba3a-44d337bbfca7</guid><dc:creator>johndoeaa1</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Thanks a lot for your answer. However, I had some additional problems when I copied your code and imported the necessary files. The errors I&amp;#39;m getting seems to be in code level inside the nrf_SDK.&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/41616.Capture.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m using nrf SDK 14.2.0 as that&amp;#39;s the default for DWM1001 examples from &lt;a href="https://github.com/Decawave/dwm1001-examples"&gt;github.com/.../dwm1001-examples&lt;/a&gt;. I tried upgrading it to 17.0.2, but I couldn&amp;#39;t get it working with the examples. Though these code-level errors mostly stem from undefined variables. I don&amp;#39;t think there&amp;#39;s a bug in the SDK, but is there more files I should import? What should I do?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DWM1001-DEV with nrf scanning to reduce power consumption</title><link>https://devzone.nordicsemi.com/thread/327660?ContentTypeID=1</link><pubDate>Wed, 01 Sep 2021 14:57:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b12424f0-671a-450b-9798-a63139d9f520</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;In practice all BLE central examples implement scanning, but they may be too complex if you just want to receive and dump any advertisement packets you can use this as a reference:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdbool.h&amp;gt;
#include &amp;quot;nordic_common.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;app_uart.h&amp;quot;
#include &amp;quot;ble_db_discovery.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;
#include &amp;quot;app_util.h&amp;quot;
#include &amp;quot;bsp_btn_ble.h&amp;quot;
#include &amp;quot;ble.h&amp;quot;
#include &amp;quot;ble_gap.h&amp;quot;
#include &amp;quot;ble_hci.h&amp;quot;
#include &amp;quot;nrf_sdh.h&amp;quot;
#include &amp;quot;nrf_sdh_ble.h&amp;quot;
#include &amp;quot;nrf_sdh_soc.h&amp;quot;
#include &amp;quot;ble_nus_c.h&amp;quot;
#include &amp;quot;nrf_ble_gatt.h&amp;quot;
#include &amp;quot;nrf_pwr_mgmt.h&amp;quot;
#include &amp;quot;nrf_ble_scan.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;


#define APP_BLE_CONN_CFG_TAG    1                                       /**&amp;lt; Tag that refers to the BLE stack configuration set with @ref sd_ble_cfg_set. The default tag is @ref BLE_CONN_CFG_TAG_DEFAULT. */
#define APP_BLE_OBSERVER_PRIO   3                                       /**&amp;lt; BLE observer priority of the application. There is no need to modify this value. */

static uint8_t buffer[BLE_GAP_SCAN_BUFFER_EXTENDED_MIN];
static ble_data_t m_scan_buffer = {.p_data = buffer, .len = sizeof(buffer)};

/**@brief Function for handling asserts in the SoftDevice.
 *
 * @details This function is called in case of an assert in the SoftDevice.
 *
 * @warning This handler is only an example and is not meant for the final product. You need to analyze
 *          how your product is supposed to react in case of assert.
 * @warning On assert from the SoftDevice, the system can only recover on reset.
 *
 * @param[in] line_num     Line number of the failing assert call.
 * @param[in] p_file_name  File name of the failing assert call.
 */
void assert_nrf_callback(uint16_t line_num, const uint8_t * p_file_name)
{
    app_error_handler(0xDEADBEEF, line_num, p_file_name);
}


/**@brief Function for handling the Nordic UART Service Client errors.
 *
 * @param[in]   nrf_error   Error code containing information about what went wrong.
 */
static void nus_error_handler(uint32_t nrf_error)
{
    APP_ERROR_HANDLER(nrf_error);
}



/**@brief Function to start scanning. */
static void scan_start(void)
{
    ret_code_t ret;
    
    static ble_gap_scan_params_t scan_params = {0};
    scan_params.extended = 0;
    scan_params.filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL;
    scan_params.scan_phys = BLE_GAP_PHY_1MBPS;
    scan_params.interval = 1000; // 625 us units
    scan_params.window = 500;  // 625 us units
    scan_params.timeout = BLE_GAP_SCAN_TIMEOUT_UNLIMITED;
   
    
    ret = sd_ble_gap_scan_start(&amp;amp;scan_params, &amp;amp;m_scan_buffer);
    APP_ERROR_CHECK(ret);

    ret = bsp_indication_set(BSP_INDICATE_SCANNING);
    APP_ERROR_CHECK(ret);
}





/**@brief Function for handling BLE events.
 *
 * @param[in]   p_ble_evt   Bluetooth stack event.
 * @param[in]   p_context   Unused.
 */
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    ret_code_t            err_code;
    ble_gap_evt_t const * p_gap_evt = &amp;amp;p_ble_evt-&amp;gt;evt.gap_evt;
    ble_gap_evt_adv_report_t const * p_adv_report = &amp;amp;p_ble_evt-&amp;gt;evt.gap_evt.params.adv_report;

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_ADV_REPORT:
            NRF_LOG_INFO(&amp;quot;Received advertising report. Data:&amp;quot;)
            NRF_LOG_HEXDUMP_INFO(p_adv_report-&amp;gt;data.p_data, p_adv_report-&amp;gt;data.len); 

            // Resume the scanning.
            UNUSED_RETURN_VALUE(sd_ble_gap_scan_start(NULL, &amp;amp;m_scan_buffer));

            break;

        default:
            break;
    }
}


/**@brief Function for initializing the BLE stack.
 *
 * @details Initializes the SoftDevice and the BLE event interrupt.
 */
static void ble_stack_init(void)
{
    ret_code_t err_code;

    err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);

    // Configure the BLE stack using the default settings.
    // Fetch the start address of the application RAM.
    uint32_t ram_start = 0;
    err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &amp;amp;ram_start);
    APP_ERROR_CHECK(err_code);

    // Enable BLE stack.
    err_code = nrf_sdh_ble_enable(&amp;amp;ram_start);
    APP_ERROR_CHECK(err_code);

    // Register a handler for BLE events.
    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
}



/**@brief Function for handling events from the BSP module.
 *
 * @param[in] event  Event generated by button press.
 */
void bsp_event_handler(bsp_event_t event)
{
    ret_code_t err_code;

    switch (event)
    {
        default:
            break;
    }
}



/**@brief Function for initializing buttons and leds. */
static void buttons_leds_init(void)
{
    ret_code_t err_code;
    bsp_event_t startup_event;

    err_code = bsp_init(BSP_INIT_LEDS, bsp_event_handler);
    APP_ERROR_CHECK(err_code);

    err_code = bsp_btn_ble_init(NULL, &amp;amp;startup_event);
    APP_ERROR_CHECK(err_code);
}


/**@brief Function for initializing the timer. */
static void timer_init(void)
{
    ret_code_t err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);
}


/**@brief Function for initializing the nrf log module. */
static void log_init(void)
{
    ret_code_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();
}


/**@brief Function for initializing power management.
 */
static void power_management_init(void)
{
    ret_code_t err_code;
    err_code = nrf_pwr_mgmt_init();
    APP_ERROR_CHECK(err_code);
}



/**@brief Function for handling the idle state (main loop).
 *
 * @details Handles any pending log operations, then sleeps until the next event occurs.
 */
static void idle_state_handle(void)
{
    if (NRF_LOG_PROCESS() == false)
    {
        nrf_pwr_mgmt_run();
    }
}


int main(void)
{
    // Initialize.
    log_init();
    timer_init();
    buttons_leds_init();
    power_management_init();
    ble_stack_init();

    // Start execution.
    NRF_LOG_INFO(&amp;quot;Coded PHY beacon scanner started.&amp;quot;);
    scan_start();

    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Regarding &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/78650/using-nrf-ble-with-dwm1001-dev"&gt;the other thread&lt;/a&gt;, the application engineer assigned to the case is OoO this week which has caused some delay. I have bumped it and expect you will get a response tomorrow.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DWM1001-DEV with nrf scanning to reduce power consumption</title><link>https://devzone.nordicsemi.com/thread/327475?ContentTypeID=1</link><pubDate>Tue, 31 Aug 2021 16:01:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1f7f374c-9ba0-497e-ac59-d3fdb31b83f2</guid><dc:creator>johndoeaa1</dc:creator><description>&lt;p&gt;I&amp;#39;m also working on the ticket&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/78650/using-nrf-ble-with-dwm1001-dev,"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/78650/using-nrf-ble-with-dwm1001-dev,&lt;/a&gt;&amp;nbsp;but the developer seems to have stopped responding. It&amp;#39;s just been 2 days,&amp;nbsp;so I don&amp;#39;t blame him, but we have been messaging daily, and&amp;nbsp;we&amp;#39;re in a little hurry.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>