i am using the elekfreaks shield with Arduino UNO and SparkFun Can Library. Everything's working fine. I tried to use coryjfowler's can Lib because i need dual can support. I connected 2 shield to Arduino, one shield with INT 2 and CS 10 and the other with INT 3 and CS 9. both CAN: Init OK Baudrate Successful and Configuration Mode Successful. i can see data incoming. The RX Led is blinking but nothing is being printed on the serial console. I tried the receive example with one shield attached only. But same problem. Everything is been initialized ok but i am not receiving anything. The shield is running on 16 Mhz. With the same setup i can start the receive example script from spark fun library and its working fine. (without changing any wires) what could be the problem?
// Demo: Dual CAN-BUS Shields, Data Pass-through
// Written by: Cory J. Fowler
// January 31st 2014
// This examples the ability of this library to support more than one MCP2515 based CAN interface.
#include <mcp_can.h>
#include <SPI.h>
unsigned long rxId;
byte len;
byte rxBuf[8];
byte txBuf0[] = {};
byte txBuf1[] = {};
MCP_CAN CAN0(10); // CAN0 interface usins CS on digital pin 10
MCP_CAN CAN1(9); // CAN1 interface using CS on digital pin 9
void setup()
{
Serial.begin(115200);
// init CAN0 bus, baudrate: 250k@16MHz
if(CAN0.begin(MCP_ANY, CAN_100KBPS, MCP_16MHZ) == CAN_OK){
Serial.print("CAN0: Init OK!\r\n");
CAN0.setMode(MCP_NORMAL);
pinMode(2, INPUT);
} else Serial.print("CAN0: Init Fail!!!\r\n");
// init CAN1 bus, baudrate: 250k@16MHz
if(CAN1.begin(MCP_ANY, CAN_100KBPS, MCP_16MHZ) == CAN_OK){
Serial.print("CAN1: Init OK!\r\n");
CAN1.setMode(MCP_NORMAL);
pinMode(3, INPUT);
} else Serial.print("CAN1: Init Fail!!!\r\n");
SPI.setClockDivider(SPI_CLOCK_DIV2); // Set SPI to run at 8MHz (16MHz / 2 = 8 MHz)
}
void loop(){
if(!digitalRead(2)){ // If pin 2 is low, read CAN0 receive buffer
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if(rxId == 0x130)
{
Serial.println("0x130 empfangen");
byte rxBuf[5] = {0x45,0x41,0x21,0x8F,0x57};
CAN1.sendMsgBuf(rxId, 0, len, rxBuf);
}
else
CAN1.sendMsgBuf(rxId, 0, len, rxBuf); // Immediately send message out CAN1 interface
}
if(!digitalRead(3)){ // If pin 3 is low, read CAN1 receive buffer
CAN1.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
Serial.print("ID: ");
Serial.print(rxId,HEX);
Serial.print(", ");
Serial.print("Data: ");
for(int i=0;i<len;i++)
{
Serial.print(rxBuf[i],HEX);
Serial.print(" ");
}
Serial.println("");
}
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/