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");
}