BLE 33: Writing to SD Card (SPI) stuck every 15ms

Hello,

i'm using multiple Arduino Nano BLE 33 to log data to a SD Card. At first, everything works fine, until I take a closer look to the logged timestamps: The log stuck recurrently in a same time pattern! In my case, I'm logging data every 6ms, but every 60ms the log stuck for 15ms.

That's why I created a bare example of the SD-Card logging:

#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;
File myFile;

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; 
  }
  Serial.print("Initializing SD card...");

  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    while (1);
  }
  Serial.println("card initialized.");
}

void loop() {
   myFile = SD.open("test.csv", O_CREAT | O_APPEND | O_WRITE);
   if(myFile){
      for( int i = 0; i < 10000;  i++ ){
        myFile.println(millis());
      }      
    }
  myFile.close();
}

The Pin connection (MISO, MOSI, CLK) is as usual (I connected CS to Pin 10).
After running the bare example and evaluate the milliseconds I received a similar output: The logging stuck for 13ms every 15ms!

Output extract:

7884
7884
7884
7884
7884
7884
7884
7897 <<< stuck 13ms
7897
7897
7897
7897
7897
7897
7897
7897
7897
7897
7897
7897
7897
7897
7897
7897
7897
7897
7897
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7898
7899
7899
7899
7899
7899
7899
7899
7899
7899
7899
7899
7899
7899
7899
7899
7899
7899
7899
7899
7899
7899
7899
7899
7899
7899
7912 <<< stuck again 13ms after 15ms
7912
7912
7912
7912
7912
7912
7913
7913

What is happening here? I could really need some help :wink: Should I use the mbed-SD libraries (SDFileSystem / SDBlockDevice) instead of the Arduino-SD.h? Sadly, I didn't get this lib to work...
Thanks a lot!
Klaus

Update: I've tried it with the SDfat library - without success =(
I'm using the newest version of the SD lib. I've used different types of SD-Cards (Class U1 and U3-V30) - nothing changed..
I've uploaded the sketch to different Nano BLE 33 - but nothing helps!

Hello, I really could need some help here. Did someone experience a same behavior? Or can someone give me a hint?

Is there a better way to write a lot of data to the SD card (maybe raw writing in 512kb blocks?)

Thanks,
Klaus

During the 15ms the data is actually written to the SD card.

I did an experiment with your sketch and a logic analyzer and looked at the SD card signals plus a debug signal. Have a look at the screenshot. The debug line goes LOW before the myFile.println( millis() ); and HIGH after the call.

As you can see there is a burst of calls (~70) and then one call takes ~16ms and then there is another burst of calls.

1 Like

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