Hello,
I'm doing a sketch with the sdfat library, for high speed data logging (GPS+accelerometer).
I'm using the RawWrite.ino from the examples (modified version). I mean I create N blocks in the contiguous file. But after serveral tests, I "break" the SD card (I'm done with 2 cards).
The SD is corrupt and I can't format it.
In one SD, i get this error in linux when I try mounting it ->Error mounting: Mount: /dev/sdb1: Can't read superblock.
Why I'm "breaking" the SD card? There are any problem with the creation the blocks in SD card? Is there any way to fix the card?
I use this code for the SD card (only paste the code associate with the SD card):
void setup() {
.
.
.
if (!sd.begin(SS, SPI_FULL_SPEED)) sd.initErrorHalt();
// delete possible existing file
sd.remove("TEST.CSV");
// create a contiguous file (BLOCK_COUNT = 10000UL)
if (!file.createContiguous(sd.vwd(), "TEST.CSV", 512UL*BLOCK_COUNT)) {
error("createContiguous failed");
}
// get the location of the file's blocks (uint32_t bgnBlock, endBlock;)
if (!file.contiguousRange(&bgnBlock, &endBlock)) {
error("contiguousRange failed");
}
// clear the cache and use it as a 512 byte buffer
pCache = (uint8_t*)sd.vol()->cacheClear();
// fill cache with eight lines of 128 bytes each
memset(pCache, ' ', 512);
for (uint16_t i = 0; i < 512; i += 128) {
// put line number at end of line then CR/LF
pCache[i + 126] = '\r';
pCache[i + 127] = '\n';
}
// tell card to setup for multiple block write with pre-erase
if (!sd.card()->erase(bgnBlock, endBlock)) error("card.erase failed 1");
if (!sd.card()->writeStart(bgnBlock, BLOCK_COUNT)) {
error("writeStart failed 1");
}
.
.
.
}
void loop(){
.
.
.
//with a for, I save values in pCache
for (uint8_t i = 0; i < SIZE; i++) {
...
pCache[i] = any_value();
...
}
// each block (512 bytes), I write data in SD. (512 bytes is when line == 3)
if(line == 3){
if (!sd.card()->writeData(pCache)) error("writeData failed");
pCache = (uint8_t*)sd.vol()->cacheClear();
}
.
.
.
}