cory.j.fowler wrote: I thought I posted before I left work... First, you didn't mention having power connected, just ground, but I will assume you have power (+5V) connected to the CAN shield. Second, the Leonardo does not have SPI on its Digital 11-13 pins. SPI is only available on the ICSP header. You mentioned connecting the two with wires, can you clarify where you have the shield connected on the Leonardo? (Digital pin 10 is still used for the shield's CS and digital pin 2 for the interrupt input.) Third, confirm MOSI is connected to MOSI, MISO to MISO and CLK to CLK... While its not crucial for operation, the Leonardo's /RESET line should be tied to the shield's /RESET line so everything starts in a known state. Also, I would use the version of the library located on my GitHub. The receive example you posted is still using the Arduino's interrupt handler which will cause the Arduino to hang during operation due to how the interrupts are used on the shield and the version of the library that example comes with has bugs.First of all, thank you for you answer.
Of course, I connected power pin, just forget to mention it.
After I wrote all these posts I found that CAN shield is not compatible with Leonardo, so I took my UNO and tried a slightly modified example from your github library:
Code: // demo: CAN-BUS Shield, receive data #include <mcp_can.h> #include <SPI.h> long unsigned int rxId; unsigned char len = 0; unsigned char rxBuf[8]; MCP_CAN CAN0(10); // Set CS to pin 10 void setup() { delay(5000); Serial.begin(115200); if(CAN0.begin(CAN_100KBPS) == CAN_OK) Serial.print("can init ok!!\r\n"); else Serial.print("Can init fail!!\r\n"); // init can bus : baudrate = 100k pinMode(2, INPUT); // Setting pin 2 for /INT input Serial.println("MCP2515 Library Receive Example..."); } void loop() { if(!digitalRead(2)) // If pin 2 is low, read receive buffer { CAN0.readMsgBuf(&len, rxBuf); // Read data: len = data length, buf = data byte(s) rxId = CAN0.getCanId(); // Get message ID Serial.print("ID: "); Serial.print(rxId, HEX); Serial.print(" Data: "); for(int i = 0; i<len; i++) // Print each byte of the data { if(rxBuf[i] < 0x10) // If data byte is less than 0x10, add a leading zero { Serial.print("0"); } Serial.print(rxBuf[i], HEX); Serial.print(" "); } Serial.println(); } } /********************************************************************************************************* END FILE *********************************************************************************************************/That gives me this output:
Code: can init ok!! MCP2515 Library Receive Example...So, as I see, the library itself works, but after that there's complete silence. No RX blinking, no messages received. I have CAN wires connected to my car's wires, and it is know to work because CAN adapter for my clarion stereo works fine.
What else could I check to receive something?
Statistics : Posted by cherkasoff • on Tue Jan 28, 2014 4:25 pm • Replies 11 • Views 72