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

nRF52840 stops scanning

Hi.

We have a strange issue we are seeing with a nRF52840 where scanning fails, but it is very rare.

Setup - nRF52840 is a central device, and there are 20 x nRF52832's peripherals advertising. The central reports the status of all the peripherals to a PC via CDC usb.

The system can be running fine like this for 1 / 2 weeks 24 hours a day, then out of the blue the nRF52840 stops picking up any peripherals. It could be in the middle of the night, when the system isn't doing anything complicated like connecting / mass data transfer etc.

The fact that all the peripherals 'disappear' at the same time suggests the central is at fault. The peripherals have all been started at different times and have power etc.

I can't monitor / debug as it is a almost finished system, and the fault is too rare to wait and see it.

Are there any obvious properties I could monitor and report over so they are logged on the PC? All the BLE functions result in a hard restart if they fail which I am not seeing. This problem just occurs randomly, like the radio has just switched off etc.

Thanks

Phil

Parents
  • I find tracing all the scanning events helpful, something like this:

    // Scan Events
    static char * ble_scan_event_description[] =
    {
    /* NRF_BLE_SCAN_EVT_FILTER_MATCH",        */ " 0 Filter matched in the multifilter mode",
    /* NRF_BLE_SCAN_EVT_WHITELIST_REQUEST:    */ " 1 Request the whitelist from the main application",
    /* NRF_BLE_SCAN_EVT_WHITELIST_ADV_REPORT: */ " 2 Device from the whitelist is found",
    /* NRF_BLE_SCAN_EVT_NOT_FOUND:            */ " 3 Filter not matched for the scan data",
    /* NRF_BLE_SCAN_EVT_SCAN_TIMEOUT:         */ " 4 Scan timeout",
    /* NRF_BLE_SCAN_EVT_SCAN_REQ_REPORT:      */ " 5 Scan request report",
    /* NRF_BLE_SCAN_EVT_CONNECTING_ERROR:     */ " 6 Error occurred when establishing the connection from sd_ble_gap_connect",
    /* NRF_BLE_SCAN_EVT_CONNECTED:            */ " 7 Connected to device"
    };
    #define NUM_BLE_SCAN_EVENTS (sizeof(ble_scan_event_description)/sizeof(ble_scan_event_description[0]))
    
    /**@brief Function for handling Scanning Module events.
     */
    static void scan_evt_handler(scan_evt_t const * p_scan_evt)
    {
        ret_code_t err_code;
    
        switch(p_scan_evt->scan_evt_id)
        {
             case NRF_BLE_SCAN_EVT_CONNECTING_ERROR:     // Error occurred when establishing the connection. In this event, an error is passed from the function call @ref sd_ble_gap_connect
             {
                  err_code = p_scan_evt->params.connecting_err.err_code;
                  APP_ERROR_CHECK(err_code);
             } break;
    
             case NRF_BLE_SCAN_EVT_CONNECTED:            // Connected to device
             {
                 ble_gap_evt_connected_t const * p_connected = p_scan_evt->params.connected.p_connected;
                 // Scan is automatically stopped by the connection.
                 NRF_LOG_INFO("Connect to Id %02x%02x%02x%02x%02x%02x",
                          p_connected->peer_addr.addr[0],
                          p_connected->peer_addr.addr[1],
                          p_connected->peer_addr.addr[2],
                          p_connected->peer_addr.addr[3],
                          p_connected->peer_addr.addr[4],
                          p_connected->peer_addr.addr[5]
                          );
             } break;
    
             case NRF_BLE_SCAN_EVT_SCAN_TIMEOUT:         // Scan timeout
             {
                 NRF_LOG_INFO("Scan timed out.");
                 scan_start();
             } break;
    
             case NRF_BLE_SCAN_EVT_FILTER_MATCH:         // A filter is matched or all filters are matched in the multifilter mode
                 {
                   ble_gap_evt_adv_report_t const *p_adv_report = p_scan_evt->params.filter_match.p_adv_report;
                   NRF_LOG_INFO("Scan Match Id: %02x%02x%02x%02x%02x%02x",
                          p_adv_report->peer_addr.addr[0],
                          p_adv_report->peer_addr.addr[1],
                          p_adv_report->peer_addr.addr[2],
                          p_adv_report->peer_addr.addr[3],
                          p_adv_report->peer_addr.addr[4],
                          p_adv_report->peer_addr.addr[5]
                          );
                 }
                 break;
    
             case NRF_BLE_SCAN_EVT_NOT_FOUND:            // The filter was not matched for the scan data
                 {
                   ble_gap_evt_adv_report_t const *p_not_found = p_scan_evt->params.p_not_found;
                   NRF_LOG_INFO("Deny Id: %02x%02x%02x%02x%02x%02x",
                          p_not_found->peer_addr.addr[0],
                          p_not_found->peer_addr.addr[1],
                          p_not_found->peer_addr.addr[2],
                          p_not_found->peer_addr.addr[3],
                          p_not_found->peer_addr.addr[4],
                          p_not_found->peer_addr.addr[5]
                          );
                 }
                 break;
    
             default:
    //       case NRF_BLE_SCAN_EVT_FILTER_MATCH:         // A filter is matched or all filters are matched in the multifilter mode
             case NRF_BLE_SCAN_EVT_WHITELIST_REQUEST:    // Request the whitelist from the main application. For whitelist scanning to work, the whitelist must be set when this event occurs
             case NRF_BLE_SCAN_EVT_WHITELIST_ADV_REPORT: // Send notification to the main application when a device from the whitelist is found
    //       case NRF_BLE_SCAN_EVT_NOT_FOUND:            // The filter was not matched for the scan data
             case NRF_BLE_SCAN_EVT_SCAN_REQ_REPORT:      // Scan request report
                if (p_scan_evt->scan_evt_id < NUM_BLE_SCAN_EVENTS)
                {
                   NRF_LOG_INFO("scan_evt_id: %d %s", p_scan_evt->scan_evt_id, ble_scan_event_description[p_scan_evt->scan_evt_id]);
                }
                else
                {
                   NRF_LOG_INFO("Unhandled scan_evt_id: %d", p_scan_evt->scan_evt_id);
                }
                 break;
        }
    }

    Selectively enable/disable the event reports, but ensure everything generates a trace in case something wierd happes .. if any event happens that is ..

  • Hmm, thanks for the suggestion sounds good.

    I will give it a try and monitor the events.

    Thanks

    Phil

  • Actually in the multi-link central SDK15.0.0 I am using there is no scan_init or scan_evt_handler? Must have been added in SDK15.2.0.

    Phil 

  • Hi Philip, 

    Yes, we added a Scanning Module in SDK v15.2.0. In SDK v15.0.0 you can monitor the underlying events that is abstracted by the scanning module. The BLE_GAP_EVT_TIMEOUT event will be sent with the field params.timeout.src set to BLE_GAP_TIMEOUT_SRC_SCAN(0x01), so you can check for this in the ble_evt_handler() in main.c

            case BLE_GAP_EVT_TIMEOUT:
            {
                // Check if scaning times out
                if (p_gap_evt->params.timeout.src == BLE_GAP_TIMEOUT_SRC_SCAN)
                {
                    NRF_LOG_DEBUG("Scanning timed out.");
                }
            } break;

    Best regards

    Bjørn

  • Thanks Guys.

    I added a command to restart scanning when the issue occurs. It did happen again the other day and restarting scanning solved the issue.

    However I still don't understand why it would stop or timeout, after a random period of time. Makes no sense. There is no scanning timeout set in my project.

    Phil

Reply Children
Related