Hello im working on reverse engineering a 2019 Jeep Cherokee cluster, ive been able to connect to CAN-C with one shield but I cannot get the second shield to connect to CAN-IHS.
I have both shields stacked on the UNO and they both have pin 9 default CS pin and pin 2 default INT pin
I am using MCP_CAN_lib by coryjfowler
#include <mcp_can.h>
#include <SPI.h>
// Define chip select pins for each MCP2515 CAN controller
MCP_CAN CAN0(9); // CAN-C on CS pin 9
MCP_CAN CAN1(10); // CAN-IHS on CS pin 10
void setup() {
Serial.begin(115200);
SPI.begin();
// Initialize CAN-C (500 kbps, standard CAN)
if (CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK) {
Serial.println("CAN-C Initialized Successfully!");
} else {
Serial.println("Error Initializing CAN-C...");
}
// Initialize CAN-IHS (125 kbps, extended CAN)
if (CAN1.begin(MCP_ANY, CAN_125KBPS, MCP_16MHZ) == CAN_OK) {
Serial.println("CAN-IHS Initialized Successfully!");
} else {
Serial.println("Error Initializing CAN-IHS...");
}
// Set both controllers to normal mode
CAN0.setMode(MCP_NORMAL);
CAN1.setMode(MCP_NORMAL);
}
// Send message to CAN-C using standard 11-bit ID
void sendCAN_C(int identifier, int dlc, byte data[]) {
byte result = CAN0.sendMsgBuf(identifier, MCP_STD, dlc, data);
Serial.println(result == CAN_OK ? "Sent on CAN-C!" : "Failed to send on CAN-C...");
}
// Send message to CAN-IHS using extended 29-bit ID
void sendCAN_IHS(int identifier, int dlc, byte data[]) {
byte result = CAN1.sendMsgBuf(identifier, MCP_EXT, dlc, data);
Serial.println(result == CAN_OK ? "Sent on CAN-IHS!" : "Failed to send on CAN-IHS...");
}
void loop() {
if (Serial.available()) {
char input[64] = {0};
Serial.readBytesUntil('\n', input, sizeof(input) - 1);
Serial.print("Received: ");
Serial.println(input);
// Parse input: ID,DLC,DATA0,DATA1,...
char *token = strtok(input, ",");
if (!token) return;
int identifier = atoi(token);
token = strtok(NULL, ",");
if (!token) return;
int dlc = atoi(token);
if (dlc < 0 || dlc > 8) return;
byte data[8] = {0};
for (int i = 0; i < dlc; i++) {
token = strtok(NULL, ",");
if (token) data[i] = (byte)atoi(token);
}
// Debug: Print data bytes
Serial.print("Data (HEX): ");
for (int i = 0; i < dlc; i++) {
Serial.print("0x");
if (data[i] < 0x10) Serial.print("0");
Serial.print(data[i], HEX);
Serial.print(" ");
}
Serial.println();
sendCAN_C(identifier, dlc, data);
sendCAN_IHS(identifier, dlc, data);
}
}
still learning as I go, sorry if its a simple fix