NCS1.9.0 or NCS1.9.1 periodic_adv work error in nRF5340-DK

Hello,

NCS1.9.0 or NCS1.9.1,  Windows10 X64,VS Code,periodic_adv.default codes

with nRF52840-DK work fine.

but nRF5340-DK got error,as folow logs

"Failed to create advertising set (err -5)"

*** Booting Zephyr OS build v2.7.99-ncs1  ***
Starting Periodic Advertising Demo
Failed to create advertising set (err -5)
[00:00:00.283,355] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
[00:00:00.283,355] <inf> bt_hci_core: HW Variant: nRF53x (0x0003)
[00:00:00.283,386] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 14.50663 Build 1008232294
[00:00:00.286,712] <inf> bt_hci_core: Identity: C7:71:77:EB:8D:C1 (random)
[00:00:00.286,712] <inf> bt_hci_core: HCI: version 5.2 (0x0b) revision 0x22fe, manufacturer 0x0059
[00:00:00.286,712] <inf> bt_hci_core: LMP: version 5.2 (0x0b) subver 0x22fe
[00:00:00.289,093] <wrn> bt_hci_core: opcode 0x2036 status 0x01

  

thanks

Best Regards

Parents Reply Children
  • Hello

    thank you very much,

    it work,but can't enter sent callback function,no recv callback.

    i want change next data in sent callback(when send finished).

    #include <bluetooth/bluetooth.h>
    #include "common/log.h"
    
    static uint8_t mfg_data[9] = { 0xff, 0xff, 0x00 };
    static struct bt_le_ext_adv_cb cb;//call back
    
    static const struct bt_data ad[] = {
    	BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, 9 ),
    };
    static const struct bt_data sd[] = {
    	BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, 9 ),
    };
    
    void sent(struct bt_le_ext_adv *adv, struct bt_le_ext_adv_sent_info *info)
    {
            printk("Sent Data...");
    }
    void connected(struct bt_le_ext_adv *adv, struct bt_le_ext_adv_connected_info *info)
    {
          printk("connected...");
    }
    void scanned(struct bt_le_ext_adv *adv, struct bt_le_ext_adv_scanned_info *info)
    {
          printk("scanned...");
    }
    
    void main(void)
    {
    	struct bt_le_ext_adv *adv;
            cb.sent=sent;//call back
            cb.connected=connected;//call back
            cb.scanned=scanned;//call back
    	int err;
    
    	printk("Starting Periodic Advertising Demo\n");
    
    	// Initialize the Bluetooth Subsystem
    	err = bt_enable(NULL);
    	if (err) {
    		printk("Bluetooth init failed (err %d)\n", err);
    		return;
    	}
     
            // Non-connectable extended advertising with @ref BT_LE_ADV_OPT_USE_NAME BT_LE_ADV_OPT_CODED
           #define BT_LE_EXT_ADV_NCONN_NAME_CODED  BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | \
    						 BT_LE_ADV_OPT_USE_NAME | BT_LE_ADV_OPT_USE_TX_POWER | \
                                                     BT_LE_ADV_OPT_CODED, \
    						 BT_GAP_ADV_FAST_INT_MIN_1, \
    						 BT_GAP_ADV_FAST_INT_MAX_1, \
    						 NULL)   //Peer address, set to NULL for undirected advertising
    	// Create a non-connectable non-scannable unDIRECTED advertising set
    	err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN_NAME_CODED, &cb, &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, \
    						  BT_LE_PER_ADV_OPT_USE_TX_POWER)
    	// Set periodic advertising parameters
    	err = bt_le_per_adv_set_param(adv,BT_LE_PER_ADV_DEFAULT);
    	if (err) {
    		printk("Failed to set periodic advertising parameters (err %d)\n", err);
    		return;
    	}
            err = bt_le_ext_adv_set_data(adv,ad, ARRAY_SIZE(ad),sd, ARRAY_SIZE(sd) );
    	if (err) {
    		printk("Failed to set  bt_le_ext_adv_set_data (err %d)\n", err);
    		return;
    	}
    
    	// Enable Periodic Advertising
    	err = bt_le_per_adv_start(adv);
    	if (err) {
    		printk("Failed to enable periodic advertising (err %d)\n", err);
    		return;
    	}
    
    	// 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;
    	}
    
        for(int i=0;i<sizeof(mfg_data);i++){mfg_data[i]=0;}
    	while (true) 
    	{
    		k_sleep(K_SECONDS(1));
    
    		mfg_data[2]++;
    
    		printk("Set Periodic Advertising Data...");
    		err = bt_le_per_adv_set_data(adv, ad, ARRAY_SIZE(ad));
    		if (err) {
    			printk("Failed (err %d)\n", err);
    			return;
    		}
    		printk("done.\n");
    	}
    }

      

    thanks

    Best Regards

  • Hi 

    Have you configured a timeout on the advertising?

    Looking at your code I can't see that you configure a timeout anywhere. 

    As explained here the sent callback won't be triggered until the advertising times out, which won't happen unless you enable it. 

    Best regards
    Torbjørn

  • Hi,

    how to configured a timeout?is it.

    the starting example code  is not perfect, some difficult for novice,

    can help debug the basic function:

    1. bt_le_per_adv_set_data() in sent function;

         prepare the next data at finished last sending;

    2. set Peer address, for directed advertising;

        for only some one hear;

    3. enable LE_CODE for long rang;

        for low rate 125kbit/s;

    4. periodic_sync can recv directed advertising data;

         now it can't recv data.

        

    thanks

    Best Regards

  • Hi 

    The second parameter of the bt_le_ext_adv_start(..) function provides a pointer to a struct of type bt_le_ext_adv_start_param, which allows you to define the timeout either as a time (in 10ms units), or as a number of advertising events:

    struct bt_le_ext_adv_start_param {
    	/**
    	 * @brief Advertiser timeout (N * 10 ms).
    	 *
    	 * Application will be notified by the advertiser sent callback.
    	 * Set to zero for no timeout.
    	 *
    	 * When using high duty cycle directed connectable advertising then
    	 * this parameters must be set to a non-zero value less than or equal
    	 * to the maximum of @ref BT_GAP_ADV_HIGH_DUTY_CYCLE_MAX_TIMEOUT.
    	 *
    	 * If privacy @kconfig{CONFIG_BT_PRIVACY} is enabled then the timeout
    	 * must be less than @kconfig{CONFIG_BT_RPA_TIMEOUT}.
    	 */
    	uint16_t timeout;
    	/**
    	 * @brief Number of advertising events.
    	 *
    	 * Application will be notified by the advertiser sent callback.
    	 * Set to zero for no limit.
    	 */
    	uint8_t  num_events;
    };
    

    If you create a struct like this, define either the timeout or num_event fields as you want, and provide a pointer to the structure in the bt_le_ext_adv_start(..) call, then the advertising should time out accordingly. 

    Best regards
    Torbjørn

  • Hi,

    my project directed advertising low quality audio(2kByte/s), One-way communication,no reply.

    Because need to send continuous audio data, so prepare the next data in sent function. 

    data must be send one by one,

    it means :

    send next data at finshed last data sending,

    not at timeout.

    as:

    i'll periodic_adv send "123456789",  three bytes are sent at a time.

    1.bt_le_per_adv_set_data("123")

    2.when "123" send finshed, in sent() function

       bt_le_per_adv_set_data("456")

    3.when "456" send finshed, in sent() function

       bt_le_per_adv_set_data("789")

     

    Make sure periodic_sync receives correctly "123456789".

    Error received:

    "123123456789"

    "456123789"

    "789123"

    "123789"

    You know what I mean?

      

    thanks

    Best Regards

Related