International Journal on Recent and Innovation Trends in Computing and Communication ISSN: 2321-8169
Volume: 2 Issue: 6 1568 – 1573
_______________________________________________________________________________________________
Implementation of CAN Bus Protocol
Ms. Ashwini S. Shinde Ms. Aarti S. Deshpande Mr. Pradnyant N Kalamkar Mr. Arjun R. Nichal
Departement of ENTC Departement of ENTC Departement of ENTC Departement of ENTC
AITRC Vita AITRC Vita AITRC Vita AITRC Vita
Vita, India Vita, India Vita, India Vita, India
ashushinde16@gmail.com aartideshpande11@gmail.com pnkalamkar4587@gmail.com arjunnichal@gmail.com
Abstract— Controller Area Network (CAN) is a vehicle bus standard protocol designed specifically for automotive application.
ECUs (Electronic control units) within vehicle can communicate with each other using CAN Bus standard protocol. It is high
speed, bandwidth efficient network. 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 over increased flexibility and expandability.
Keywords- Vehicle Automation, Controller Area Network (CAN), Electronic Control Unit (ECU)
__________________________________________________*****_________________________________________________
I. INTRODUCTION II. OVER VIEW OF CAN BUS PROTOCOL
Vehicle system is composed of automotive electrical CAN bus is a serial data communication protocol in-
architecture consists of a large number of electronic control vented by German BOSCH Corporation in the year 1986.
units (ECU) carrying out a variety of control functions. From CAN is a network protocol which is designed for the car in-
vehicle system we generally want greater safety, more comfort dustry. Since data communication in car often have many sen-
and less fuel consumption. A modern vehicle may have many sors transmitting small data packets, CAN supports data
electronic control units (ECUs) for various subsystems. Dif- frames with sizes only up to 8 bytes. Meanwhile, the 8 bytes
ferent such subsystems are airbags, antilock braking, engine will not take the bus for a long time, so it ensures real-time
control, audio system, windows, doors, mirror adjustment etc. communication. CAN protocol has a large amount of over-
Some of these subsystems form independent subsystems, but head, which is combined with a 15-bit CRC, makes CAN very
communication among others is essential. Traditional electron- secure and reliable. The CAN protocol standardizes the physi-
ic control system can improve a vehicle dynamics, economy cal and data link layers, which are the two lowest layers of the
and comfort. But some problems also have come up, such as open systems interconnection (OSI) communication model.
the body wiring complexity, space constraints and some relia- CAN protocol belong to the class of protocols denoted as car-
bility issues. In order to solve these problems, the vehicle net- rier sense multiple access /collision avoidance (CSMA/CA).
work technology has been created. The communication rate of CAN based network, depends on
In vehicle networking protocols must satisfy require- the physical distances between the nodes. If the distance is less
ments which include significant reduction of wiring harness, than 40m, the rate can be up to 1Mbps. CAN bus Protocol has
reducing body weight and costs, improving the efficiency of the following properties:
fault diagnosis, low latency time, configuration flexibility and
1. Prioritization of messages
enhancing the level of intelligent control. Sub systems (ECUs)
2. Guarantee of latency time
require the exchange of particular performance and position
3. Configuration flexibility
information within defined communication latency. Therefore
4. Multicast reception with time synchronization
the requirement for each ECU is to communicate via some
5. System wide data consistency
kind of network technology such as CAN (Controller Area
6. CAN protocol support Multi-master communication
Network) bus. At present, some vehicle buses have been al-
7. Error detection and signaling
ready put into use, such as CAN bus, LIN (Local Interconnect
8. Automatic retransmission of corrupted messages as soon as
Network) bus, Flexray bus etc.
the bus is idle again
. Before invention of CAN, D2B network is used in car
9. Distinction between temporary errors and permanent fail-
which uses ring topology which has disadvantages that it is not
ures of nodes and autonomous switching off of defective
reliable, if one node becomes faulty then whole system col-
nodes.
lapse. Before CAN, electronic control units are connected in
There are two message formats: Base frame format with 11
mesh topology. More wiring is required to connect the various
identifier bits and Extended frame format with 29 identifier
ECUs. By using CAN protocol ECUs are connected in bus
bits.
topology. It offers high speed, less wiring is needed, and it is
more reliable because we can connect or delete any node ac-
cording to our requirement.
Figure 1. CAN Data Frame
1568
IJRITCC | June 2014, Available @ http://www.ijritcc.org
_______________________________________________________________________________________
International Journal on Recent and Innovation Trends in Computing and Communication ISSN: 2321-8169
Volume: 2 Issue: 6 1568 – 1573
_______________________________________________________________________________________________
A. Hierarchical structure of CAN BUS 2. Acknowledge Error
Architecture of CAN protocol based on OSI reference In the Acknowledge Field of a message, the transmit-
model is as shown in figure 2. CAN protocol contain only ting node checks if the Acknowledge contains a dominant bit.
three layers, physical layer, data link layer and application This dominant bit would acknowledge that at least one node
layer. Application layer has different protocols such as SAE correctly received the message. If this bit is recessive, then no
J1939, CANopen, DeviceNet, etc. node received the message properly. An Acknowledge Error
has occurred.
3. Form Error
If any node detects a dominant bit in one of the fol-
lowing four segments of the message: End of Frame, Inter
frame Space, Acknowledge Delimiter or CRC Delimiter, the
CAN protocol defines this to be a form violation and a Form
Error is generated.
4. Bit Error
A Bit Error occurs if a transmitter sends a dominant
bit and detects a recessive bit, or if it sends a recessive bit and
detects a dominant bit when monitoring the actual bus level
and comparing it to the bit that it has just sent.
5. Stuff Error
CAN protocol use a Non-Return to-Zero (NRZ)
transmission method. This means that the bit level is placed on
the bus for the entire bit time. Bit stuffing is used to allow re-
ceiving nodes to synchronize. If, between the Start of Frame
Figure 2. Hierarchical structure of CAN BUS and the CRC Delimiter, six consecutive bits with the same
polarity are detected, then stuff Error occurs.
1. Physical Layer
The physical layer defines how the signals are actually trans- III. OVER VIEW OF SPI PROTOCOL
mitted. Tasks include: signal level, bit representation and MCP2515 is Stand-Alone CAN Controller with
transmission medium. Physical layer defines physical and SPI Interface. The MCP2515 interfaced with microcontroller
electrical characteristics of the network. Physical layer is same (LPC2148) via an industry standard Serial Peripheral Interface
for all the nodes on the same network. Physical layer is related (SPI). SPI is a full duplex serial interfaces. It can handle mul-
to bit encoding, decoding, bit timing and synchronization. tiple masters and slaves being connected to a given bus. Only
2. Data link layer a single master and a single slave can communicate on the
The data link layer is divided into two sub layers, logical link interface during a given data transfer. During a data transfer
control sub layer (LLC) and medium access sub layer (MAC). the master always sends 8 to 16 bits of data to the slave, and
Logical link control sub layer (LLC) accept the messages, the slave always sends a byte of data to the master. 4 pins
supports overload notification and recovery management. Me- SCK0, SSEL0, MISO0 and MOSI0 of LPC2148 are used for
dium access sub layer (MAC) performs message framing, arbi- SPI interface. SCK0 is input/output SPI clock signal used to
tration, acknowledgment, error detection and signaling. synchronize the transfer of data across the SPI interface.
3. Application Layer SSEL0 is input SPI slave select signal is an active low signal
Application Layer is specified by user. CANOPEN, Device- that indicates which slave is currently selected to participate in
Net, SAEJ1938 be the implementation of CAN application a data transfer. MISO0 is input/output Master In Slave Out
layer. signal. The MISO signal is a unidirectional signal used to
transfer serial data from the slave to the master. MOSI0 in-
B. CAN Message Frames
put/output Master Out Slave In signal. The MOSI signal is a
CAN has four frame types unidirectional signal used to transfer serial data from the mas-
1. Data frame: a frame containing node data for transmission ter to the slave. The SPI contains 5 registers[6].
2. Remote frame: a frame requesting the data 1. S0SPCR: SPI Control Register, this register controls the
3. Error frame: a frame transmitted by any node detecting an operation of the SPI.
error 2. S0SPSR: SPI Status Register, this register shows the status
4. Overload frame: a frame to inject a delay between data of the SPI.
and/or remote frame 3. S0SPDR: SPI Data Register, this bi-directional register pro-
C. CAN Errors vides transmit and receive data for the SPI.
4. S0SPCCR: SPI Clock Counter Register, this register con-
1. CRC Error
trols the frequency of a master SCK0.
A 15-bit Cyclic Redundancy Check (CRC) value is
5. S0SPINT: SPI Interrupt Flag, this register contains the inter-
calculated by the transmitting node and this 15-bit value is
rupt flag for the SPI interface.
transmitted in the CRC field. All nodes on the network receive
this message, calculate a CRC and verify that the CRC values
A. Master operation
match. If the values do not match, a CRC error occurs
The following sequence describes a data transfer with the SPI
block when it is set up to be the master,
1569
IJRITCC | June 2014, Available @ http://www.ijritcc.org
_______________________________________________________________________________________
International Journal on Recent and Innovation Trends in Computing and Communication ISSN: 2321-8169
Volume: 2 Issue: 6 1568 – 1573
_______________________________________________________________________________________________
1. Set the SPI clock counter register to the desired clock rate. nected TxD and RxD pins of the MCP2551 respectively.
2. Set the SPI control register to the desired settings. CANH and CANL pins of MCP2551 are connected to CAN
3. Write the data to transmit to the SPI data register. This write bus.
starts the SPI data transfer.
4. Wait for the SPIF bit in the SPI status register to be set to 1
the SPIF bit will be set after the last cycle of the SPI data
transfer.
5. Read the SPI status register.
6. Read the received data from the SPI data register (optional).
7. Go to step 3 if more data is required to transmit.
B. Slave operation
The following sequence describes how one should process
a data transfer with the SPI block when it is set up to be a
slave.
1. Set the SPI control register to the desired settings.
2. Write the data to transmit to the SPI data register (optional).
Note that this can only be done when a slave SPI transfer is
not in progress.
3. Wait for the SPIF bit in the SPI status register to be set to 1
the SPIF bit will be set after the last sampling clock edge of
the SPI data transfer.
4. Read the SPI status register.
5. Read the received data from the SPI data register (optional).
6. Go to step 2 if more data is required to transmit.
IV. HARDWARE DESIGN Figure 4. Detailed Block Diagram
The block diagram for CAN bus communication sys-
tem is as shown in figure 3. Different nodes are nothing but
ECUs of vehicle system, which are connected to each other
through, CAN bus. Monitor node monitors information on bus
and provide it to computer for further analysis. VB6 software
is used for collection of data, analysis as well as fault diagno-
sis of the system.
Figure 5: Block Diagram of node
V. SOFTWARE DESIGN
Figure 3. Block Diagram The software part of main program unit is divided
into: CAN initialization unit, message sending unit, message
The devices that are connected by a CAN network are receiving unit and interrupt service unit. We have designed
typically sensors, actuators, and other control devices. These three nodes, named as Dashboard node, Indicator node and
devices are not connected directly to the bus, but through a Bus monitor node. Dashboard node and Indicator node are
host processor and a CAN controller as shown in above figure communicating with each other while Bus monitor node moni-
IV. CAN node consist of host processor, CAN controller and tors messages available on CAN BUS and these messages are
CAN transceiver. LPC2148 ARM7 TDMI-S processor is used send to PC. Dashboard node and Indicator node operates in
as host processor. MCP2515 is Stand-Alone CAN Controller normal mode while Bus monitor node operates in listen only
with SPI Interface. MCP2551 is used as CAN transceiver. The mode. Block diagram of Dashboard node is as shown in figure
figure 5 shows hardware module of CAN controller and CAN 6. Brake switch is connected at P0.9 pin of LPC2148. AC Ok
transceiver. This module is connected to LPC2148 host pro- indicator LED is connected at P0.31, relay is connected at
cessor. TxCAN and RxCAN pins of the MCP2515 are con- p0.12 and LCD display indicates the status of AC.
1570
IJRITCC | June 2014, Available @ http://www.ijritcc.org
_______________________________________________________________________________________
International Journal on Recent and Innovation Trends in Computing and Communication ISSN: 2321-8169
Volume: 2 Issue: 6 1568 – 1573
_______________________________________________________________________________________________
ID distribution of Dashboard node is as shown in fol- A. CAN Controller Initialization
lowing figure 7. CAN controller initialization include initialization of transmit
and receive buffer of CAN controller MCP2515. When initia-
lizing the CAN registers in the MCP2515, the system imme-
diately clear the read and write buffer, Configures the operat-
ing mode, bit timing register, filter and mask register, and in-
terrupt enable register.
B. CAN Message Sending
After initialization, the MCP2515 is in normal communication
status and is ready to work. The CAN message sending adopts
Figure 6: Dashboard node inquiry mode or it sends message when remote request is re-
ceived. In inquiry mode, after specific time interval, LPC2148
creates packet and sends data to CAN Controller transmit buf-
fer for further transmission.
C. CAN Message Receiving
There are two ways for messages receiving: inquiry mode and
interrupt mode. In system design, interrupt mode is imple-
mented. In interrupt mode, if MCP2515 CAN controller rece-
ives valid message in receive buffer, it generates interrupt sig-
nal on INT pin. Message is read by LPC2148 by using SPI
Figure 7: Dashboard node ID commands of MCP2515.
Flow chart for Dashboard node and Indicator node is as
Block diagram of Indicator node is as shown in figure shown in figure 11 & 12
8. AC switch is connected to P0.9 pin of LPC2148. Brake Ok
indicator LED is connected at P0.31 pin of LPC2148, LCD
display indicates the status of Brake Switch. ID distribution of
Indicator node is as shown in following figure 9. Block dia-
gram of Bus monitor node is as shown in figure 10.
Figure 8: Indicator node
Figure 9: Indicator node ID
Figure 11: Flow chart for Dashboard node
Figure 10: Bus Monitor node
1571
IJRITCC | June 2014, Available @ http://www.ijritcc.org
_______________________________________________________________________________________
International Journal on Recent and Innovation Trends in Computing and Communication ISSN: 2321-8169
Volume: 2 Issue: 6 1568 – 1573
_______________________________________________________________________________________________
Figure 13: CAN Analyzer
Figure 12: Flow chart for Indicator node
VI. RESULTS
By using UART interface the CAN monitor achieves the
reception of CAN messages and time oriented buffering even
when dealing with very high bus loads and baud rates. CAN
monitor window allows the visualization of the BUS data at
the package level and its columns means the following,
1. Serial no. : Indicates number of the received message
2. Date and Time: Indicates the date and time at which data is Figure 14: CAN Bus output observed on the DSO
received
3. ID: Indicates the Identifier of the message
4. Std: Indicates that received message is standard or extended VII. CONCLUSION
5. Data: Indicates the data byte of the CAN package
6. Data Length: Indicates the length of the data byte of the The basics of CAN Bus protocol can be understood.
CAN package The software and hardware can be used to construct a fully
Different buttons are provided on CAN monitor window working CAN bus for vehicle automation, at various levels of
to allow user to interact with CAN bus system. "Connect" but- complexity. Basics of packet structure can be seen and unders-
ton checks the connection of PC with hardware. "Start" button tood. CAN Analyzer collects CAN messages and allows time
starts the collection of messages and buffering, it also saves oriented buffering of messages even when dealing with very
the messages in database. "Stop" button stops message recep- high bus loads and baud rates. It allows the visualization of the
tion. "Clear All" button clears all contents of database. "Exit" data. Designed CAN Bus system may be adapted for actual
button exits from CAN monitor window. ECU node design of vehicle system. We can adapt GUI design
The output of the CAN Bus is observed on the DSO. The to make CAN Analyzer more powerful, versatile tool for the
output wave-form can be observed at TxCAN or RxCAN pins development, testing and servicing of Controller Area Net-
of MCP2515 CAN controller with respect to ground terminal. work based systems.
The output waveform shows that bit stream in a CAN bus
message is coded according to the Non-Return-to-Zero (NRZ)
method.
1572
IJRITCC | June 2014, Available @ http://www.ijritcc.org
_______________________________________________________________________________________
International Journal on Recent and Innovation Trends in Computing and Communication ISSN: 2321-8169
Volume: 2 Issue: 6 1568 – 1573
_______________________________________________________________________________________________
VIII. REFERENCES
[1] Li Ran, Wu Junfeng, Wang Haiying, Li Gechen, “Design Method of
CAN BUS Network Communication Structure for Electric Vehicle”, Mr. P. N. Kalamkar received his B.E. de-
IFOST 2010 Proceedings IEEE. gree in Electronics from Dr. Babasaheb
[2] Yujia Wang, Hao Su, Mingjun Zhang, “CAN Bus Based Ambedkar Marthwada University, Aura-
Communication System Research for Modular Underwater Vehicle”, gabad in 2009 and received M.Tech in
2011 IEEE DOI 10.1109/ICICTA.2011.
Electronics from Walchand College of
[3] He Yu1, Guihe Qin1,2,3, Zhizhong Tian1, Jinnan Dong1,3, “ Network-
based In-Vehicle Body Bus Control System” , 2010 IEEE. engineering, Sangli in 2012. His area of
[4] Chin E. Lin, Hung-Ming Yen, “A PROTOTYPE DUAL CAN-BUS interest is Digital Image Processing and
AVIONICS SYSTEM FOR SMALL AIRCRAFT TRANSPORTATION VLSI system. He published 1 Interna-
SYSTEM”, 1-4244-0378-2/06/20.00 2006 IEEE.. tional journal papers.
[5] Chris Quigley,Richard McLaughlin, “ELECTRONIC SYSTEM
INTEGRATION FOR HYBRID AND ELECTRIC VEHICLES”
[6] UM10139, LPC214x User manual, Rev. 3, 4 October 2010 Prof.A.R.Nichal received his B.E. degree in
[7] LPC2141/42/44/46/48, Product data sheet, Rev. 03, 19 October 2007 Electronics and telecommunication from
[8] MikroDes MD2148 ARM7 kit Lab Manual. Shivaji University at Ashta in 2010 and
[9] MCP2515 Data sheet, 2005 Microchip Technology Inc. received M.Tech in Electronics from Wal-
[10] MCP2551 Data sheet, 2007 Microchip Technology Inc. chand College of engineering, Sangli in
[11] AN228, Application Note on “A CAN Physical Layer Discussion”, 2002 2012. His area of interest is Digital Image
Microchip Technology Inc.
Processing and embedded system. He pub-
lished 8 International journal papers, 1
Conference paper, 1 Ebook and He has one blog on Funda-
BIOGRAPHY mentals of Image Processing, Matlab Basics and Embedded
Ms. A. S. Shinde received her B.E. degree in System.
Electronics Engineering from Shivaji Uni- URL: www.imagelpcmatlab.blogspot.com
versity at PVPIT, Budhgaon in 2009 and
received M.Tech in Electronics Engineering
from Walchand College of Engineering,
Sangli in 2012. Her area of interest is em-
bedded system. She published 1 Interna-
tional journal paper and 1 Ebook.
Ms. A. S. Deshpande received her B.E. de-
gree in Electronics and telecommunication
from Pune University in 2009 and re-
ceived M.Tech in Electronics from Wal-
chand College of engineering, Sangli in
2012. Her area of interest is Digital Image
Processing and Communication Engineer-
ing. She published 1 International journal
papers
1573
IJRITCC | June 2014, Available @ http://www.ijritcc.org
_______________________________________________________________________________________