I'm using a seeeduino V4.0 and a CAN-BUS shield v2.0 with industrial grade SD card.
I'm using the default library given by the wiki of seeed.
I've simulate a can bus with two mcp2515. I can read it without trouble and everything is fine.
I can write/read on the SD card with the exemple given in the SD library.
But when I use this example, the can bus and SD card start without error. The can bus read normally and show the can bus data. But when I read the SD card, the file is created but completly empty. I've tried to modify to write on a .txt instead of .csv and when I try a
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile)
{
...
}
else
{
Serial.println("error: file not reachable");
}
The "myFile" return false.
ps: I don't ask a lot of question here. Sorry for bad formating my question.
1 Answer 1
Despite the "the library example must be correct, It's work for other people before you", I'm not sure a lot of people make it works.
I've seen that even when the mcp2551 don't receive anything on can bus, the SPI bus is saturated by the mcp2551.
The solution was to use a simplest library make for 8MHz cristal chip. Modify it to works with standard 16MHz and use the interrupt pin (pin 2 on board) as interrupt.
If anybody got the same issue, just post a comment here and I'll do a better and more complete response.
Thank you very much @Timemage for your help
myFile.close();
You may not have any writes until you close(), flush(), or fill a sector. Given what you've shown and what I've read about the shield etc, it seems like this shoudn't be a problem though. Which Arduino are you using? You did not change the CS selection on the board right?volatile unsigned char flagRecv = 0;
But I have little confidence that this is actually the problem. I kind of expect that as a bug it would manifest differently if at all in this usage. It should be fixed though in any case. If it actually solves it though, let me know and I'll stick it as an answer.digitalWrite(4,LOW); digitalWrite(9,HIGH); if (!SD.begin(4)) { print error } print success myFile = SD.open("can.txt", FILE_WRITE);
and put ss 9 to low right after that. It show a success It read as usual but still nothing on the SD. Look like the spi is saturated by the mcp2515. If I remove the sd card, I got an error.