Error using Fatlib LowLatencyLogger

Hi,

I am trying to use the LowLatencyLogger example to log data from a gyroscope/accelerometer at a frequency of 100Hz on a mega2560 .

I got the following error message and tried to reformat using the example format tool.

FreeRam: 7233
Records/block: 42
Invalid format, reformat SD.

Format :

Enter option: F
Card Size: 3790 MB, (MB = 1,048,576 bytes)

Erasing
..............................
All data set to 0x00
Erase done

Formatting
Blocks/Cluster: 64
FAT32
........
Format done

However, the LowLatencyLogger still doesn't work.
Other examples "datalogger", "ReadWrite", "SdInfo" work.
I tried with another SD card without success. This one even can't be formatted with the embedded tool!! but the datalogger example still works.

Formatting
Blocks/Cluster: 64
FAT32
error: FAT32 write PBS failed
SD error: 6,ff

Any idea?

Thanks!!

Looks like SPI I/O errors, nothing to do with format.

This was most likely due to a read error, not a bad format. Arduino has no CRC on read data.

Records/block: 42
Invalid format, reformat SD.

This is a failed write block error.

SD error: 6,ff

What SD module are you using? What other SPI devices are your using. Any long wires to the SPI pins?

A photo would be helpful.

Hi,

I am using the micro sd from this GPS module : http://www.itead.cc/itead-gps-shield.html
I used it on a temporary set up with an arduino mega connected with quite long wires.
Using it as a shield on the arduino UNO everything works now fine..

Thanks for the tip on the cabling length.

I need to connect a lcd screen working with SPI as well.

Should I expect a bad behaviour with the LCD and SD both on SPI?

Thanks!

Long wires could be the problem. Also, this module has an unusual level shifter on MISO which may cause problems since it is not properly implemented.

I assume you have slected 5 V, not 3.3V on the shield.

Which pin on the Mega is connected to SD chip select? Is the same pin number used in the SD begin call?

I put the scheme of this module as an attachment.

I tried both to connect the SD ship select on the Mega SS pin and on the pin 10, reflecting this in the SD begin call.
I will re-try with shorter wiring. I have also two other SD modules that I need to try.
One is combined with a LCD screen, similar to this one ili9341 2.2 and 2.4" Fast library for Arduino Uno, mini and nano - YouTube

SCH_IM120417017_ArduinoGPSshield.pdf (29.6 KB)

I modified my sketch to use shorter wires and the LowLatencyLogger works perfectly.

I started to modify the example for my accelerometer logger.

Instead of logging at regular time interval I want logging only when the new accelerometer data is available (every 10ms).

I broke the LowLatencyLogger example in three parts

InitSD() called once at the beginning of the execution
LogData() called each time accelerometer data is available
closefile() called at the end of the execution

I get this error when calling the InitSD():

Creating new file
error: createContiguous failed
SD errorCode: 0X19,0X0

My InitSD function is:

void InitSD() {
  uint32_t bgnBlock, endBlock;

  // Allocate extra buffer space.
  block_t block[BUFFER_BLOCK_COUNT];
  curBlock = 0;
  //block_t* curBlock = 0;
  Serial.println();

  // Find unused file name.
  if (BASE_NAME_SIZE > 6) {
    error("FILE_BASE_NAME too long");
  }
  while (sd.exists(binName)) {
    if (binName[BASE_NAME_SIZE + 1] != '9') {
      binName[BASE_NAME_SIZE + 1]++;
    } else {
      binName[BASE_NAME_SIZE + 1] = '0';
      if (binName[BASE_NAME_SIZE] == '9') {
        error("Can't create file name");
      }
      binName[BASE_NAME_SIZE]++;
    }
  }
  // Delete old tmp file.
  if (sd.exists(TMP_FILE_NAME)) {
    Serial.println(F("Deleting tmp file"));
    if (!sd.remove(TMP_FILE_NAME)) {
      error("Can't remove tmp file");
    }
  }
  // Create new file.
  Serial.println(F("Creating new file"));
  binFile.close();
  if (!binFile.createContiguous(sd.vwd(),
                                TMP_FILE_NAME, 512 * FILE_BLOCK_COUNT)) {
    error("createContiguous failed");
  }
  // Get the address of the file on the SD.
  if (!binFile.contiguousRange(&bgnBlock, &endBlock)) {
    error("contiguousRange failed");
  }
  // Use SdFat's internal buffer.
  uint8_t* cache = (uint8_t*)sd.vol()->cacheClear();
  if (cache == 0) {
    error("cacheClear failed");
  }

  // Flash erase all data in the file.
  Serial.println(F("Erasing all data"));
  uint32_t bgnErase = bgnBlock;
  uint32_t endErase;
  while (bgnErase < endBlock) {
    endErase = bgnErase + ERASE_SIZE;
    if (endErase > endBlock) {
      endErase = endBlock;
    }
    if (!sd.card()->erase(bgnErase, endErase)) {
      error("erase failed");
    }
    bgnErase = endErase + 1;
  }
  // Start a multiple block write.
  if (!sd.card()->writeStart(bgnBlock, FILE_BLOCK_COUNT)) {
    error("writeBegin failed");
  }
  // Initialize queues.
  emptyHead = emptyTail = 0;
  fullHead = fullTail = 0;

  // Use SdFat buffer for one block.
  emptyQueue[emptyHead] = (block_t*)cache;
  emptyHead = queueNext(emptyHead);

  // Put rest of buffers in the empty queue.
  for (uint8_t i = 0; i < BUFFER_BLOCK_COUNT; i++) {
    emptyQueue[emptyHead] = &block[i];
    emptyHead = queueNext(emptyHead);
  }
  Serial.println(F("Logging - type any character to stop"));
  // Wait for Serial Idle.
  Serial.flush();
  delay(1);
}

Did you call sd.begin()?

:-[
My stupid mistake...

Now I have an error executing the

  while (sd.exists(binName)) { loop.

My arduino resets when it comes to this line...
Itthe lowlatencylogger exampe works so it must be my mistake splitting the code

On my Arduino UNO board I ran LowLatencyLogger and had no errors. However when running the same code on my Teensy4.0, I got "error: createContiguous failed" .

My solution was to change:
#define FILE_BASE_NAME "droneData"
to:
#define FILE_BASE_NAME "droneD"

Apparently any file name longer than 6 characters gave me the "error: createContiguous failed" error with the Teensy 4.0.

On a side note (I think it is appropriate here since the thread is simply titled "Error using Fatlib LowLatencyLogger"), I got the following error when running the same code (that worked fine on my UNO), on my Teensy 4.0:

Can't access SD card. Do not reformat.
SD errorCode: 0X30,0X2

I solved it by:

  1. changing the Vcc pin of my MicroSDcard Module from 3.3V to 5V
    and:
  2. Lowering "SD_SCK_MHZ(50)" to "SD_SCK_MHZ(25)"

Hopefully this can save someone 3 hours of their life.

Thibag64:
I modified my sketch to use shorter wires and the LowLatencyLogger works perfectly.

I started to modify the example for my accelerometer logger.

Instead of logging at regular time interval I want logging only when the new accelerometer data is available (every 10ms).

I broke the LowLatencyLogger example in three parts

InitSD() called once at the beginning of the execution
LogData() called each time accelerometer data is available
closefile() called at the end of the execution

I get this error when calling the InitSD():

Creating new file

error: createContiguous failed
SD errorCode: 0X19,0X0





My InitSD function is:



void InitSD() {
  uint32_t bgnBlock, endBlock;

// Allocate extra buffer space.
  block_t block[BUFFER_BLOCK_COUNT];
  curBlock = 0;
  //block_t* curBlock = 0;
  Serial.println();

// Find unused file name.
  if (BASE_NAME_SIZE > 6) {
    error("FILE_BASE_NAME too long");
  }
  while (sd.exists(binName)) {
    if (binName[BASE_NAME_SIZE + 1] != '9') {
      binName[BASE_NAME_SIZE + 1]++;
    } else {
      binName[BASE_NAME_SIZE + 1] = '0';
      if (binName[BASE_NAME_SIZE] == '9') {
        error("Can't create file name");
      }
      binName[BASE_NAME_SIZE]++;
    }
  }
  // Delete old tmp file.
  if (sd.exists(TMP_FILE_NAME)) {
    Serial.println(F("Deleting tmp file"));
    if (!sd.remove(TMP_FILE_NAME)) {
      error("Can't remove tmp file");
    }
  }
  // Create new file.
  Serial.println(F("Creating new file"));
  binFile.close();
  if (!binFile.createContiguous(sd.vwd(),
                                TMP_FILE_NAME, 512 * FILE_BLOCK_COUNT)) {
    error("createContiguous failed");
  }
  // Get the address of the file on the SD.
  if (!binFile.contiguousRange(&bgnBlock, &endBlock)) {
    error("contiguousRange failed");
  }
  // Use SdFat's internal buffer.
  uint8_t* cache = (uint8_t*)sd.vol()->cacheClear();
  if (cache == 0) {
    error("cacheClear failed");
  }

// Flash erase all data in the file.
  Serial.println(F("Erasing all data"));
  uint32_t bgnErase = bgnBlock;
  uint32_t endErase;
  while (bgnErase < endBlock) {
    endErase = bgnErase + ERASE_SIZE;
    if (endErase > endBlock) {
      endErase = endBlock;
    }
    if (!sd.card()->erase(bgnErase, endErase)) {
      error("erase failed");
    }
    bgnErase = endErase + 1;
  }
  // Start a multiple block write.
  if (!sd.card()->writeStart(bgnBlock, FILE_BLOCK_COUNT)) {
    error("writeBegin failed");
  }
  // Initialize queues.
  emptyHead = emptyTail = 0;
  fullHead = fullTail = 0;

// Use SdFat buffer for one block.
  emptyQueue[emptyHead] = (block_t*)cache;
  emptyHead = queueNext(emptyHead);

// Put rest of buffers in the empty queue.
  for (uint8_t i = 0; i < BUFFER_BLOCK_COUNT; i++) {
    emptyQueue[emptyHead] = &block[i];
    emptyHead = queueNext(emptyHead);
  }
  Serial.println(F("Logging - type any character to stop"));
  // Wait for Serial Idle.
  Serial.flush();
  delay(1);
}

chessbucket:
My solution was to change:
#define FILE_BASE_NAME "droneData"
to:
#define FILE_BASE_NAME "droneD"

Apparently any file name longer than 6 characters gave me the "error: createContiguous failed" error with the Teensy 4.0.

Files names on SD cards need to adhere to the 8.3 notation. "droneData" is already 9 characters so would not have worked on an Uno either. "droneD" is six characters and allows e.g. names up to e.g. "droneD99".