SdFat
SdFat copied to clipboard
SdFat + MCP_CAN_lib
Hi, first of all thank you for your work!
I've been researching and trying to make both Sd and MCP2515 work fine. The issue is that I must call function sd.begin everytime before reading from CAN, or CAN won't work.
Using SHARED_SPI.
Simplified code:
#include "mcp_can.h"
#include "SdFat.h"
ExFile file;
SdExFat sd;
MCP_CAN CAN(10);
void setup()
{
Serial.begin(115200);
initSD();
initCANBUS();
}
void loop()
{
readCANBUS();
saveSD();
initSD(); //THIS MUST BE CALLED OR NEXT readCANBUS() wont work.
}
void initSD()
{
sd.begin(53, SD_SCK_MHZ(16));
}
void saveSD()
{
file = sd.open("test", FILE_WRITE);
if (file)
{
file.print("test");
file.close();
}
}
void initCANBUS()
{
while (CAN_OK != CAN.begin(MCP_ANY, CAN_250KBPS, MCP_8MHZ))
{
delay(100);
}
CAN.setMode(MCP_NORMAL);
}
void readCANBUS()
{
//...
}
I have no idea what the MCP2515 library does or why there is a conflict. Can't help you.
Ok, thank you very much anyways!