Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SdFat + MCP_CAN_lib #23

Open
JJGR93 opened this issue May 6, 2021 · 0 comments
Open

SdFat + MCP_CAN_lib #23

JJGR93 opened this issue May 6, 2021 · 0 comments

Comments

@JJGR93
Copy link

JJGR93 commented May 6, 2021

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()
{
  //...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant