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

NRF52832 scan error in app_timer to start and stop it

Hello,

Now i use SDK15.0 and NRF52832 to make a BLE scanner.

I want to scan advertisers every 5s , scan window and scan interval are equal(max=0x3FFF). Also,they are all scan at 37 cannnel.

I want to open scan window only 5ms every 5s peroid.

So ,i want to start a app_timer every 5s to start scanning and delay 5ms to stop it. Like this:

static void 5s_every_timeout_handler(void)
{
scan_start();
nrf_delay_ms(5);
sd_ble_gap_scan_stop();
}
But ,i find i cann't get scan data in ble_evt_handler();
Otherwise, i place these orders in for(::) of main(),like this:
for(;;)
{
scan_start();
nrf_delay_ms(5);
sd_ble_gap_scan_stop();
nrf_delay_ms(5000);
}
It is ok.
So,i think if app_timer handler and ble_evt_handler() cann't run at the same time?

Another question, i want to know what time will spend in stop and start scanning.

I tihink after the chip run scan_start() of software a minutes about N ms or us ,the scanner of hardware can scan really.Is it right?
Thanks.
  • Hi,

    So it sounds like what you really want is a scan interval of 5 s and scan window of 5 ms? So why don't you just configure you scan parameters like this?

    In sdk_config.h:

    // <o> NRF_BLE_SCAN_SCAN_INTERVAL - Scanning interval. Determines the scan interval in units of 0.625 millisecond. 
    #ifndef NRF_BLE_SCAN_SCAN_INTERVAL
    #define NRF_BLE_SCAN_SCAN_INTERVAL 8000 // 5000 ms scan interval
    #endif
    
    // <o> NRF_BLE_SCAN_SCAN_WINDOW - Scanning window. Determines the scanning window in units of 0.625 millisecond. 
    #ifndef NRF_BLE_SCAN_SCAN_WINDOW
    #define NRF_BLE_SCAN_SCAN_WINDOW 8 // 5 ms scan window
    #endif

    Remember that now you are only scanning for 0.1 % of the time, and unless your peripheral have really short advertising intervals it might take a while for the scanner to pick up packets from your peripheral. 

Related