Xiao Nrf52840 BLE issue

Hi Everyone,

I’m having issues with the BLE examples using bluefruit, the issue I’m having is to do with broadcasting intervals, setting interval works no worries however it broadcasts about 10 times then pauses for a somewhat random amount of time, this pause seems to be proportional to the set interval times.

I have tried all the set type options with no changes,

any idea?

thanks

problem solved,

my silly mistake, wasn’t the peripheral taking a pause it was the central not continuously scanning, set Bluefruit.Scanner.setInterval(160, 160), problem solved.

Hi there,
I have one, an Idea…
How about you post up the code?

we can look at it.
HTH
GL :slight_smile: PJ

#include <bluefruit.h>

#include <ble_gap.h>

// Software Timer for blinking RED LED

SoftwareTimer blinkTimer;

// Custom UUID used to differentiate this device.

// Use any online UUID generator to generate a valid UUID.

// Note that the byte order is reversed ... CUSTOM_UUID

// below corresponds to the follow value:

// df67ff1a-718f-11e7-8cf7-a6006ad3dba0

const uint8_t CUSTOM_UUID[] =

{

    0xA0, 0xDB, 0xD3, 0x6A, 0x00, 0xA6, 0xF7, 0x8C,

    0xE7, 0x11, 0x8F, 0x71, 0x1A, 0xFF, 0x67, 0xDF

};

BLEUuid uuid = BLEUuid(CUSTOM_UUID);

void setup()

{

  Serial.begin(115200);

  while ( !Serial ) delay(10);   // for nrf52840 with native usb

  Serial.println("Bluefruit52 Peripheral Proximity Example");

  Serial.println("----------------------------------------\n");

  // Initialize blinkTimer for 1000 ms and start it

  blinkTimer.begin(1000, blink_timer_callback);

  blinkTimer.start();

  if (!Bluefruit.begin(1,0))

  {

    Serial.println("Unable to init Bluefruit");

    while(1)

    {

      digitalToggle(LED_RED);

      delay(100);

    }

  }

  else

  {

    Serial.println("Bluefruit initialized (peripheral mode)");

  }

  Bluefruit.setTxPower(4);    // Check bluefruit.h for supported values

  // Set up and start advertising

  startAdv();

  Serial.println("Advertising started");

  sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);

}

void startAdv(void)

{  

  //Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);

  Bluefruit.Advertising.addTxPower();

  Bluefruit.Advertising.addUuid(uuid);

  Bluefruit.Advertising.setType(BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED);  // for XIAO BLE

  //Bluefruit.Advertising.setType(BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED);

 

  Bluefruit.Advertising.restartOnDisconnect(true);

  Bluefruit.Advertising.setInterval(1600, 1600); // in unit of 0.625 ms

  //Bluefruit.Advertising.setInterval(4000, 4000); // in unit of 0.625 ms

  Bluefruit.Advertising.setFastTimeout(1);      // number of seconds in fast mode

  Bluefruit.Advertising.start();

}

void loop()

{

}

/**

 * Software Timer callback is invoked via a built-in FreeRTOS thread with

 * minimal stack size. Therefore it should be as simple as possible. If

 * a periodically heavy task is needed, please use Scheduler.startLoop() to

 * create a dedicated task for it.

 *

 * More information http://www.freertos.org/RTOS-software-timer.html

 */

void blink_timer_callback(TimerHandle_t xTimerID)

{

  (void) xTimerID;

  digitalToggle(LED_RED);

}

Yikes… :face_with_peeking_eye:
Edit…

#include <bluefruit.h>
#include <ble_gap.h>
// Software Timer for blinking RED LED
SoftwareTimer blinkTimer;
// Custom UUID used to differentiate this device.
// Use any online UUID generator to generate a valid UUID.

// Note that the byte order is reversed … CUSTOM_UUID

// below corresponds to the follow value:
// df67ff1a-718f-11e7-8cf7-a6006ad3dba0
const uint8_t CUSTOM_UUID[] =
{
0xA0, 0xDB, 0xD3, 0x6A, 0x00, 0xA6, 0xF7, 0x8C,
0xE7, 0x11, 0x8F, 0x71, 0x1A, 0xFF, 0x67, 0xDF
};

BLEUuid uuid = BLEUuid(CUSTOM_UUID);

void setup()
{
Serial.begin(115200);
while ( !Serial ) delay(10); // for nrf52840 with native usb
Serial.println(“Bluefruit52 Peripheral Proximity Example”);
Serial.println("----------------------------------------\n");
// Initialize blinkTimer for 1000 ms and start it
blinkTimer.begin(1000, blink_timer_callback);
blinkTimer.start();
if (!Bluefruit.begin(1,0))
{
Serial.println("Unable to init Bluefruit");
while(1)
{
  digitalToggle(LED_RED);
  delay(100);
}
}
else
{
Serial.println("Bluefruit initialized (peripheral mode)");
}
Bluefruit.setTxPower(4); // Check bluefruit.h for supported values
// Set up and start advertising
startAdv();
Serial.println(“Advertising started”);
sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
}

void startAdv(void)
{
//Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
Bluefruit.Advertising.addTxPower();

Bluefruit.Advertising.addUuid(uuid);

Bluefruit.Advertising.setType(BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED); // for XIAO BLE
//Bluefruit.Advertising.setType(BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED);
Bluefruit.Advertising.restartOnDisconnect(true);
Bluefruit.Advertising.setInterval(1600, 1600); // in unit of 0.625 ms
//Bluefruit.Advertising.setInterval(4000, 4000); // in unit of 0.625 ms
Bluefruit.Advertising.setFastTimeout(1); // number of seconds in fast mode

Bluefruit.Advertising.start();

}
void loop()
{
}
/**
Software Timer callback is invoked via a built-in FreeRTOS thread with

minimal stack size. Therefore it should be as simple as possible. If

a periodically heavy task is needed, please use Scheduler.startLoop() to
create a dedicated task for it.
More information FreeRTOS - RTOS software timer functionality and features description
*/
void blink_timer_callback(TimerHandle_t xTimerID)
{
(void) xTimerID;
digitalToggle(LED_RED);

}

Ah’ this looks better when you use the </> tags above next to the quote marks and Upload button. :v:
HTH
GL :slight_smile: PJ

so this compiles , but of course because of the settings is not connectable or scannable?

Thanks for the tip, Yes it compiles and is not connectable or scannable. though have tried the other settings, I issues I’m having is a pause after advertising 10 or so times, if I really want i can work around this but broadcasting once or twice stopping advertise then using delay(); for the desired interval then starting advertise and repeat but I feel this shouldn’t be necessary.

Hi there,
You may need to Start and STOP the advertising manually in order to get the timing requirement you have. I have heard of settings that it would advertise more often as time goes by then resets the advertised timer kind of thing.

What is the end goal here?
GL :slight_smile: PJ

End goal for is to advertise an id number once every second until a interrupt tells the device to stop

1 Like

Hi there,
Yea, So I know there’s an example that changes the BLE.advertisement name when you press a pushbutton for ESP32c3 if that helps. does the ID number change?
GL :slight_smile: PJ

Hi, No the ID stays the same,

problem solved, my silly mistake, wasnt the peripheral taking a pause it was the central not contiuously scanning, set Bluefruit.Scanner.setInterval(160, 160), problem solved.

1 Like

@b.goodwin What Board Manager Version are you using to get Bluefruit to work?

Hi there and welcome,
SO I see the mbed thread vs. non. this isn’t one of those issues, You’ll see Bluefruit is dependant on NON-embed. You should read up on the Bootloader info’s to help you understand the differences.
Only the non-embed is supported.
HTH
GL :slight_smile: PJ
BTW BSP 1.1.1 was used in testing.

Thanks!

Any link to the Bootloader info you mention?
And sorry, what is BSP stand for?

Hi there,
No , not specifically, Just google it and you’ll have enough reading for a day or three :smile:
It all starts with the bootloader. “SandeepMistry” started with his port of the Adafruit BL.,The BSP is the " Board Support Package " these are Non-embed 1.1.1 and the Embed versions like 2.9.1 & 2.9.2 . for example There should be a Newer one dropping soon for new chips and or bugfixes.
HTH
GL :slight_smile: PJ

Hi @LePetitRenard ,

I’m using the latest version on everything 2.x version of the ide, windows setup, and non mbed version. All downloaded though the ide

Let me know if you have any questions, but the examples are pretty good once to do the right downloads

Cheers,