Problem on connecting two SPI modules on arduino

Trying to connect two SPI modules to arduino ( CAN-BUS module for Arduino - ElectroYA RC - Racing Drones and a SD module) in order to read from my car CAN and save a log on the SD card for emulating the information indoor, but having some problem in making both the modules work at the same time.
If I test the module individually, they work without a problem, if i connect both of them and try just to read from the CAN module, i receive no information, but the moment I disconect the SD card module, the data starts to pour. I have connected the SKC, MOSI, MISO and the INT (for the CAN module), and the CS to pins 10 for the CAN module and 4 for the SD module.
I have attached below the arduino code for checking the number of msg/sec from the CAN BUS.

#include <SPI.h>
#include <mcp2515.h>
 
struct can_frame canMsg;
MCP2515 mcp2515(10);
int cntr = 0;
unsigned long oldTime = 0;
 
 
void setup() {
  Serial.begin(115200);
 
  mcp2515.reset();
  mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ);
  mcp2515.setNormalMode();
 
  Serial.println("------- CAN Speedtest ----------");
}
 
void loop() {
  if (mcp2515.readMessage(&canMsg) == MCP2515::ERROR_OK) {
    cntr++;
  }
 
  if ((millis()-oldTime)>1000) {
    oldTime = millis();
    Serial.print(cntr);
    Serial.println(" msg/sec");
    cntr = 0;      
  }
}

Also, i will attach the code for reading and logging the data to the sd card.

#include <SPI.h>
#include <SD.h>
#include <mcp2515.h>

File myFile;

const int button = 7;
bool read_switch = false;

struct can_frame canMsg;
MCP2515 mcp2515(10);


void setup() {
  Serial.begin(115200);

  Serial.print("Initializing SD card...");
  if (!SD.begin(4)){
    Serial.println("initialization failed!");
  }
  if (!SD.begin(4)) Serial.println("initialization done.");
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
  Serial.println("File opened");  
  
  mcp2515.reset();
  mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ);
  mcp2515.setNormalMode();
  
  Serial.println("------- CAN Read ----------");
  Serial.println("ID  DLC   DATA");
}

void loop() {  

  if (digitalRead(button) == HIGH){
    Serial.println("Button pressed");
    myFile.println("Button pressed");
    if (read_switch == true){
      read_switch = false;
      myFile.println("File closed");
      myFile.close();
      Serial.println("File closed");
    } else read_switch = true;
    delay(500);
  }
    
  if (mcp2515.readMessage(&canMsg) == MCP2515::ERROR_OK  && read_switch == true) {
    myFile.print(millis());
    myFile.print("-");    
    myFile.print(canMsg.can_id); // print ID
    myFile.print("-"); 
    myFile.print(canMsg.can_dlc); // print DLC
    myFile.print("-");
    
    for (int i = 0; i<canMsg.can_dlc; i++)  {  // print the data
      myFile.print(canMsg.data[i]);
      myFile.print(" ");
    }

    myFile.println();
    Serial.println(".");      
  }
}

Also, i have tested the hardware setup with 2 different CAN modules, unfortunatelly, I only have one SD card module, but if tested independently, it works perfectly.
Can't seem to find any problem, I'm stuck.

  1. I don't see where you select the chip select pin for either module. You are using different pins for each when you have both connected, yes?

  2. We have seen where SD modules do not stop driving their MISO pin when their chip select is not active. Best design would be to buffer MISO from the SD and only enable it when the SD CS is active with something like 1 gate of a 74xx125 kind of part.

Update:
Took a closer look at the sd card module and something doesn't seem right. The MISO pin (what should be the MISO pin) is noted MOSO. Now, is that a typo, or are the master output/slave output SPI modules?

No way for us to know, we haven't seen the module or it's schematic.
You said it works fine by itself, presumably connected to MOSI and MISO, which can both be active at the same time during an SPI transfer, so that would tend to point to mismarking.
The module is pretty simple, not that many connections, so you could probably buzz out the signals with a multimeter and see what is connected to what.

CrossRoads:

  1. I don't see where you select the chip select pin for either module. You are using different pins for each when you have both connected, yes?

In the first example, i only set the pin 10 for the CAN modulr, giving the fact i don't use the SD module. Keep in mind it is connected though. And yes, i use pin 10 for the CAN and pin 4 for the SD.
Should i declare the SD library and the cs pin, even though i am not trying to send data to it?

So something happened. When i tested the hardware config, i haven't placed a Sd card in the sd module. The minute i add one, the can bus starts receiving data and savong it on the sd. Also, i receive data on the serial port even if i not declared the sd library and the cs pin. Can someone explain why is that, please?

Is this a microSD module? If so, they typically do not properly release MISO when their CS is not active. So they work fine if there's no other SPI slave, but don't play well with others. Here's the fix: