Can bus communication between TJA1050 and MCP2515 using MCP2551

Hello everyone!
I am currently working on a project trying to understand can bus communication. I firstly used the MCP2515 can bus module to gain an insight on how to establish a communication between the modules. As I established a communication, I tired to substituting one of the can bus modules with both a MCP2551 and a MCP2515 (receiver side) to understand deeper into the placement of capacitors, resistors and other vital components.
I have attached my schematic of the system, along with the corresponding code for the transceiver and receiver part. However, I am unable to receive messages between the TJA1050 and MCP2551. My primary hypothesis is that the can bus module in the transceiver segment is equipped with an 8MHz crystal, while I have installed a 16MHz crystal in the MCP2551 on the receiver side.
I'm reaching out to the community in search of valuable insights. Does anyone have suggestions or ideas on where I should begin my troubleshooting efforts?

I sincerely appreciate any assistance in advance!

//RECEIVER SIDE
#include <SPI.h>
#include <mcp2515.h>

struct can_frame canMsg;
MCP2515 mcp2515(10);


void setup() {
  Serial.begin(9600);
  
  mcp2515.reset();
  mcp2515.setBitrate(CAN_125KBPS, MCP_8MHZ);   
  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();      
  }
}
//TRANSCEIVER SIDE
#include <mcp2515.h>
#include <SPI.h>
struct can_frame frame;

MCP2515 mcp2515(10);

void setup() {
  while (!Serial);
  Serial.begin(9600);
  mcp2515.reset();
  mcp2515.setBitrate(CAN_125KBPS, MCP_8MHZ);
  mcp2515.setNormalMode();
  

}

void loop() {

  int sensorValue = analogRead(A0);
  byte high = (sensorValue >> 8) & 0xFF;
  byte low = sensorValue & 0xFF;
  frame.can_id = 0x003;
  frame.can_dlc = 4;
  frame.data[0] =  2;
  frame.data[1] = 5;
  frame.data[2] =  high;
  frame.data[3] = low;
  
  mcp2515.sendMessage(&frame);
  delay(100);

  Serial.println("Message sent");


}

This statement needs to reflect the exact frequency of the crystal. If you get errors check the library to see if your choice is supported and how to state it.

Yes, I have tried to change the 8MHz to 16MHz but nothing changed. I've also tried to understand the library and make some changes which did not make a difference. This is the library I'm using GitHub - autowp/arduino-mcp2515: Arduino MCP2515 CAN interface library

I am not familiar with the libraries but can only suggest playing with the frequencies. Have you ever had them communicating between each other? Those two chips MPC2551 is a transceiver and the MPC2515 is a controller, they work together but do not interchange. The CAN bus is well defined, I am curious what you are trying to accomplish, adding capacitance and resistors generally causes problems and bus failure.

The CAN bus is a differential 60 Ohm bus. The physical ends need to be terminated with a 120 Ohm resister, no more no less. It can be up to about a mile long depending on the baud. I have not had good results when the bus is under a meter (3 feet). You have to have both a transmitter and a receiver on the bus or it will not work. The reason is the in frame acknowledge bit. The acknowledge will be done automatically by any node receiving the transmission.

When playing with modules I highly recommend you do it on a bus with two other units that are working. Cory Fowler has a great can library mcp-can, it is easy to find and comes with a good code for a transmitter and a receiver. With that working you can then test your parts.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.