Professional Documents
Culture Documents
Signal Interfacing Using Can Bus: A Project Report
Signal Interfacing Using Can Bus: A Project Report
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)
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.
This is to certify that the above statement made by the candidate is correct to best of my knowledge.
Dept. of Electronics
& Communication Engineering
Birla Institute of Applied Sciences
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.
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
1 Introduction 1-2
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
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.
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.
3
CAN Node
An ECU that performs its tasks in a CAN network is referred to as a CAN
node.
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.
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
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.
11
Controller IC and the physical can bus. Thus increasing the speed of system.
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.
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>
MCP_CAN CAN(spiCSPin);
void setup()
{
Serial.begin(115200);
void loop()
{
Serial.println("In loop");
CAN.sendMsgBuf(0x43, 0, 8, stmp);
delay(1000);
}
Reciever Code
#include <SPI.h>
#include "mcp_can.h"
MCP_CAN CAN(spiCSPin);
void setup()
{
Serial.begin(115200);
pinMode(ledPin,OUTPUT);
void loop()
{
unsigned char len = 0;
unsigned char buf[8];
if(CAN_MSGAVAIL == CAN.checkReceive())
{
CAN.readMsgBuf(&len, buf);
Serial.println("-----------------------------");
Serial.print("Data from ID: 0x");
Serial.println(canId, HEX);
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.
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:
19
Conclusion
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