CAN-BUS Shield V1.2
CAN-BUS is a common industrial bus because of its long travel distance, medium communication speed and high reliability. It is commonly found on modern machine tools, such as an automotive diagnostic bus.
This CAN-BUS Shield adopts MCP2515 CAN Bus controller with SPI interface and MCP2551 CAN transceiver to give your Arduino/Seeeduino CAN-BUS capability. With an OBD-II converter cable added on and the OBD-II library imported, you are ready to build an onboard diagnostic device or data logger.
This document applies to the following version of products:
|Version||Released Date||How to Buy|
|CAN BUS Shield V1.0||Oct 14, 2012|
|CAN BUS Shield V1.1||Aug 10, 2013|
|CAN BUS Shield V1.2||Jan 5, 2015|
|CAN BUS Shield V2.0||Aug 01,2017|
What's new in CAN BUS Shield V1.2
- Pads on the backside of PCBA
- Change terminal resistor to 120 Ohm
If your project is space limited and also don't need other fuctions except CAN-BUS, here is a Grove CAN-BUS module which is Arduino compatible, more compact and cost effective, please click here to visit its page.
What if I want to connect this shield to my car
If you want to read data or control your car, there's an OBD>DB9 cable available for you, this cable make easier to connect to OBD-connector and DB9-connector. This cable will also work with anything that has a OBD-connector. Add a power switch makes such a satisfying click.
If you want a CAN Bus Analyzer to debug your CAN Bus, this USB-CAN Analyzer is recommended.
- Implements CAN V2.0B speed up to 1 Mb/s
- SPI Interface speed up to 10 MHz
- Standard (11 bit) and extended (29 bit) data and remote frames
- Two receive buffers with prioritized message storage
- Industrial standard DB-9 connector
- LED indicators
CAN BUS Shield Work well with Arduino UNO (ATmega328), Arduino Mega (ATmega1280/2560) as well as Arduino Leonardo (ATmega32U4).
- DB9 Interface - to connect to OBDII Interface via a DBG-OBD Cable.
- V_OBD - It gets power from OBDII Interface (from DB9)
- Led Indicator:
- PWR: power
- TX: blink when the data is sending
- RX: blink when there's data receiving
- INT: data interrupt
- Terminal - CAN_H and CAN_L
- Arduino UNO pin out
- Serial Grove connector
- I2C Grove connector
- ICSP pins
- IC - MCP2551, a high-speed CAN transceiver (datasheet)
- IC - MCP2515, stand-alone CAN controller with SPI interface (datasheet)
When you use more than two CAN Bus Shield in one net, you should take the impedance into consideration. You should either cut P1 in the PCB with a knife, or just remove R3 on the PCB.
The FREE pin is available for the other usages.
SPI_CS pin of V1.2 is connected to D9 by default. If you want to change to D10, please follow below instructions.
- Step1: Take a look at the backside of the PCBA, you will find a pad named CS.
- Step2: Cut the wire between pad9 and the middle pad.
- Step3:Solder the middle pad and pad 10.
Be careful with the box cutter, it's easy to hurt yourself or the PCBA.
The SPI pins (SCK, MISO, MOSI) are routed to the ICSP pins by default. But for some boards, the SPI pins are located at D11~D13. if this happens, you need make some change to the PCBA. Take a look at the backside of the PCBA, there're three pads, MOSI, MISO and SCK, they are connected to A by default. You can change them to B if needed.
For Arduino UNO, Arduino Mega, Arduino Leonardo and any others AVR based Arduino boards, it works well by default setting.
Be careful when you are going to change SPI pins, it's easy to hurt yourself or the PCBA.
Here's a simple example to show you how CAN-BUS Shield works. In this example we need 2 pieces of CAN-BUS Shields as well as Arduino or Seeeduino.
This example is built under Arduino IDE version 1.6.9.
STEP1: What do we need
|CAN-BUS Shield||CAN Bus communication||2||link|
STEP2: Hardware Connection
Insert each CAN-BUS Shield into Seeeduino V4.2, and connect the 2 CAN-BUS Shield together via 2 jumper wires. Shown as below images.
CAN_H to CAN_H, CAN_L to CAN_L
Please follow how to install an arduino library procedures to install CAN BUS shield library.
Click on below button to download the library.
Install the library to your Arduino IDE when it is downloaded.
One of the node (a node means Seeeduino + CAN_BUS Shield) acts as master, the other acts as slaver. The master will send data to slaver constantly.
Each node can act as master before the code being uploaded.
Open the send example (File > Examples > CAN_BUS_Shield-master > send) and upload to the master. Open the receive_check example (File > Examples > CAN_BUS_Shield-master > receive_check) and upload to the slaver.
STEP4: View Result
Open the Serial Monitor of Arduino IDE(slaver), you will get the data sent from the master.
1. Set the Baud rate¶
This function is used to initialize the baud rate of the CAN Bus system.
The available baud rates are listed as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
2. Set Receive Mask and Filter¶
There are 2 receive mask registers and 5 filter registers on the controller chip that guarantee you getting data from the target device. They are useful especially in a large network consisting of numerous nodes.
We provide two functions for you to utilize these mask and filter registers. They are:
- num represents which register to use. You can fill 0 or 1 for mask and 0 to 5 for filter.
- ext represents the status of the frame. 0 means it's a mask or filter for a standard frame. 1 means it's for a extended frame.
- ulData represents the content of the mask of filter.
3. Check Receive¶
The MCP2515 can operate in either a polled mode, where the software checks for a received frame, or using additional pins to signal that a frame has been received or transmit completed.
Use the following function to poll for received frames.
The function will return 1 if a frame arrives, and 0 if nothing arrives.
4. Get CAN ID¶
When some data arrive, you can use the following function to get the CAN ID of the "send" node.
5. Send Data¶
It is a function to send data onto the bus. In which:
- id represents where the data comes from.
- ext represents the status of the frame. '0' means standard frame. '1' means extended frame.
- len represents the length of this frame.
- data_buf is the content of this message.
For example, In the 'send' example, we have:
6. Receive Data¶
The following function is used to receive data on the 'receive' node:
In conditions that masks and filters have been set. This function can only get frames that meet the requirements of masks and filters.
- len represents the data length.
- buf is where you store the data.
Generate a New BaudRate¶
We had provided many frequently-used baud rates, as below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Yet you may still can't find the rate you want. Here we provide a software to help you to calculate the baud rate you need.
Click here to download the software, it's in Chinese, but never mind, it's easy to use.
This software supports Windows system only. If you can't open it, please feel free to contact firstname.lastname@example.org for support.
Open the software, what you need to do is to set the baud rate you want, and then do some simple setting, then click calculate.
Then you will get some data, cfg1, cfg2 and cfg3.
You need to add some code to the library.
Open mcp_can_dfs.h, you need to add below code at about line 272:
1 2 3
Then let's go to about line 390, add below code:
Open mcp_can.cpp, goto the function mcp2515_configRate(at about line 190), then add below code:
1 2 3 4 5
Then you can use the baud rate you need. And please give me a pull request at github when you use a new rate, so I can add it to the library to help other guys.
If you want to make some awesome projects with CAN-BUS shield, here are some projects for reference.
Volkswagen CAN BUS Gaming¶
Ever wanted to play a car/truck simulator with a real dashboard on your PC? Me too! I'm trying to control a VW Polo 6R dashboard via CAN Bus with an Arduino Uno and a Seeed CAN Bus Shield. Inspired by Silas Parker. Thanks Sepp and Is0-Mick for their great support!
Hack your vehicle CAN-BUS¶
Modern Vehicles all come equipped with a CAN-BUS Controller Area Network, Instead of having a million wires running back and forth from various devices in your car to the battery, its making use of a more clever system.
All electronic functions are connected to the TIPM, (Totally integrated Power Module), such as solenoids/relays to lock the doors or mini motors to wind the windows etc.
From each node (IE Switch pod that controls your windows or electric door locks) it broadcasts a message across the CAN. When the TIPM detects a valid message it will react accordingly like, lock the doors, switch on lights and so on.
Q1: I can't get data from other CAN device.
- Check if the connection is right
- Check if the baud rate setting is right
Q2: The serial monitor print Init Fail.
- Check if the CS pin setting is matched with the code. For CAN Bus Shield V1.1/1.2, CS pin is connected to D9, others are to D10.
Q3. Where can I find technical support if I have some other issues.
- You can post a question to Seeed Forum.