Dear all,
I have a CAN-BUS Shield V2.0 connected to the CAN-BUS device CAN CASE XL.
The problem is that I do not receive CAN messages and not even get the CAN BUS ID.
I try to get the connection working with the example “receive_check” in which I also integrated sending of CAN BUS messages (See code).
got correct wiring
set baudrate correct
got message “CAN init ok!”
The CAN CASE XL sends and receives CAN messages for testing.
The CAN CASE XL reports that it receives CAN BUS Messages from the CAN-BUS Shield.
The RX and TX LEDs on the CAN-BUS Shield are both flickering.
The INT LED does NOT glow.
The funtion CAN.checkReceive() returns “4” (instead of “3”).
The function CAN.getCanId() returns nothing.
Here the code
// demo: CAN-BUS Shield, receive data with check mode
// send data coming to fast, such as less than 10ms, you can use this way
// loovee, 2014-6-13
// MRE alles von Shield for Raspberry Pi (MCP2518FD) gelöscht
#include <SPI.h>
// For Arduino MCP2515 Hat:
// SPI_CS Pin: D9
#include “mcp2515_can.h”
const int SPI_CS_PIN = 9;
//const int CAN_INT_PIN = 2;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
void setup() {
SERIAL_PORT_MONITOR.begin(115200);
// while the serial stream is not open, do nothing:
while (!Serial) ;
while (CAN_OK != CAN.begin(CAN_250KBPS)) { // init can bus : baudrate = 500k // MRE - auf CLAAS CAN angepasst 250k
SERIAL_PORT_MONITOR.println(“CAN init fail, retry…”);
delay(100);
}
SERIAL_PORT_MONITOR.println(“CAN init ok!”);
}
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};
void loop() {
// send data: id = 0x00, standrad frame, data len = 8, stmp: data buf
stmp[7] = stmp[7] + 1;
if (stmp[7] == 100) {
stmp[7] = 0;
stmp[6] = stmp[6] + 1;
if (stmp[6] == 100) {
stmp[6] = 0;
stmp[5] = stmp[5] + 1;
}
}
CAN.sendMsgBuf(0x00, 0, 8, stmp);
delay(100); // send data per 100ms
SERIAL_PORT_MONITOR.println(“CAN BUS sendMsgBuf ok!”);
unsigned char len = 0;
unsigned char buf[8];
SERIAL_PORT_MONITOR.print("CAN.checkReceive(): ");
SERIAL_PORT_MONITOR.println(CAN.checkReceive());
// if (CAN_MSGAVAIL == CAN.checkReceive()) { // check if data coming
SERIAL_PORT_MONITOR.println(“get CANBUS data”);
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
unsigned long canId = CAN.getCanId();
SERIAL_PORT_MONITOR.println("-----------------------------");
SERIAL_PORT_MONITOR.print("Get data from ID: 0x");
SERIAL_PORT_MONITOR.println(canId, HEX);
for (int i = 0; i < len; i++) { // print the data
SERIAL_PORT_MONITOR.print(buf[i], HEX);
SERIAL_PORT_MONITOR.print("\t");
}
SERIAL_PORT_MONITOR.println();
/* }
else
{
SERIAL_PORT_MONITOR.println(“no CANBUS data”);
}*/
}
Best regards
Max