Page 1 of 1

Re: Arduino CAN BUS monitoring tool

Posted: 2015 Dec 20 09:05
by TheMatrix
Seem very useful, Thanks for implementing this communication protocol. I will try it in my car.
I am also using Excel since years to sort my CAN frames. I was looking for a better inexpensive tool. Thanks for your work, and many thanks for Sharing.

Re: Arduino CAN BUS monitoring tool

Posted: 2015 Dec 21 00:57
by linuxkidd
latonita wrote:Guys,

Just want to share my tool to sniff CAN bus using Arduino + CAN BUS Shield. Link on github: This is an implementation of CAN232 serial protocol. Use it with software that understands it.

First, I started to use CAN_BUS_Shield library to read data and that was okay. Then I realized I need a software to visualize the data - and I used excel. But then I understood I need to interact with the bus and I decided to do it in some standard way - and just made an implementation of serial can bus protocol initially proposed by Lawicel and their CAN232/CANUSB. There a many tools which can work with this protocol. In my studies I use free tool called CANHacker v.2.00.01 (I found working downloadable link on this page: ... ddeaec14b1)

Step 1. Get my arduino-canbus-monitor. Build and upload to arduino. (I tested this on Arduino Uno)
Step 2. Download CANHacker or another analyzer tool which support serial can232 protocol. Choose a proper COM port.
Step 3. Have fun! Monitor your can bus, save traces, send messages, do what your analyzer/visualizer software can.

This arduino-canbus-protocol tool is free - everybody is welcome to fork and enhance it. If you like the tool or have a question/proposal - just drop me a line here or on github.
Hey Iatonita,
I'm using the Seeedstudio CAN-shield for my sniffing and prototyping.. I have however just picked up 3 of low cost SPI bus CAN adapters from amazon (link)

Wondering if you could help me determine the proper CNF register values to get 250kbps on an 8mhz clocked MCP2515 with the same timings as these provide for 16mhz:
#define MCP_16MHz_250kBPS_CFG1 (0x41)
#define MCP_16MHz_250kBPS_CFG2 (0xF1)
#define MCP_16MHz_250kBPS_CFG3 (0x85)

I've tried the bit timing calculator here ( ... alculator/), but while I can sniff traffic using the first few settings, it causes comms issues with other nodes on the bus whereas the ones listed above for the 16mhz clocked chip do not.

Thanks to anyone who can help!

Re: Arduino CAN BUS monitoring tool

Posted: 2015 Dec 21 12:29
by linuxkidd
I seem to have determined the answer... Found in the MCP2515 datasheet, the full details of each config bit set by the CNF1|2|3 values.

At this time, the following seems to operate quite well:
#define MCP_8MHz_250kBPS_CFG1 (0x40)
#define MCP_8MHz_250kBPS_CFG2 (0xF1)
#define MCP_8MHz_250kBPS_CFG3 (0x85)

All of the params configured use multiples of a value called Tq, which is calculated from the 6 LSBs of the CNF1 ( aka Baud Rate Prescaler or BRP ). Tq is calculated as: 2 x (BRP + 1)/Fosc
Where Fosc = Frequency of the Oscillator.

The good values for 16Mhz have the BRP set to 1, thus:
2 x ( 1 + 1 ) / 16Mhz = Tq of 0.00000025

Since the clock on the linked CAN SPI adapter is 1/2 that of the CAN-Shield, I reduced the BRP to 0:
2 x ( 0 + 1 ) / 8Mhz = Tq of 0.00000025

YEAH! Stable operations on my bus.. :D

fwiw, I'm using this to hack the RV-C (Recreational Vehicle CAN bus) on my 2016 Allegro Bus 45OP Motorhome.. :) The good news is that RV-C spec is open and quite well documented. Which is a damn good thing, since they use extended CanID, and overload it with the command, priority, data byte count and source address. Would have been difficult to figure that out.


Re: Arduino CAN BUS monitoring tool

Posted: 2017 Aug 28 00:05
by tandm87
Nothing happens,

i have a test with Arduino Nano v3 with MCP 2515 CAN Interface & OBD2.
i have to connect Arduino Nano v3 with MCP 2515 CAN and connect MCP 2515 CAN Interface with OBD2 (on my car is Chevrolet Captiva 2008) by H-CAN to Pin 1, L-CAN to Pin4.

MCP2515 module : Image

Wiring Diagram: Image

and i use library MCP-can-lib-master :

My code:

Code: Select all

#include <mcp_can.h>
#include <SPI.h>

long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
char msgString[128];                        // Array to store serial string

#define CAN0_INT 2                              // Set INT to pin 2
MCP_CAN CAN0(10);                               // Set CS to pin 10

void setup()

 if (CAN0.begin(MCP_ANY, CAN_33K3BPS, MCP_16MHZ) == CAN_OK)
   Serial.println("MCP2515 Initialized Successfully!");
 else {
   while (true) {
     Serial.println("Error Initializing MCP2515...");
 pinMode(CAN0_INT, INPUT);
 Serial.println("MCP2515 Library Receive Example...");

void loop()
 if (!digitalRead(CAN0_INT))                    
   CAN0.readMsgBuf(&rxId, &len, rxBuf);      // Read data: len = data length, buf = data byte(s)

   if ((rxId & 0x80000000) == 0x80000000)
     sprintf(msgString, "Extended ID: 0x%.8lX  DLC: %1d  Data:", (rxId & 0x1FFFFFFF), len);
     sprintf(msgString, "Standard ID: 0x%.3lX       DLC: %1d  Data:", rxId, len);


   if ((rxId & 0x40000000) == 0x40000000) {
     sprintf(msgString, " REMOTE REQUEST FRAME");
   } else {
     for (byte i = 0; i < len; i++) {
       sprintf(msgString, " 0x%.2X", rxBuf[i]);


 if(CAN0.checkError() == CAN_CTRLERROR){
   Serial.print("Error register value: ");
   byte tempErr = CAN0.getError() & MCP_EFLG_ERRORMASK; // We are only interested in errors, not warnings.
   Serial.println(tempErr, BIN);
   Serial.print("Transmit error counter register value: ");
   tempErr = CAN0.errorCountTX();
   Serial.println(tempErr, DEC);
   Serial.print("Receive error counter register value: ");
   tempErr = CAN0.errorCountRX();
   Serial.println(tempErr, DEC);
And i have a problem when run, MCP2515 Initialized Successfully, but allways return length = 0 with ID = 0x000.
and with error check, serial return :

Code: Select all

Error register value: 1000
Transmit error counter register value:
Receive error counter register value: 128.
=> please help me what's wrong?

I had tried with canhack library, but nothing happens.
Please guide me how to check MCP2515 module.

Re: Arduino CAN BUS monitoring tool

Posted: 2017 Aug 28 12:22
by linuxkidd
Hello tandm87,
The board you're using is 8mhz clock, but you're trying to initialize it as 16mhz clock. See my adjustments above to modify the MCP library to allow 8mhz clock usage.


Re: Arduino CAN BUS monitoring tool

Posted: 2017 Aug 30 10:57
by tandm87
Thank @linuxkidd, let me try, thank again.