1

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.

5
  • I don't have any good ideas, so here's one bad idea: print something showing that it made it to 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?
    – timemage
    Dec 27 '20 at 13:11
  • I got the same "bad idea" but even with the close() (and withouthe the if(myFile)) The SD card don't write anything. If I process to write before using MCP2515, it works fine. It look like a problem with the ISP to determinate the slave to talk to. My board is a seeeduino V4.0
    – Thanatheos
    Dec 28 '20 at 6:01
  • That is more or less what I think, but I didn't find anything confirming that when I went looking through the code of the two libraries. At some point I may try setting up an UNO with an SD card and some SPI device as a stand-in for your MCP2515 (I don't have one of these). Though, by then someone else may already have answered.
    – timemage
    Dec 28 '20 at 16:51
  • I did more digging, but I'm not turning up anything clear. In their example flagRecv should be volatile qualified, as 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.
    – timemage
    Dec 28 '20 at 21:43
  • Thank you for your help. The volatile don't help. Still the same issue. I tried to force the SPI to use the slave 4 (SD) and not the 9 (CANbus) 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.
    – Thanatheos
    Dec 29 '20 at 7:05
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.