Arduino – CAN BUS Communication

In this tutorial I am going to show you how to interface the MCP2515 CAN Bus Controller with an Arduino and how to communicate between two Arduinos via CAN BUS.

This tutorial can be a good kickstart for future development of an individual CAN writer or reader to use it in different applications (car CAN Bus sniffer, connection to an equipment control network, among others).

Parts Required

MCP2515 Can Controller + TJA1050 Can Transceiver

The MCP2515 CAN Bus Controller it’s an IC that supports CAN Protocol version 2.0 and can be used for communication at 1Mbps.

Module used in this project.
U1 – TJA1050
U2 – MCP2515

This particular module is based on the MCP2515 CAN Controller IC and the TJA1050 CAN Transceiver IC. The MCP2515 IC is a standalone CAN Controller and has integrated SPI Interface for communication with microcontrollers.

MCP2515 IC is the main controller that internally consists of three main subcomponents: The CAN Module (responsible for transmitting and receiving messages on the CAN Bus), the Control Logic (handles the setup and operation of the MCP2515 by interfacing all the blocks) and the SPI Block (responsible for the SPI Communication interface).

The TJA1050 IC acts as an interface between the MCP2515 CAN Controller IC and the Physical CAN Bus. Since it acts as an interface between MCP2515 CAN Controller and the physical CAN Bus, this IC is responsible for taking the data from the controller and relaying it on to the bus.

Circuit

Arduino PinCAN Board Pin
10CS
11SI
12SO
13SCK
Pinout Arduino <-> Can Board
CAN Board 1 PinCAN Board 2 Pin
CAN HCAN H
CAN LCAN L
Pinout Can Board 1 <-> Can Board 2
Schematic circuit.
Real project circuit.

One Arduino Uno and one Arduino Micro were used in this project, but you can use the version of the arduino that you have, as long as the connections for MISO, MOSI, CS and SCK are fulfilled.

Code

It is necessary to install a library for the MCP2515 Module. In this project we used this particular one. Here is a guide to install .zip libraries.

Transmitter Code

Receiver Code

Results

Here we are visualizing the data in decimal format, but if you want to see it in hexadecimal, change DEC to HEX in line 29 of the receiver code.

References

[1] https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf

[2] https://www.nxp.com/docs/en/data-sheet/TJA1050.pdf?

[3] https://www.electronicshub.org/arduino-mcp2515-can-bus-tutorial/

[4] https://circuitdigest.com/microcontroller-projects/arduino-can-tutorial-interfacing-mcp2515-can-bus-module-with-arduino

Leave a Reply

Your email address will not be published. Required fields are marked *