Hi, thanks for your help!
as I announced yesterday, i made huge improvements using the continous method, that fat16lib uses in his waverp project.
additionally, I skipped the sprintf and went to a method comparable to what robtillaart suggested (although his seems a lot prettier, i'll try your struct method later today!).
for the initialization and usage, I stuck to fat16libs code example:
uint32_t bgnBlock, endBlock;
uint8_t* pCache;
// number of blocks in the contiguous file
#define BLOCK_COUNT 10000UL
// time to produce a block of data
#define MILLIS_PER_BLOCK 10
...
// create a contiguous file
char name[] = "RAWLOG00.TXT";
if (!file.createContiguous(&root, name, 512UL*BLOCK_COUNT)) error ("file.create");
// get the location of the file's blocks
if (!file.contiguousRange(&bgnBlock, &endBlock)) {
error("contiguousRange failed");
}
// clear the cache and use it as a 512 byte buffer
pCache = volume.cacheClear();
// fill cache with eight lines of 64 bytes each
memset(pCache, ' ', 512);
for (uint16_t i = 0; i < 512; i += 32) {
// put line number at end of line then CR/LF
pCache[i + 29] = '0' + (i/32);
pCache[i + 30] = '\r';
pCache[i + 31] = '\n';
}
// tell card to setup for multiple block write with pre-erase
if (!card.erase(bgnBlock, endBlock)) error("card.erase failed");
if (!card.writeStart(bgnBlock, BLOCK_COUNT)) {
error("writeStart failed");
}
but now to the more important part:
uint8_t data[8];
int i = 0;
char semik = ';';
char dPoint = ':';
char slash = '-';
long testid= 10401l;
void loop(){
data[0] = B01110011;
data[1] = B01110001;
data[2] = B01110111;
data[3] = B01110010;
data[4] = B01110001;
data[5] = B01110101;
data[6] = B01011001;
data[7] = B01110001;
// copy the time
memcpy(pCache+i*32,&t, sizeof t);
//copz the slash
pCache[i*32 + sizeof t] = slash;
//copy the id
memcpy(pCache+i*32 + (sizeof slash) + (sizeof t),&testid, sizeof testid);
//copz the dpoint
pCache[i*32 + (sizeof slash) + (sizeof t)+ (sizeof testid)] = dPoint;
// copy the data
memcpy(pCache+i*32 + (sizeof slash) + (sizeof t)+ (sizeof testid) + (sizeof dPoint),&data,sizeof data);
//copy the semikola
pCache[i*32 + sizeof data + (sizeof slash) + (sizeof t)+ (sizeof testid) + (sizeof dPoint)] = semik;
// write the cache every 16th time
i++;
if((i%16) == 0){
i=0;
if (!card.writeData(pCache)) error("writeData failed");
}
}
This works! I also changed my parser to accept the new code and data structure. I managed to write 15 times in 20 microseconds (!!!) and then the 16th time (the actual writing to the SD card) it takes less than 1 millisecond (600-800 microseconds) . So it's a massive improvement (x10) - and losing a maximum of 2 CAN messages, when actually writing to the SD should be acceptable.
i fixed the following problem, take a look at the next post - I'm leaving this here just for reference
BUT ...
when trying to put that code into my actual project I encountered a massive problem ... It collides with reading the CAN message out of the mcp2515 buffer .. as soon as i've read a message from the buffer, writing returns an error 11,FF ... if i comment out the receiving, it works -.- ...
I've already reveiwed the code that gets the message, as well as trying to free the tCan message, before writing to the SD ...
void loop(){
if (mcp2515_check_message()) {
tCAN message;
WRITING TO SD HERE WORKS
// read the message from the MCP2515 buffer
if (mcp2515_get_message(&message)) {
WRITING TO SD HERE FAILS ...
}
}
I REALLY DON'T want you to debug my code ... but aaaaany suggestion or hint (maybe you've encountered a comparable problem and had to ... I don't know ... touch your toes while writing to solve it ...)
@fat16lib ... what cache is actually used to write the data to the sd ? is it an SD card cache, or a cache of the ARdunio?