Seeed XIAO NRF52840 sense breaks as soon as I upload my code

Hello guys, please I beg you help me.

Here's the situation: I've developed some code and thoroughly debugged it on a breadboard. The code has been running smoothly on a XIAO SAMD21 board, and everything was working perfectly. However, I've encountered a snag—I've run out of pins and needed to incorporate an accelerometer into my circuit. I thought that by purchasing the NRF52840 Sense board, I could utilize its onboard accelerometer. So, I acquired the board, uploaded my code to it, and unfortunately, it's not working as expected.

The NRF board operates flawlessly with all the example codes; there are no issues even with a customized code that toggles all the pins on and off. However, as soon as I upload my code, it malfunctions. Specifically, incorrect pins are activated, some don't function at all, the serial connection between the board and my PC is lost, and it becomes nearly impossible to upload any further code to the board. I have to force the board into bootloader mode by pressing the reset button twice to, for example, load the Blink example code onto the board. Once this is done, the board operates perfectly again. However, if I upload my code again, the same issues arise. It's important to note that at this point, the board isn't connected to the breadboard, and all the pins are unconnected—it's solely powered by the USB cable connected to my PC.

I have already tried changing which pins are used in the code, but that didn't change anything. Additionally, I have attempted to remove the interrupts, but that didn't help either.

Is it possible that my code is causing such significant issues with this board? I'm a complete amateur at this, so I'd greatly appreciate your help in figuring this out. Please bear with me and my potentially flawed code.

Thank you in advance for any assistance you can provide!

The error message i get after the board is broke is here:

*Failed to upgrade target. Error is: Write timeout

  • Traceback (most recent call last):
    • File "nordicsemi_main_.py", line 294, in serial*
    • File "nordicsemi\dfu\dfu.py", line 235, in dfu_send_images*
    • File "nordicsemi\dfu\dfu.py", line 206, in _dfu_send_image*
    • File "nordicsemi\dfu\dfu_transport_serial.py", line 213, in send_firmware*
    • File "nordicsemi\dfu\dfu_transport_serial.py", line 241, in send_packet*
    • File "site-packages\serial\serialwin32.py", line 323, in write*
  • serial.serialutil.SerialTimeoutException: Write timeout
    *> *
  • Possible causes:
  • - Selected Bootloader version does not match the one on Bluefruit device.
    • Please upgrade the Bootloader or select correct version in Tools->Bootloader.*
  • - Baud rate must be 115200, Flow control must be off.
  • - Target is not in DFU mode. Ground DFU pin and RESET and release both to enter DFU mode.

Here is my code for referance.

BROKEN_CODE.ino (18.8 KB)

the two boards you mention use different microcontrollers, therefore you will have to work around your code to get it working.

For example, I created a sketch that worked on an arduino nano, but then I upgraded to an arduino nano ESP32-S3 and had to change parts of my code.

Have you tried updating the bootloader or selecting a different one in tools?

Also, I’m not sure if this would help but if you go onto device manager and select the com port for your new board, have a look at the properties and see if the baud rate is 115200.

So in my device manager is set to 9600. If my serial in the code is running 9600 shouldn't the device manager setting be set to the same rate? Or is that individual?

I haven't tried updating the bootloader. It's just so strange how only my code breaks it. What spetificly is causing that? Maybe I can just change the code, remove the issue?

Thanks for a fast response.

Try update the bootloader or select the correct one in tools, or select the correct board.

Go to device manager -> select the COM port for your board -> properties -> port settings -> bits per second and select 115200. The serial bit rate is just the upload rate to the serial monitor.

Okay so i have changed the settings and now i'm able to upload to the board and it not break. the serial monitor is working everything seems to be good.

But the code does not run as it should. When i connect the board to the breadboard with the same pinout some LEDs dont turn on for example. The motor isnt doing what it should. Any ideas?

I have already checked that all the pins on the new board work fine by just uploaded a program that turns them all on and off.

What could be causing such weird results?

Thanks, Patrik

As you are using two boards with different microcontrollers (check documentation of both boards), the behaviour of your code will work differently.

My suggestion would be to isolate different parts of code, maybe a single function or a single piece of hardware, and write a minimalised code for that specific part you isolated.

It may take a while but it will definitely help you understand why things are going wrong in your code.

Then, once everything works in isolated code, put it all together, and if it doesn't work, start building your code with each isolated code you made. That way, you can see what part of code is incompatible with another part.

I've had to do it too, from moving to an atmega328p to an esp32. The code worked fine on an atmega, and didn't work at all on an esp32.

Okay I have it working now. The problem was that I was trying the "analogRead" a digital pin. On an Arduino board this doesn’t break the board it just gives weird readings. Turns out on the NRF it completely shuts the board down and make all the pins do weird things. I have now defined my Pins using A1, A2 and D5, D6 for analog and digital pins to make sure there is no confusion.

That in combinasion with the com port setting being changed to 115200 has solved all my porblems.

Thank you for your help. I'm glad this is resolved.

I'm glad you have it working now!

1 Like

@dunkno Would you mind posting your fixed code, along with all the library settings you're using? I'm in a similar situation and struggling to get already working code working on my Xiao Sense nRF52

Could you detail which boards manager selection your using (Seeed nRF52 vs Seeed nRF52 mbed-enabled Boards) and which version your using?

Edit: Also which LSM6DS3.h library your using too!

Sure, here is the code I used to get it working.

FIXED_CODE.ino (18.8 KB)

I'm using the "nRF52 mbed-enabled boards" version 2.9.2

For the LSM6DS3 im using the Arduino LSM6dS3 by seeed Studies verison 2.0.3

I'm not sure what you mean by "Library settings"?

Let me know if you need anymore info. Happy to help.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.