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:
- changing the Vcc pin of my MicroSDcard Module from 3.3V to 5V
and:
- 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);
}