NCS2.0.x periodic_adv, PHY CODED lost data

Hello,

nRF5340, NCS2.0.2, vscode.

\v2.0.2\zephyr\samples\bluetooth\periodic_adv

when TX and RX work on PHY_1M,  two side work well.

but when TX side set  BT_LE_ADV_OPT_CODED and RX side set BT_LE_SCAN_OPT_CODED,  RX side frequent data loss. 

the frist data byte for Serial number (like 0 1 2 3 4....),

interval 100ms  bt_le_per_adv_set_data(), RX side will loss some Serial number data.

how config it?

TX side demo code as follow,

RX code is default project periodic_sync (only set  bt_le_scan_start()BT_LE_SCAN_OPT_CODED, and printk recv data)

#include <bluetooth/bluetooth.h>
#if defined (NRF5340_XXAA_APPLICATION)
  #define CLOCK_FEATURE_HFCLK_DIVIDE_PRESENT
  #include "nrfx_clock.h"
#endif
#include <devicetree.h>
#include <device.h>
#include <drivers/gpio.h>
#include <hal/nrf_gpio.h>
#include <hal/nrf_gpiote.h>
#include <nrfx_gpiote.h>
#include <sys/reboot.h>

void main(void)
{
	uint8_t mfg_data[25] = {0, 'a','b','c','d','e','f','g'};
	const struct bt_data ad[] = {
		BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, sizeof(mfg_data)),
	};

	struct bt_le_ext_adv *adv=NULL;
	#if defined (NRF5340_XXAA_APPLICATION)
	nrfx_clock_divider_set(NRF_CLOCK_DOMAIN_HFCLK, NRF_CLOCK_HFCLK_DIV_1);//128MHz
	#endif

		#define BT_LE_EXT_ADV_NCONN_NAME_USER  \
	   			BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_CODED | \
						BT_LE_ADV_OPT_USE_NAME, \
						BT_GAP_ADV_FAST_INT_MIN_1, \
						BT_GAP_ADV_FAST_INT_MAX_1, \
						NULL)
	// Create a non-connectable non-scannable unDIRECTED advertising set
	int err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN_NAME_USER, NULL, &adv);
	if (err) {
		printk("Failed to create advertising set (err %d)\n", err);
		return;
	}

        #define BT_LE_PER_ADV_P   BT_LE_PER_ADV_PARAM(BT_GAP_PER_ADV_FAST_INT_MIN_1, \
						BT_GAP_PER_ADV_FAST_INT_MIN_1, \
						0)
	// Set periodic advertising parameters   
	err = bt_le_per_adv_set_param(adv, BT_LE_PER_ADV_P);
	if (err) {
		printk("Failed to set advertising parameters (err %d)\n", err);
		return;
	}

	// Enable Periodic Advertising
	err = bt_le_per_adv_start(adv);
	if (err) {
		printk("Failed to enable advertising (err %d)\n", err);
		return;
	}

	printk("Start Extended Advertising...");
	err = bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_DEFAULT);
	if (err) {
		printk("Failed to start extended advertising (err %d)\n", err);
		return;
	}
	printk("done.\n");

	while (true) 
	{	
		k_msleep(100);

		mfg_data[0]++;// The first byte acts as a sequence number, increment it for every data update
		err = bt_le_per_adv_set_data(adv, ad, ARRAY_SIZE(ad));
		if (err) {
			printk("Failed (err %d)\n", err);
			break;
		}
	}

}

   

Best regards

Parents Reply
  • Hi,

    use two nRF5340-DK,one for TX side ,another for RX side

    build the two side code from adv_sync.zip on above.

    download builded to two side DK.

    RX side DK connect to Window10 x64,

    open Wndows Uart Serial as follow pic logs,

    log [xxx] is data number, follow pic will tell you lost No 76 (TX side 100ms interval setdata())

    if TX side 20ms interval setdata(), it will lost a lot of data.

    there will always be data loss , loop Interstitial loss of different data (not only No 76).

    I think I have described it very clearly!

        

    Best regards

Children
Related