MCP2515 Module
MCP2515 Module
Table of Contents
Introduction
A Brief Note on MCP2515 CAN Bus Controller Module
Schematic of MCP2515 CAN Bus Module
Circuit Diagram for Interfacing MCP2515 with Arduino
o Components Required
o Circuit Design
Code
o Transmitter Code
o Receiver Code
Working
Applications
Introduction
Controlled Area Network of simple CAN is a bus standard that allows
a Microcontroller and its peripheral devices to communicate without
the need of a host device or a computer.
For example, the Engine Control Unit is a major control using in a car.
This unit is connected to many sensors and actuators like air flow,
pressure, temperature, valve control, motors for air control etc. The
communication between these modules and the control unit is through
CAN Bus.
In order to understand a little bit more about CAN Bus, CAN Controller
and other important aspects, the MCP2515 CAN Bus Controller
Module is very helpful.
Components Required
Arduino UNO x 2
MCP2515 x 2
USB Cable x 2
Connecting Wires
Circuit Design
As mentioned earlier, the CAN Controller IC facilitates SPI
Communication Protocol for interfacing with any Microcontroller.
Hence, connect the SPI Pin i.e. SCK, MOSI (SI), MISO (SO) and CS
of the MCP2515 Module to corresponding SPI Pins of Arduino (see
circuit diagram).
Make two such connections: one pair acts as a transmitter and the
other as a receiver. Now for the communication between this
transmitter and receiver, connect CANH and CANL pins of each
MCP2515 Module.
Code
Before going into the code, you need to download a library for the
MCP2515 Module. There are many libraries but I have
used this particular one.
Transmitter Code
#include <SPI.h>
#include <mcp_can.h>
int ledHIGH = 1;
int ledLOW = 0;
MCP_CAN CAN(spiCSPin);
void setup()
Serial.begin(115200);
delay(100);
void loop()
Serial.println("In loop");
CAN.sendMsgBuf(0x43, 0, 8, stmp);
delay(1000);
Receiver Code
#include <SPI.h>
#include "mcp_can.h"
boolean ledON = 1;
MCP_CAN CAN(spiCSPin);
void setup()
Serial.begin(115200);
pinMode(ledPin,OUTPUT);
delay(100);
void loop()
if(CAN_MSGAVAIL == CAN.checkReceive())
CAN.readMsgBuf(&len, buf);
Serial.println("-----------------------------");
Serial.println(canId, HEX);
Serial.print(buf[i]);
Serial.print("\t");
digitalWrite(ledPin, buf[i]);
ledON = 0;
delay(500);
}
digitalWrite(ledPin, buf[i]);
ledON = 1;
Serial.println();
Working
Working of this project is very simple as all the work is done by the
libraries (SPI and CAN). Since CAN is message-based
communication, you need to send a message anywhere between 0
and 8 bytes.
Additionally, the 0th and 4th bit i.e. 1 and 0 in the above sequence are
extracted separately by the receiver and turns ON and OFF the LED
connected to Pin 2 of Arduino.
Applications
As mentioned in the introduction, CAN is widely used in the field of
automobiles. Some of the applications include: