Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 31

SIGNAL INTERFACING USING

CAN BUS
A PROJECT REPORT
SUBMITTED IN PARTIAL FULFILLMENT OF THE
REQUIREMENTS FOR THE AWARD OF THE DEGREE
OF
BACHELOR OF TECHNOLOGY
(ELECTRONICS AND COMMUNICATION ENGINEERING)
TO
UTTARAKHAND TECHNICAL UNIVERSITY
DEHRADUN

Submitted By;
Rakshit Kandpal Shubham Chaudhary
(Roll No.: 160050102042) (Roll No.: 160050102053)

Under The Supervision Of

Mr. Anil Chaurasia


Assistant Professor

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


BIRLA INSTITUTE OF APPLIED SCIENCES, BHIMTAL NAINITAL-

1
263136, UTTARAKHAND, INDIA
(2016-2020)

2
DECLARATION CERTIFICATE

We hereby, certify that the work which has been presented in the project entitled “Signal

Interfacing Using CAN Bus” in partial fulfilment of the requirement for the award of the
Degree of Bachelor of Technology, submitted in the Department of Electronics and
Communication Engineering, Birla Institute of Applied Sciences, Bhimtal, is an authentic record
of our work under supervision of Mr. Anoop Raghuvanshi.
The results embodied in this project have not been submitted by us or anybody else to any other
University of Institute for the award of any Degree or Diploma.

Date: Rakshit Kandpal (160050102042)


Shubham Chaudhary(160050102053)

This is to certify that the above statement made by the candidate is correct to best of my knowledge.

Date: Mr. Anil Chaurasia


( Professor)

Dept. of Electronics
& Communication Engineering
Birla Institute of Applied Sciences

Forwarded and Recommended for Submission.

Dr. Hem Chandra Pandey


(Head of Department)
Dept. of Electronics & Communication Engineering
Birla Institute of Applied Sciences
Uttarakhand-263136

3
CERTIFICATE OF APPROVAL

The foregoing project entitled “Signal Interfacing Using CAN Bus”, is hereby approved as a
creditable study of project topic and has been presented in satisfactory manner to warrant
acceptance as prerequisite to the degree for which it has been submitted.
It is understood that by this approval the undersigned do not necessarily endorse any conclusion
drawn or opinion expressed therein, but approve the project for the purpose for which it is
submitted.

(External Examiner) (Project Guide)

(Head of the Department)

4
Acknowledgement

It gives me a great pleasure to express our deep sense of gratitude and indebtedness to my
Project mentor Mr. Anoop Raghuvanshi, Assistant Professor (BIAS,Bhimtal) for his valuable
support and encouraging mentality throughout my work. I am highly obliged to him for helping
me to gain the successful completion of my project.

I am highly grateful to the Honorable Head of Department, Prof. Dr. H.C Pandey (Department of
Electronics & Communication Engineering) and my Parents for their valuable guidance and
encouragement during the work. I have taken efforts for this report. However, it would not have
been possible without the kind support and help of many individuals who made my Seminar
report successful. I would also like to extend my sincere thanks to all of them. I would like to
take opportunity to sincerely thanks to all the concern individuals, family members, friends, who
made my Seminar successful. I also thank all those people who helped me in anyway what so
ever act some point in time.

5
Abstract

CAN (Controller Area Network) is a serial communication technology used especially for
reliable data exchange between electronic control units (ECUs) in the automobile.

Data exchange between the electronic control units was initially implemented conventionally, i.e.
a physical communication channel was allocated to every signal to be transmitted.

However, intensive wiring effort enabled just limited data exchange. The only solution that
seemed to offer a way out of this dilemma came from serial bit exchange of data via a single
communication channel (bus). This led to the need to conceptualize a serial communication
system tailored to the requirements of the automobile.

In this project, we will learn about the MCP2515 CAN Controller Module, how to interface the
MCP2515 CAN Bus Controller with Arduino and finally how to enable communication between
two Arduino board with the help of two MCP2515 CAN Controllers and the CAN Protocol.
Based on requirements of modern vehicle, in- vehicle Controller Area Network (CAN)
architecture has been implemented. In order to reduce point to point wiring harness in vehicle
automation, CAN is suggested as a means for data communication within the vehicle
environment. The benefits of CAN bus based network over traditional point to point schemes
will offer increased flexibility and expandability for future technology insertions. This paper
presents the development and implementation of a digital driving system for a semi-autonomous
vehicle to improve the driver- vehicle interface. It uses an ARDUINO based data acquisition
system that uses ADC to bring all control data from analog to digital format and visualize
through LCD. The communication module used in this project is embedded networking by CAN
which has efficient data transfer.

6
TABLE OF CONTENTS

Serial No. Chapter Page No.

1 Introduction 1-2

2 About CAN Bus 3-4

3 CAN Framing 5-8

CRC And
4 Acknowledgment 9

Brief Note On
5 MCP2515 CAN 10
Bus

Schematic of
6 11
MCP2515 CAN

Bus

Circuit Design Of
7 MCP2515 With 12
Arduino

8 Coding 13-15

9 Components 16
Required

7
17
10 Working &
Application

11 Conclusion 18

12 Future Scope 19

13 References 20

8
TABLE OF FIGURES

Serial No. Picture Page No.

1 CAN Network 3

2 CAN Framing 6

3 CAN 7
(Data Framing)

4 Message Frame 8
Structure

5 MCP2515 CAN 10
Controller

6 Circuit Design Of 11
MCP2515

Circuit Design Of
7 MCP2515 With 12
Arduino

9
1. 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.Developed
by Robert Bosch GmbH, CAN is protocol is main used in automobiles for communication
between a control unit and its components.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.

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.

The more recent history of the automobile is characterized by intensive electronification. The
driving force for this can be traced primarily to continual growth of customer wishes for a
modern automobile. Another factor is globalization, which increases competitive and cost
pressures that result in continual innovative pressure.

Data exchange between the electronic control units was initially implemented conventionally, i.e.
a physical communication channel was allocated to every signal to be transmitted.

However, intensive wiring effort enabled just limited data exchange. The only solution that
seemed to offer a way out of this dilemma came from serial bit exchange of data via a single
communication channel (bus). This led to the need to conceptualize a serial communication
system tailored to the requirements of the automobile.

1
At the beginning of the 1980s, Bosch began to develop such a serial communication system. It
was given the name CAN (Controller Area Network). Even today, CAN is still performing useful
services in motor vehicles in networking ECUs in the powertrain, chassis and convenience areas.
Above all, CAN is characterized by very reliable data
transmission that satisfies the real-time requirements of target usage areas.

Nowadays accidents occur due to mistakes done by driver. An intelligent system needs to be
developed to overcome these mistakes. So this system is proposed where mistakes done by driver
are eliminated. Most of the intelligent car systems have monitoring system only. Antilock brakes,
speed sensors and other automatic systems are present in sports cars and other luxury cars only.
But these cars are not affordable to everyone. So, a system needs to be developed which can be
implemented in every car.

A collision avoidance system is a system of sensors that is placed within a car to warn its driver
of any dangers that may lie ahead on the road. Some of the dangers that these sensors can pick up
on include how close the car is to other cars surrounding it, how much its speed needs to be
reduced while going around a curve, and how close the car is to going off the road.

2
2.ABOUT CAN BUS

CAN technology has been standardized since 1994 and is described by four
ISO documents. ISO 11898-1 describes the CAN protocol. In relation to the
reference model of data communication, the CAN protocol just covers the Data
Link Layer (MAC — Medium Access Control, LLC — Logical Link Control)
and the Physical Layer (PLS — Physical Signalling).

CAN Communication

CAN Network
A CAN network consists of a number of CAN nodes which are linked via a
physical transmission medium (CAN bus) In practice, the CAN network is
usually based on aline topology with a linear bus to which a number of
electronic control units are each connected via a CAN interface. The passive
star topology may be used as an alternative.

The maximum data rate is 1 Mbit/s. A maximum network extension of about 40


meters is allowed. At the ends of the CAN network, bus termination resistors
contribute to preventing transient phenomena (reflections). ISO 11898 specifies
the maximum number of CAN nodes as 32.

3
CAN Node
An ECU that performs its tasks in a CAN network is referred to as a CAN
node.

In the beginnings of ECU networking, an adequate implementation of the CAN


interface involved a simple CAN driver — which provided an essentially
simple hardware- independent interface for the application — together with a
CAN controller and a CAN transceiver. Today, it is no longer possible to do
without an operating system, network management functions or diagnostics.
The software complexity, which has meanwhile become enormous, makes it
necessary to standardize the ECU infrastructure.

CAN Controller
An electronic control unit (ECU) that wants to participate in CAN
communication requires a CAN interface. This comprises a CAN controller and
a CAN transceiver. The CAN
controller fulfills communication functions prescribed by the CAN protocol,
which relieves the host considerably. CAN Transceiver
Previously, the CAN controller was frequently connected to the communication
media (CAN bus) by a discrete circuit. Today, however, CAN transceivers
handle the bus connection. A CAN transceiver always has two bus pins: one for
the CAN high line (CANH) and one for the CAN low line (CANL). This is
4
because physical signal transmission in a CAN network is symmetrical to
achieve electromagnetic compatibility, and the physical transmission medium
in a CAN network consists of two lines.

CAN Bus L
Physical signal transmission in a CAN network is based on transmission of
differential voltages (differential signal transmission). This effectively
eliminates the negative effects of interference voltages induced by motors,
ignition systems and switch contacts.
Consequently, the transmission medium (CAN bus) consists of two lines:CAN
high line (CANH) and CAN low line (CANL).
Twisting of the two lines reduces the magnetic field considerably. Therefore, in
practice twisted pair conductors are generally used as the physical transmission
medium.

CAN Bus Logic


A basic prerequisite for smooth communication in a CAN network —
especially for bus access, fault indication and acknowledgement — is clear
distinctions between dominant and recessive bus levels. The dominant bus level
corresponds to logical “0”. The recessive bus level corresponds to logical “1”.

CAN Communication Principle


CAN network is based on a combination of multi-master architecture and line
topology: essentially each CAN node is authorized to place CAN messages on
the bus in a CAN network. The transmission of CAN messages does not follow
any predetermined time sequence, rather it is event-driven.

A method of receiver-selective addressing is used in a CAN network to prevent


dependencies between bus nodes and thereby increase configuration flexibility:
Every CAN message is available for every CAN node to receive
(broadcasting). A prerequisite is that it must be possible to recognize each CAN
message by a message identifier (ID) and node- specific filtering. Although this
increases overhead, it allows integration of additional CAN nodes without
requiring modification of the CAN network.

5
Physical signal transmission in a CAN network is based on transmission of
differential voltages (differential signal transmission). This effectively
eliminates the negative effects of interference voltages induced by motors,
ignition systems and switch contacts. In the beginnings of ECU networking, an
adequate implementation of the CAN interface involved a simple CAN driver
— which provided an essentially simple hardware- independent interface for
the application — together with a CAN controller and a CAN transceiver.
Today, it is no longer possible to do without an operating system, network
management functions or diagnostics. The software complexity, which has
meanwhile become enormous, makes it necessary to standardize the ECU
infrastructure.

CAN Framing

Frame Types

For transmitting user data, ISO 11898-1 prescribes the so-called data frame.

6
The error frame is available to indicate errors detected during communication.
An ongoing erroneous data transmission is terminated and an error frame is
issued. The layout of an error frame differs significantly from the structure of
the terminated erroneous data or remote frame. It consists of just two parts: The
error flag and the error delimiter.

Data Frame
Data frames assume a predominant role in a CAN network: They serve to
transmit user data. A data frame is made up of many different components.
Each individual component carries out an important task during transmission.
Tasks to be performed are: Initiate and maintain synchronization between
communication partners, establish the communication relationships defined in
the communication matrix and transmit and protect the user data.

Transmission of a data frame begins with the start bit (Start of Frame — SOF).
It is transmitted by the sender as a dominant level which produces a signal edge
7
from the previous recessive (bus idle) level which is used to synchronize the
entire network. In order

for the receivers not to lose synchronism to the sender during transmission of
the frame, they compare all recessive-to-dominant signal edges with their preset
bit timing. In case of deviation, receivers re-synchronize by the amount of the
relevant phase error (re- synchronization).

Following the SOF is the identifier (ID). This sets the priority of the data frame,
and together with the acceptance filtering it provides for sender-receiver
relations in the CAN network that are defined in the communication matrix.
Next comes the RTR bit (Remote Transmission Request). It is used by the
sender to inform receivers of the frame type (data frame or remote frame). A
dominant RTR bit indicates a data frame.

The IDE bit (Identifier Extension bit) which follows serves to distinguish
between standard format and extended format. In standard format the identifier
has 11 bits, and in extended format 29 bits. The figure “Data Frame in Standard
and Extended Format” is available to study the two formats.
The DLC (Data Length Code) communicates the number of payload bytes to
the receivers. The payload bytes are transported in the data field. A maximum
of eight bytes can be transported in one data frame. The payload is protected by
a checksum using a cyclic redundancy check (CRC) which is ended by a

delimiter bit. Based on the results of the CRC, the receivers acknowledge
positively or negatively in the ACK slot (acknowledgement) which also is
followed by a delimiter bit. After this the transmission of a data frame is
8
terminated by seven recessive bits (End Of Frame —EOF).

Remote Frame

Besides the data frame used to transport data, there is the remote frame — a
frame
type used to request data, i.e. data frames, from any CAN node. Nonetheless,
these frames are hardly ever used in automotive applications, since data
transmission is not based on requesting, rather it is primarily based on the self-
initiative of information producers. Remote frames may be transmitted in either
standard or extended format.

Addressing

Communication in the CAN network is based on content-related addressing. It


is not the CAN nodes that have identifiers, but rather the data and remote
frames are identified (identifier — ID). So, all CAN messages can be received
by every CAN node (broadcasting). Each receiver is independently responsible
for selecting CAN messages. Such receiver-selective addressing is very
flexible, but it requires that each receiver filters the received CAN messages
(acceptance filtering).

CRC and Acknowledgement


One of the greatest challenges of serial communication in the automotive
environment is to guarantee an extremely high level of reliability in
9
transmission. The CRC method that is used (CRC: Cyclic Redundancy Check)
represents one of the most powerful error detection methods.
In the CRC method, a CRC sequence is computed based on the bits to be
transmitted (from SOF up to and including the data field) and a generator
polynomial G(x) defined by ISO 11898-1. The CRC sequence is appended to
the bits to be transmitted. The overall polynomial is a multiple of the bits to be
transmitted. The receiver of the overall polynomial can then detect — with very
high reliability — whether a transmission error occurred (exception: CRC
sequence itself was corrupted by a disturbance), i.e. if division by the generator
polynomial yields a remainder.

Bit Stuffing
A basic prerequisite for correct data transmission is synchronized
communication partners. The dominant-to-recessive signal edge of the start bit
serves to produce synchronism (Start Of Frame — SOF) of a CAN message.
Afterwards, are synchronization mechanism is used to maintain synchronism
up to the end of the message transmission.

10
A Brief Note on MCP2515 CAN Bus Controller Module

The MCP2515 CAN Bus Controller is a simple Module that supports CAN
Protocol version 2.0B and can be used for communication at 1Mbps. In order to
setup a complete communication system, you will need two CAN Bus Module.

This particular module is based on MCP2515 CAN Controller IC and TJA1050


CAN Transceiver IC. The MCP2515 IC is a standalone CAN Controller and
has integrated SPI Interface for communication with microcontrollers. Coming
to the TJA1050 IC, it acts as an interface between the MCP2515 CAN

11
Controller IC and the physical can bus. Thus increasing the speed of system.

Schematic of MCP2515 CAN Bus Module

Before seeing the schematic of the module, we need to understand a couple of


things about both the ICs i.e. MCP2515 and TJA1050.

MCP2515 IC is the main controller that internally consists of three main


subcomponents: The CAN Module, the Control Logic and the SPI Block.

CAN Module is responsible for transmitting and receiving messages on the


CAN Bus. Control Logic handles the setup and operation of the MCP2515 by
interfacing all the blocks. The SPI Block is responsible for the SPI
Communication interface.

12
Coming to the TJA1050 IC, 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.

The following image shows the schematic of the MCP2515 CAN Module and it
shows how MCP2515 IC and TJA1050 IC are connected on the Module.

Circuit Design Of MCP2515 with Arduino

The following image shows the circuit diagram of interfacing MCP2515 CAN
Module with Arduino and possible communication between two Arduino over
CAN Protocol.

13
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 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
MCP2515Module.  

14
Coding
Since the communication involves a Transmitter Module and a Receiver
Module, the code is also divided into Transmitter Code and Receiver Code.

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

const int spiCSPin = 10;


int ledHIGH = 1;
int ledLOW = 0;

MCP_CAN CAN(spiCSPin);

void setup()
{
Serial.begin(115200);

while (CAN_OK != CAN.begin(CAN_500KBPS))


{
Serial.println("CAN BUS init Failed");
delay(100);
}
Serial.println("CAN BUS Shield Init OK!");
}

unsigned char stmp[8] = {ledHIGH, 1, 2, 3, ledLOW, 5, 6, 7};

void loop()
{
Serial.println("In loop");
CAN.sendMsgBuf(0x43, 0, 8, stmp);
delay(1000);
}

Reciever Code

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

const int spiCSPin = 10;


15
const int ledPin = 2;
boolean ledON = 1;

MCP_CAN CAN(spiCSPin);

void setup()
{
Serial.begin(115200);
pinMode(ledPin,OUTPUT);

while (CAN_OK != CAN.begin(CAN_500KBPS))


{
Serial.println("CAN BUS Init Failed");
delay(100);
}
Serial.println("CAN BUS Init OK!");
}

void loop()
{
unsigned char len = 0;
unsigned char buf[8];

if(CAN_MSGAVAIL == CAN.checkReceive())
{
CAN.readMsgBuf(&len, buf);

unsigned long canId = CAN.getCanId();

Serial.println("-----------------------------");
Serial.print("Data from ID: 0x");
Serial.println(canId, HEX);

for(int i = 0; i<len; i++)


{
Serial.print(buf[i]);
Serial.print("\t");
if(ledON && i==0)
{

digitalWrite(ledPin, buf[i]);
ledON = 0;
16
delay(500);
}
else if((!(ledON)) && i==4)
{

digitalWrite(ledPin, buf[i]);
ledON = 1;
}
}
Serial.println();
}
}

17
Components Required

Arduino UNO x 2

MCP2515 x 2

USB Cable x 2

Connecting Wires

Battery

7 Segment Display

Jumping wires

Bread Board

Wires

LED(indicator)

18
Working And Application

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.

In this project, the transmitter is sending a message as 1 1 2 3 0 5 6 7. This message is


transmitted over CAN Bus and the receiver receives this message and is displayed on its serial
monitor.

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.

Application
As mentioned in the introduction, CAN is widely used in the field of automobiles. Some of the
applications include:

 Electronic Gear Shift System


 Main Interface in Automation (like industrial)
 Medical Equipment
 Robotics
 Auto Start/Stop of Car Engine

19
Conclusion

This thesis documented a design of MCP2515-CAN module which forms a communication


bridge between the MCP2515 and CAN protocols. The module provides a protocol conversion
with a plug and play feature where modification of neither the hardware nor the software is
needed. CAN is a reliable, robust and real time serial communication protocol which reduces
wiring harness, weight and complexity. The protocol creates a master to master communication
bus and every message transmitted on the bus is received by all the nodes connected to the bus.
The message filtering technique decides whether the received data is relevant to the node or not.
The error detection and fault confinement techniques provided by the protocol are the added
features which keep the bus working without any errors and virtually detach the faulty nodes
which transmit corrupt messages on the bus.
The rate at which the base station communicates with the PC should be equal to or lesser than the
sum of rates at which the sensors communicate over MCP2515 to avoid the overflow of the data.

20
Future Scope

As the Internet of Things continues to grow and encompass more and more complex systems,
standardizing the way each component communicates with the next will be vital in ensuring
compatibility, expandability and installation longevity. Here at Logic Supply we’re working with
clients to implement CAN bus communication in a wide range of custom embedded systems and
we see a bright future for the technology, particularly in manufacturing environments and in
modern building automation installation. All electric cars are currently based in this technology
and dependence on this technology will only increase with time.

21
14. References

1. Li Ran, Wu Junfeng, Wang Haiying, Li Gechen. “Design Method of CAN BUS Network
Communication Structure for Electric Vehicle”, IFOST 2010 Proceedings IEEE.
2. Yujia Wang, Hao Su, Mingjun Zhang., “CAN-Bus-Based Communication System Research for
Modular underwater Vehicle”, 2011 IEEE DOI 10.1109/ICICTA.2011.
3. Chin E. Lin, S. F. Tai, H. T. Lin, T. P. Chen, P. K. Chang, C. C. Kao “Prototype Of A Small
Aircraft Avionics Using Hybrid Data Bus Technology” 2005 IEEE.
4. Chin E. Lin, Hung-Ming Yen, “A Prototype Dual Can-Bus Avionics System For Small Aircraft
Transportation System” 2006 IEEE.
5. Claesson, C. Ekelin, N. Suri, “The event-triggered and time- triggered medium-access methods”,
6th IEEE International Symposium on Object-Oriented Real-Time Distributed computing, May
14-16, 2003, pp. 131-134.
6. Chris Quigley, Richard McLaughlin, “Electronic System Inte- Gration For Hybrid And Electric
Vehicles”.
7. Chin E. Lin, H. M. Yen, “Reliability And Stability Survey On Can- Based Avionics Network For
Small Aircraft” -7803-9307- 4/05/2005 IEEE.

22

You might also like