Skip to content

SdFat + MCP_CAN_lib #23

Description

@JJGR93

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()
{
  //...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions