MCP2515 Can Module with Mega 2560 Problems

Hallo zusammen

I tried to conntect two Arduino Mega with two joy-it MCP 2515 can modules.

I use the mcp2515.h library, the standard test programm and also the standard connections. The onls difference is that they use a UNO instead of the MEGA I use.

Connections:
int => D2 5V measured
SCK => D13 0V measured
Sl => D11 0V measured
SO => D12 0V measured
CS => D10

At the CS pin (10) I can read a signal with the oszilloskop.KO It does not change the shape if I change the Baudrate!?! It does change if I delete one message in the send sketch and it also changes if I add a delay inbetween the two messages.
I cannot measure any signal on the other pins!?!

GND => GND
VCC1=> 5V
VCC => 5V

CanH and CanL are at about 2.3 V. No “signals” measured.

In one post I read that with the MEGA instead of the UNO not all baudrates work. There it’s told that one should change from 550k to 250K! I have tested all rates without any changes.

Another post tells to change pins??? 50, 51, … instead of the 10 to 13???

Programm to send: (Standard Library!)

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

struct can_frame canMsg1;
struct can_frame canMsg2;
MCP2515 mcp2515(10);


void setup() {

 while (!Serial);
  Serial.begin(112500);
  SPI.begin();
 
  mcp2515.reset();
  mcp2515.setBitrate(CAN_250KBPS);
  mcp2515.setNormalMode();
 
  Serial.println("Example: Write to CAN");
  canMsg1.can_id  = 0x0FF;
  canMsg1.can_dlc = 8;
  canMsg1.data[0] = 0xFF;
  canMsg1.data[1] = 0xFF;
  canMsg1.data[2] = 0xFF;
  canMsg1.data[3] = 0xFF;
  canMsg1.data[7] = 0x00;

  canMsg2.can_id  = 0x000;
  canMsg2.can_dlc = 8;
  canMsg2.data[0] = 0x00;
  canMsg2.data[1] = 0x00;
  canMsg2.data[2] = 0x00;
  canMsg2.data[3] = 0x00;
  canMsg2.data[4] = 0x00;
  canMsg2.data[5] = 0x00;
  canMsg2.data[6] = 0x00;
  canMsg2.data[7] = 0x00;
 
}

void loop() {
 
if (mcp2515.sendMessage(&canMsg1) == MCP2515::ERROR_OK){
  Serial.println("Messages sent");
}
else {
  Serial.println("Msg1 TX error");
}     
if (mcp2515.sendMessage(&canMsg2) == MCP2515::ERROR_OK) {
  Serial.println("Messages sent");
}
else {
  Serial.println("Msg2 TX error");
}

 
  delay(500);

}
[Code]

Code for reading:

[code]
#include <SPI.h>
#include <mcp2515.h>

struct can_frame canMsg;
MCP2515 mcp2515(10);


void setup() {
  Serial.begin(115200);
  SPI.begin();
  
  mcp2515.reset();
  mcp2515.setBitrate(CAN_250KBPS);
  mcp2515.setNormalMode();
  
  Serial.println("------- CAN Read ----------");
  Serial.println("ID  DLC   DATA");
}

void loop() {
  
  if (mcp2515.readMessage(&canMsg) == MCP2515::ERROR_OK) {
      
    Serial.print(canMsg.can_id, HEX); // print ID
    Serial.print(" "); 
    Serial.print(canMsg.can_dlc, HEX); // print DLC
    Serial.print(" ");
    
    for (int i = 0; i<canMsg.can_dlc; i++)  {  // print the data
        
      Serial.print(canMsg.data[i],HEX);
      Serial.print(" ");

    }

    Serial.println();      
  }

}