You are on page 1of 3

Technically Speaking AUTOMOTIVE ELECTRICAL & AIR CONDITIONING NEWS

www.aaen.com.au

CAN data polarity, as they do in the example, then in the diagram below. The way this method
This is the there is no problem. works is that after five consecutive bits
third in a of the same polarity, a bit of the opposite
But then ECU2 attempts to transmit a
series of polarity is inserted. This means that
recessive bit, while the other two transmit
articles by resynchronisation can occur at least every
a dominant bit. Since dominant bits win out
Jason Turner six bits, which means the time is not long
as we discussed earlier, we can see that
and Clinton enough for the nodes to go out of sync.
what appears on the bus is a dominant bit.
Smith from
ECU2 notices that what it transmitted does To demonstrate, after five recessive bits, the
Redarc Technologies. They are writing
not match what it is reading back, telling transmitting node adds in a dominant bit.
about the latest in CAN and developments
it that another node must be transmitting
in this rapidly changing field. Then, when a device receives the message,
as well, so it switches to listening only and
it sees that the sixth bit is a bit stuffing bit
stops transmitting.
In the last article we discussed some (because it occurs after five consecutive bits
common types of CAN, or more correctly, Next ECU3 attempts to transmit a recessive of the opposite polarity) so it discards this
common ‘CAN physical layer standards’. In bit while ECU1 transmits a dominant bit. bit to get back to the original message.
this, the third article we will be considering Again, the dominant bit wins and ECU3
the data side of CAN. stops transmitting. Stuff bit of opposite polarity added after
five consecutive bits of same polarity

First up we have arbitration; that is, what Now ECU1 is the only device transmitting on
Stuff
does a CAN bus do when two or more the bus so it continues as it was, completely bit

devices attempt to transmit at the same oblivious that any other nodes were What is observed on CAN bus
time? In most types of networks, if multiple attempting to transmit, and no collision
devices transmit a message at the same occurred so no message is lost. When Stuff bit automatically removed
time then what is called a ‘collision’ occurs transmission is complete, ECU2 and ECU3 by receiving node’s CAN logic

and the two messages are jumbled together. will attempt to transmit their messages
The devices then notice the message is again.
wrong and so they discard it and wait for What is interpreted by CAN controller
Since dominant bits win, this means that
a randomly generated time before trying to
messages with more dominant bits at
transmit again. Since this time is random,
the start will win arbitration more often, Next we consider the data-link layer proper.
one of the devices will begin retransmission
allowing for priority order to be established. That is, how do we turn ones and zeros into
first and so the other will have to wait,
meaningful data? To do this messages are
with no regard given to the importance of In order for this arbitration method to work,
carried in ‘packets’ or rather ‘frames’. CAN
the messages. This is called ‘destructive’ the messages must be in sync. However,
defines four different types of frames.
arbitration because the original message is since CAN is asynchronous (meaning there
destroyed when the collision occurs. is no separate clock signal to keep the nodes First off we have the data frame. For most
in sync) each node must synchronise its purposes this is the only type of frame that
CAN has a better way of arbitrating known
clock at the start of a message and then on people really care about, as this is the only
as non-destructive bit-wise arbitration as
every falling edge resynchronise to ensure type of frame that contains data that is
shown in the diagram below. This is how
that it counts the number of bits correctly. meaningful to the end user.
it works. Assume there are three nodes
attempting to transmit all at the same time. The problem is, if there is a long stream Next up is the remote frame. This essentially
If all of them transmit bits of the same of bits of the same type, then eventually contains no data but is used to request another
the nodes will go node to transmit a desired data frame. Then
out of sync. For we have the error frame. This is transmitted
example, if the bit automatically by any node that sees an error
This ECU is now the only
one transmitting and is rate is 250kbps to let the transmitting node know that it needs
ECU 1 completely unaware that
any other ECUs were
(bit time of 4μs), to retransmit that message.
ever transmitting at the and there is
same time Lastly we have the overload frame. This
76μs of recessive
is used to delay transmission; when one
bits measured
node is too busy processing a message and
between two
Recessive bit wants more time to complete its processing,
ECU 2 transmitted Node switches to listen
dominant bits,
but dominant only for the rest of this it can send out up to two of these frames
bit observed transmission then how many
which prevents new messages being sent
recessive bits is
out. In reality this frame is rarely – if ever
this? One node
– seen anymore as CAN controllers these
may count 20
Recessive bit
Node switches to listen days are well and truly fast enough to fully
ECU 3 transmitted and another only
but dominant
only for the rest of this
process messages before receiving the next
bit observed
transmission 19 because the
one. However, 20 years ago when CAN was
latter ones clock
created, controllers were not as fast as they
is slightly slower
are today, so this type of frame needed to
Recessive
than the former.
BUS be included in the standard. I am told that
LEVEL To prevent this, the only controller to use this message was
Dominant
Bus level is
dominant
Bus level is
dominant CAN uses a Intel’s 82526 which was created in 1987 and
method called bit is now obsolete, so it is unlikely if you will
stuffing as shown ever see this type of frame.

AUGUST/SEPTEMBER 2014
Technically Speaking AUTOMOTIVE ELECTRICAL & AIR CONDITIONING NEWS
www.aaen.com.au

The data frame IDE/r1 r0 4 bit DLC


1 bit 12 or 32 bit 6 bit 0 to 64 bit (0 to 8 bytes) 16 bit 2 bit 7 bit
The control field comes next, consisting
Arbitration Control Data field of two reserved bits both set as dominant,
SOF CRC ACK EOF
field field (message) and a four-bit data length code. This DLC is
simply a number that indicates how many
bytes long the message is, from zero to eight
We’ll look at the standard format first. The bytes.
Data frame standard format uses an 11-bit message ID
You’ll notice that the first reserve bit is
The CAN data frame, as shown in the and a single dominant bit called the Remote
also labelled IDE. By comparing the two
diagram above, is made up of seven fields: Transfer Request bit. With CAN, instead of
data-frame types we can see that this is
nodes having identifiers and anonymous
1. The first is the start of frame bit, and as because this bit in a standard data frame
messages sent to particular addresses
its name implies, is only a single bit used lines up with where the IDE bit appears
(like other networks do), it is the other
to signify the start of the frame. in an extended data frame. Because this
way around: with every message having a
bit in the control field is dominant and
2. Next is the arbitration field which unique identifier and that message being
the IDE bit in an extended data frame is
contains a message identifier. sent to every node. Each node then checks
recessive, this allows the differentiation
if that message ID is one of the ones it cares
3. Then the control field which has between the two types of data frames.
about and if so, processes it; otherwise it
information about the length of the
simply ignores it. Everything up until this point has been
message that appears in the next field.
preparing the nodes for the actual data
The CAN standard doesn’t define what
4. The data field. This field contains the to arrive. The data field is the field that
each message is, it simply defines that each
message itself. contains all the data for the message.
message must have a unique ID. So why is
Once again, the CAN standard does not
5. Part of the CAN error-detection this field called the arbitration field? The
define what this data means, how it is
mechanism is the CRC code transmitted reason for this was partially answered
formatted, etc. All the standard defines
in the CRC field. earlier when I discussed how arbitration
is that this field contains zero to eight
occurs. Since arbitration is bit-wise, with
6. As well as the acknowledge field used bytes of data.
dominant bits winning out over recessive
to ensure other devices are actually
bits, and all messages having unique IDs, it The number of bytes in a message is
receiving the messages transmitted.
means that the arbitration will be decided defined on a per message basis, and is
7. And, lastly, the end of frame field to during the transmission of this field (with specified by the DLC. This means that on
signify the end of the frame. one or two exceptions). It also means that any particular bus you may have some
messages that have a lower ID will win messages that only contain one byte of
The SOF bit is simply one single dominant
arbitration more often, so messages can data, and others that contain seven or
bit that is transmitted to indicate the start
be prioritised such that the most important eight bytes of data.
of a frame. All the nodes on the bus use
messages have the lowest IDs.
this bit to synchronise their internal clocks. Once the data has been sent it needs
Simply put, this bit can be transmitted If we look at the extended format we can to be checked to ensure that there are
whenever the bus is not already in use by see that the first part is set up to be almost no errors; this is where the CRC field
another node. identical to the standard format, except that comes in, as shown in the diagram below.
the RTR bit is replaced by a SRR bit. As each node receives a data frame it
The next field is an interesting one. As you
performs a CRC calculation as it goes
can see, the arbitration field can either This bit must be recessive and essentially
so that by the time it gets here it has
be 12 bits or 32 bits long. This is because does nothing other than ensure that standard
calculated a CRC value based on what it
of the difference between the formats in and extended messages are compatible on
has received.
CAN standard 2.0A (Standard CAN) and the same bus. What it does mean though is
2.0B (Extended CAN), where the former that a standard message that has the same
describes an 11 bit message identifier, and ID as the first part of an extended message
CRC del

15 bit CRC sequence (x15+x14+x10+x8+x7+x4+x3+1)


the latter a 29 bit identifier. CAN has been will always win arbitration.
designed so that both formats can be used
The next bit is the IDE bit. This bit must be
on the same bus without causing issues.
recessive to indicate that this is an extended Before sending, the transmitter has already
format message. You’ll see in a minute how calculated a CRC on the data and it transmits
the corresponding bit in a standard message that value in the CRC field. All the receiving
Standard format
is always dominant. nodes compare the CRC value against what
they have calculated, and any node that
After this bit we have the second part of
RTR

11 bit identifier
does not get a match immediately transmits
the identifier, a further 18 bits that when
an error frame to stop the transmitting node
Extended format combined with the first 11 bits gives the
from completing the transmission, and alert
entire 29-bit message ID.
all other nodes to discard that frame. The
IDE

Lastly, we have the RTR bit for the extended original transmitting node will then attempt
SRR

RTR

11 bit identifier (part A) 18 bit identifier (part B)

format, transmitted as a dominant bit, just to retransmit the message at the next
as it was in the standard data frame. available opportunity.

AUGUST/SEPTEMBER 2014
Technically Speaking AUTOMOTIVE ELECTRICAL & AIR CONDITIONING NEWS
www.aaen.com.au

The acknowledge field is used to determine • And the EOF field. make it obvious that this is an error frame
whether other nodes are actually receiving Besides the missing-data field, the other and not simply data on the bus.
the message being sent. To do this, the difference appears in the arbitration field. In
By transmitting the error frame over the top
transmitting node transmits a recessive bit a remote frame, the RTR bit is transmitted
of a message that is being transmitted, it
as the first bit of this field, known as the as recessive so that receiving nodes can
tells the transmitting node that the message
ACK slot. All other nodes that successfully distinguish between a data frame and a
needs to be retransmitted, and it tells the
receive the message transmit a dominant remote frame.
receiving nodes to discard the message.
bit at the same time to acknowledge they
A by-product of this is that because a data
have correctly received the message. This is where things get complicated.
frame is identical to a remote frame up until
This way, when the transmitting node reads this point, and the data frame transmits a There are three types of error states that a
back this bit and sees it is dominant, it dominant bit here, a data frame with the node can reside in. These are:
knows the message has been received by same ID as a remote frame transmitted at
• Error Active – the most common state
at least one other node; however, if it sees the same time will win arbitration. This is
where everything operates as normal.
a recessive bit then it knows that no nodes desired behaviour as the purpose of the
• Error Passive – where a certain number
have received the message and it will need remote frame is to request that very data
of errors have been detected, so the
to send it again. The second bit in the ACK frame anyway.
node is restricted from interrupting the
field is also transmitted as recessive and
bus with any more error flags (in case it
simply exists as a spacer that allows for the Error frame is the node causing the errors).
transmission delay of other nodes sending
The last type of frame we will look at is • Bus Off – this is where so many errors
the ACK bit. If this bit did not exist and the
one I have already mentioned a few times, have been detected that the node
transmission delay caused one of the ACKs
the error frame. An error frame does not essentially disconnects itself from the
sent by a receiving node to creep into the
follow the other arbitration rules of a CAN bus. The only way for it to join the bus
next bit time, then the transmitting node
bus, rather the error frame is transmitted again is to perform a software reset
would see a dominant bit at the start of the
immediately by any node that detects an and wait for 128 occurrences of 11
EOF (end of frame) field and would throw
error to intentionally disrupt whatever is consecutive recessive bits.
an error, failing transmission.
being transmitted at the time. There are two types of error counters, these
The very last field in a data frame is the are the receive error counter (REC) and
There are many different types of errors
aforementioned EOF field, which is simply transmit error counter (TEC).
that can trigger an error frame. These
seven consecutive recessive bits. This
are: These, along with a detailed list of fault
field serves two purposes: firstly it allows
• Bit error – where the transmitting node confinement rules, determine which state a
receiving nodes time to finish processing
detect that the bit it transmitted is node should be in.
the message, and secondly, if an error is
different to the bit it
detected in the CRC, then the error frame
read back. Obviously
can be transmitted within the data frame.
this does not apply
If this field was not here and an error was during the arbitration
detected at the very end of the CRC field, field and the ACK Error active
then the error frame would appear after the slot.
transmitting node has finished and it will think • Bit-stuffing error –
transmission was successful and not retransmit where six consecutive REC < 127
the message. The error frame would simply be bits of the same and TEC < 127
confused with an overload frame. polarity are detected.
This does not apply
Remote frame to error or overload Error passive TEC > 255 Bus off
frames, as this is
The second type of frame is the remote
intentional.
frame. Essentially, the remote frame is
• Acknowledge error –
exactly the same as a data frame with one
distinct difference: no data. So what is its
where the transmitter REC - receive error counter
detects a recessive bit
purpose? Well, the point of a remote frame
is to request data. By including this frame
in the ACK slot. TEC - transmit error counter
• CRC error – where
in the standard, it allows for messages to be
the CRC calculations
transmitted on a request basis, so that they
do not match.
are only transmitted when another node
• Form error – where a dominant bit is That now completes the material defined
requests the data.
detected in one of the fixed formatted by the CAN standard. In our next article we
This is how it is done: segments, for example during a will cover some really interesting material,
• Once again, the SOF bit marks the start delimiter. the CAN application layer and higher level
of the frame. The format of an error frame is quite simple, protocols.
• The arbitration field contains the ID of it is just six consecutive dominant bits and
the message being requested. then eight consecutive recessive bits. Since If you have any questions or would
• The control field specifies the length of the first six bits are dominant, they will like further information please do
the data message being requested. The always win out on the bus no matter what not hesitate to email Jason Turner at
CRC field is the same as before. else is being transmitted. Additionally, it REDARC - power@redarc.com.au -
• As is the ACK field. intentionally breaks the bit stuffing rule, to or call (08) 8322 4848.

AUGUST/SEPTEMBER 2014

You might also like