Hey y'all!
I'm pretty new to this Arduino stuff. I'm working on what I thought would be a simple project. My car is lacking a screen for displaying tyre pressure. It has a TPMS, but there's only a LED signaling that the tyre pressure is too low. No information on which tyre or exact pressures. My idea was to utiliize the CAN bus to get these information and then show it on a simple monochrome display, but I can't seem to get two Arduino Nano clones to communicate over a MCP2515.
This is my scematic (I know it's a different Nano, but the pinout is identical and I haven't found a high res image of mine):
Both MCUs are powered via their USB connector.
I'm using the arduino-mcp2515 library in version 1.2.1. The sketches are taken straight from the examples of said library, with only few adjustments described in the comments.
This is the sketch on the sending MCU:
#include <SPI.h>
#include <mcp2515.h>
struct can_frame canMsg1;
struct can_frame canMsg2;
MCP2515 mcp2515(10);
void setup() {
canMsg1.can_id = 0x0F6;
canMsg1.can_dlc = 8;
canMsg1.data[0] = 0x8E;
canMsg1.data[1] = 0x87;
canMsg1.data[2] = 0x32;
canMsg1.data[3] = 0xFA;
canMsg1.data[4] = 0x26;
canMsg1.data[5] = 0x8E;
canMsg1.data[6] = 0xBE;
canMsg1.data[7] = 0x86;
canMsg2.can_id = 0x036;
canMsg2.can_dlc = 8;
canMsg2.data[0] = 0x0E;
canMsg2.data[1] = 0x00;
canMsg2.data[2] = 0x00;
canMsg2.data[3] = 0x08;
canMsg2.data[4] = 0x01;
canMsg2.data[5] = 0x00;
canMsg2.data[6] = 0x00;
canMsg2.data[7] = 0xA0;
while (!Serial);
Serial.begin(115200);
mcp2515.reset();
// The crystal on my MCP2515 reads "8.000",
// so I set the oscillator frequency to 8 MHz.
mcp2515.setBitrate(CAN_125KBPS, MCP_8MHZ);
mcp2515.setNormalMode();
Serial.println("Example: Write to CAN");
}
void loop() {
mcp2515.sendMessage(&canMsg1);
mcp2515.sendMessage(&canMsg2);
Serial.println("Messages sent");
delay(100);
}
This is the sketch on the receiving MCU:
#include <SPI.h>
#include <mcp2515.h>
struct can_frame canMsg;
MCP2515 mcp2515(10);
void setup() {
Serial.begin(115200);
mcp2515.reset();
// Same as above: Frequency set to 8 MHz.
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();
}
}
The sending sketch seems to send CAN frames. Return value of MCP2515::sendMessage(...)
is 0
/MCP2515::ERROR_OK
the first two or three times, then it's 2
/MCP2515::ERROR_ALLTXBUSY
. After setting the jumper to use the 120 Ω resistor, it seems to always be 0
/MCP2515::ERROR_OK
.
The receiving sketch receives nothing. Return value of MCP2515::readMessage(...)
is always 5
/MCP2515::ERROR_NOMSG
.
I have multiple Arduino Nano MCUs and MCP2515 modules lying around. I tried all of them in different combinations, so I can rule out broken hardware.
As the two MCP2515 modules are the ends of the bus, both are having the jumper for the 120 Ω termination resistor set. I tried it without the jumper, but to no avail.
Does anyone know what I'm doing wrong?