XIAO nRF52840 (Sense) not working only in BLE examples

Hi,

I have 2 XIAO nRF52840 Sense in my hands. They both work fine with the Blink example described in the “Getting Started document” ( wiki. seeedstudio. com/XIAO_BLE/ ).

However, they don’t work for the example mentioned in “Control built-in LED using a smartphone” in the “Bluetooth Usage document” ( For Seeed nRF52 mbed-enabled Boards Boards - Seeed Wiki ). There is no LED BLE peripheral on the phone’s APP peripheral list.

I modified the code as follows. It should blink a LED in the infinite loop in the beginning, but it didn’t. So I guess the image uploading didn’t make success, although there was no error message while uploading.

//......
void setup() {
  Serial.begin(9600);
  while (!Serial);
 
  // set LED pin to output mode
  pinMode(ledPin, OUTPUT);
  while(1) {
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
    delay(1000);
  }

  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting Bluetooth® Low Energy module failed!");
 
    while (1);
  }
 //......

Then I tried the Blink example again, and it still works. So I wonder if it might only happen when it’s involved with the BLE example.

The following is my development environment.

  • arduino-ide_2.0.2_Windows_64bit
  • Seeed nRF52 mbed-enabled Boards 2.7.2
  • ArduinoBLE 1.3.2
  • Board: Seeed XIAO BLE Sense - nRF52840

I also fixed the uploading bug according to this doc.

I didn’t find a related discussion about this issue. So It may work in a specific environment. It would also help if someone could share a work environment with me. Thanks.

Hi williamlai,
I am using the same environment as you, pasted the code from the wiki and it worked as expected. (I haven’t fixed any particular uploading bugs since IDE 2.0.2.)

I figured out the root cause. The program is actually stuck at this line at the very beginning.

while (!Serial);

It won’t proceed until I connect the serial terminal. I guess it’s because Serial is a device of USB.

The solution I use is removing Serial, and everything works after then.

If you start up a serial monitor in the IDE, it will work without removing it!