Soft Device Scan Parms not being set correctly from struct

I set my scan params in the following init code.

 

/**@brief Function for initializing the scanning and setting the filters.
 */
static void scan_init(void)
{   
    ret_code_t          err_code;
    nrf_ble_scan_init_t init_scan;
    ble_gap_scan_params_t const m_scan_param =
    {
      .active        = 0x01,
      .interval      = NRF_BLE_SCAN_SCAN_INTERVAL,
      .window        = NRF_BLE_SCAN_SCAN_WINDOW,
      .filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL, //BLE_GAP_SCAN_FP_WHITELIST,
      .timeout       = 0,
      .scan_phys     = BLE_GAP_PHY_1MBPS,
    };

    memset(&init_scan, 0, sizeof(init_scan));
    /**< Scan parameters requested for scanning and connection. */
    init_scan.p_scan_param     = &m_scan_param;
    init_scan.connect_if_match = false;
    init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;

    err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
    APP_ERROR_CHECK(err_code);

}

The interval and scan window are both set to 100. However, when I watch the variables in debug mode, the variables are as follows. 

Any idea how they are being set so wrong? No other references to these variables in the code anywhere except here and when I start scanning following the advertising period ending (60 seconds).

Parents
  • Hi,

    Any idea how they are being set so wrong? No other references to these variables in the code anywhere except here and when I start scanning following the advertising period ending (60 seconds).

    You should use a static variable for the ble_gap_scan_params_t structure used for the p_scan_param pointer in the p_init argument to nrf_ble_scan_init().

    In your implementation, the variable is not static, so when your function scan_init() returns the pointer points to a location in stack memory that will later be overwritten by the local variables of other functions.

    For an example of working initialization with custom scan parameters, see the Advanced initialization section of the Scanning Module documentation.

    Regards,
    Terje

  • I changed it to a static and still no luck. I copied over the strict from the working example. 

  •   My interval I want is being set as the window and my set window is being set as the timeout. The interval has been stuck at 0x0104 for the past two days. 

  • Hi,

    inspiringdev123 said:
    I advertise with my module for 1 minute in the beginning of the program. Could this possibly be affecting the scanning parameters?

    It could be related somehow to what you see, yes. Can you share (a minimal version of) the project for reproducing / investigating?

    inspiringdev123 said:
     I even passed in NULL for the scan parameters to set them to the default configuration and it is still setting them 0x6401 and 0x6400...

    Something is definitely not acting right there, then. I am afraid we do need the project for reproducing this behavior. If you cannot share anything in the open then please create a new case, refer to this one, and add the project there. Preferably the project is stripped down to only containing the parts needed for reproducing the issue.

    Regards,
    Terje

  •   I have opened a private case fyi and reference this case.

  •   If i set the scan parameters like this     m_scan.scan_params = scan_param; They set correctly...

  • But the scan does not start due to Invalid Params Error being thrown in nrf_ble_scan_start.

     

    When using the &init_scan to set the scan paramters, everything is offset by 2 bytes. The address of m_scan.scan_params starts at 0x20004992, but from that address to 0x20004993 is never written to which is where scan_params.extended, report incomplete, active, filter policy, and scan_phys. The value I have for extended, report incomplete, active and filter policy (which are bits 0-3 of the first byte are 0x04) and scan_phys is 0x01. The value written to interval is 0x0104 which shows these bits getting put in the wrong address. The interval hex value is 0xc8 (Which I have set my define value to 200). This value is being written to the window address. This continues on for the window which is set to the define value for interval and the timeout value is set as the define for the window. What could be causing those first two addresses to not being written to?

    This is also causing garbage data to appear in the first 4 bytes of my scan buffer data array, making the first values to start at scan_buffer_data[4]  vs scan_buffer_data[0]. I hope you can access the project in the private case to maybe find what could be happening?

Reply
  • But the scan does not start due to Invalid Params Error being thrown in nrf_ble_scan_start.

     

    When using the &init_scan to set the scan paramters, everything is offset by 2 bytes. The address of m_scan.scan_params starts at 0x20004992, but from that address to 0x20004993 is never written to which is where scan_params.extended, report incomplete, active, filter policy, and scan_phys. The value I have for extended, report incomplete, active and filter policy (which are bits 0-3 of the first byte are 0x04) and scan_phys is 0x01. The value written to interval is 0x0104 which shows these bits getting put in the wrong address. The interval hex value is 0xc8 (Which I have set my define value to 200). This value is being written to the window address. This continues on for the window which is set to the define value for interval and the timeout value is set as the define for the window. What could be causing those first two addresses to not being written to?

    This is also causing garbage data to appear in the first 4 bytes of my scan buffer data array, making the first values to start at scan_buffer_data[4]  vs scan_buffer_data[0]. I hope you can access the project in the private case to maybe find what could be happening?

Children
Related