This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Long Range Mode Issue(Nrf52840)

Hi,
We have a bluetooth product which uses Nrf52840 as the MCU. It composes of a peripheral and a central device of which connect with each other via bluetooth and they work perfect so far.
When power on, the central start scanning whereas the peripheral will start advertising, as long as the central find the designated peripheral, they will establish the bluetooth connection automatically. 
Now, we plan to implement the bluetooth V5 long range mode. After doing some modification of the firmware of the central and the peripheral, I found they don't work anymore.(meaning they cannot establish the bluetooth connection)
Figure 1 and figure 2 are the change points on the central side. 
By debugging, I found that the sd_ble_gap_scan_start(&p_scan_ctx->scan_params, &p_scan_ctx->scan_buffer) return error which is  NRF_ERROR_INVALID_LENGTH. when the firmware start the scan, you can see in Figure 3(return error is located at the bottom of figure 3). 
Does anyone know why's that? Did I miss something to change?

  • Hello,

    Check out ble_gap.h line 2467 - 2479. There it says that if sd_ble_gap_scan_start() returns NRF_ERROR_INVALID_LENGTH:

    * @retval ::NRF_ERROR_INVALID_LENGTH The provided buffer length is invalid. See @ref BLE_GAP_SCAN_BUFFER_MIN.

    A search for BLE_GAP_SCAN_BUFFER_MIN points to line 347 in ble_gap.h line 347. Line 341-346 says:

    /**@defgroup BLE_GAP_SCAN_BUFFER_SIZE GAP Minimum scanner buffer size
    *
    * Scan buffers are used for storing advertising data received from an advertiser.
    * If ble_gap_scan_params_t::extended is set to 0, @ref BLE_GAP_SCAN_BUFFER_MIN is the minimum scan buffer length.
    * else the minimum scan buffer size is @ref BLE_GAP_SCAN_BUFFER_EXTENDED_MIN.
    * @{ */

    So it looks like your scan buffer is to short. The scan buffer is set in: main.c:

    NRF_BLE_SCAN_DEF(m_scan);                                               /**< Scanning Module instance. */

    A macro that declares nrf_ble_scan_t m_scan in nrf_ble_scan.h. 

    In nrf_ble_scan.h you can also see that the scan_buffer_data, the buffer where the scanned advertisements are stored is set with a length of NRF_BLE_SCAN_BUFFER, which is probably defined to 31 in your sdk_config.h.

    Try to increase this to BLE_GAP_SCAN_BUFFER_EXTENDED_MIN, or 255.

    If you increase the NRF_BLE_SCAN_BUFFER in sdk_config.h from 31 to 255, does sd_ble_gap_scan_start() still return NRF_ERROR_INVALID_LENGTH?

    Best regards,

    Edvin

Related