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

nRF52 restarts after enabling advertising start a couple of times

Hi all,

I have an nRF52 acting as Central, and it will act as beacon just when it, for example, reach a temperature above a certain point. After some time, e.g 10 calls to enable advertising my device restarts, I thought it was because it was in debug mode (I was using RTT), now I disable RTT and NRF_LOG for a release mode, and I am experimenting the same behavior.

When I am going to enable the advertising I do the following:

Stop Scanning

be sure I am not advertising before

Start advertising for a couple of seconds

Stop advertising

re-Enable Scan

it is how I set the advertising data:

	ble_advdata_manuf_data_t manuf_specific_data;
	manuf_specific_data.company_identifier = COMPANY;
	manuf_specific_data.data.p_data = (uint8_t *)&advertingData;
  manuf_specific_data.data.size   = sizeof(advertingData);

  // Build and set advertising data.
  memset(&advdata, 0, sizeof(advdata));
	 
  advdata.name_type             = BLE_ADVDATA_NO_NAME;
  advdata.flags                 = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;
  advdata.p_manuf_specific_data = &manuf_specific_data;

  err_code = ble_advdata_set(&advdata, NULL);
  APP_ERROR_CHECK(err_code);

  // Initialize advertising parameters (used when starting advertising).
  memset(&m_adv_params, 0, sizeof(m_adv_params));

  m_adv_params.type        = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND;
  m_adv_params.p_peer_addr = NULL;                             // Undirected advertisement.
  m_adv_params.fp          = BLE_GAP_ADV_FP_ANY;
  m_adv_params.interval    = NON_CONNECTABLE_ADV_INTERVAL;
  m_adv_params.timeout     = BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED;

My start/stop advertising function

void StarttAdv(void)
{
   ret_code_t err_code;
   err_code = sd_ble_gap_adv_start(&m_adv_params, BLE_CONN_CFG_TAG_DEFAULT);
   APP_ERROR_CHECK(err_code);
}
void StopAdv(void)
{
	sd_ble_gap_adv_stop();
}

///Scanning related

    ble_gap_scan_params_t scanparams;
	memset(&scanparams, 0, sizeof(scanparams));
	scanparams.active = 1;
	
	scanparams.interval = MSEC_TO_UNITS(1000, UNIT_0_625_MS);
	scanparams.window =   MSEC_TO_UNITS(60, UNIT_0_625_MS);
	scanparams.timeout = 1;
	
	
	//start scan
	void start_scan()
	{
	sd_ble_gap_scan_start(&scanparams);
	}
	
	void stop_scan()
	{
        sd_ble_gap_scan_stop();
    }

Regards,

Arepa

##############################

Update:

It seems the advertising was overlaping the scan before a scan timeout, at the moment it looks like fixed.

But in case I want to have concurrent advertising/scanning which is the proper way to do it?, how do I have to set the intervals for advertising and scan, is there a documentation for this?

Related