CAN_Basics_2 - Renesas e
Download
Report
Transcript CAN_Basics_2 - Renesas e
Course Introduction
Purpose
• This training course provides an overview of Message Frames and hardware
issues of the Controller Area Network (CAN) technology used to build networked,
multiprocessor embedded systems.
Objectives
• Discover the types of Message Frames in CAN bus traffic and the purpose of
each.
• Learn the details of a CAN Data Frame.
• Understand hardware issues of implementing CAN networks.
Content
• 23 pages
• 3 questions
Learning Time
• 30 minutes
1
© 2009, Renesas Technology America, Inc., All Rights Reserved
What is CAN?
Controller Area Network
Two-wire, bidirectional serial-bus communication method
Economical solution for high-integrity
networking in real-time embeddedcontrol applications
Standardized internationally
- CAN 2.0A: ISO11519 (low speed)
- CAN 2.0B: ISO11898 (high speed)
Widely used: >>100,000,000 nodes/year
Key features
- High reliability (essentially error free,
even in noisy environments)
- Low wiring cost and node-connection cost
- Readily scalable
- Off-the-shelf tools
- Supported by many chips
- Knowledge base growing
2
© 2009, Renesas Technology America, Inc., All Rights Reserved
Types of Message Frames
Data Frame - Carries the actual data (payload)
Error Frame - Six consecutive dominant bits,
sent anytime an error is detected by the
hardware at any node
Overload Frame - Requests a delay on the bus
Interframe Space - Provides minimum spacing between data
and remote frames; allows error frames to have levels of priority
Remote Frame - Requests transmission of a Data Frame;
carries no payload
3
© 2009, Renesas Technology America, Inc., All Rights Reserved
Data Frames: Two Types
Standard Frame (CAN 1.0 and 2.0A)
Start of Frame
End of
Frame
Arbitration Field
ACK Field
Control Field
CRC Field
Data Field
Extended Frame (CAN 2.0B)
4
© 2009, Renesas Technology America, Inc., All Rights Reserved
PERTIES
assing, 'Finish' button:
ailing, 'Finish' button:
w user to leave quiz:
may view slides after quiz:
may attempt quiz:
Goes to Next Slide
Goes to Slide
At any time
After passing quiz
Unlimited times
Start of Frame
Indicated by single dominant bit occurring
when bus is idle
All nodes synchronize timing to leading edge
Start of Frame
6
© 2009, Renesas Technology America, Inc., All Rights Reserved
Arbitration Field: IDs
Standard ID: CAN 2.0A and CAN 2.0B
12 bits
Standard ID
(11 bits)
ID0
RTR
ID10
- Gives CAN 2.0B backward compatibility
with CAN 2.0A
- 11 bits allow up to 2032 unique IDs
Extended ID: CAN 2.0B only (optional)
- 29 bits allow over 500 million unique IDs
- Extended ID with same 11-bit higher-order
field has lower priority than Standard ID
RTR bit following the ID is dominant for a
Data Frame, recessive for a Remote Frame
Arbitration Field
[Additional ID space]
(Low-order field, 18 bits)
ID0
RTR
Standard ID
(High-order
field, 11 bits)
ID18
SRR
IDE
ID17
ID28
32 bits
Extended ID (29 bits, CAN 2.0B)
7
© 2009, Renesas Technology America, Inc., All Rights Reserved
Keeping Traffic Flowing
CAN Arbitration Protocol: CSMA/CD-CR
- Carrier Sense — Nodes wait for period without bus activity
before sending message
- Multiple Access — Every node has an equal opportunity to
transmit message
- Collision Detection — Collision occurs if two nodes attempt
to transmit at same time
- Collision Resolution — Non-destructive bitwise arbitration
keeps messages intact; sends highest-priority message
without delay; and subsequently allows retransmissions of
lower-priority messages
8
© 2009, Renesas Technology America, Inc., All Rights Reserved
Keeping Traffic Flowing
• Uses Dominant and Recessive bits
- IDs with dominant bits get priority
- Nodes attempting to send lower-priority messages try to transmit in
each successive cycle, succeeding when they finally attain priority
9
© 2009, Renesas Technology America, Inc., All Rights Reserved
Control Field
Data Length Code (DLC) tells how much information the Data
Field contains
2 bits of Control field are reserved
4 bits give DLC (# of bytes in Data Field)
Number
of Data
Bytes
0
1
2
3
4
5
6
7
8
DCL0
DCL3
RB0
IDE
Data Length
Code (4 bits)
Control Field
Data Length Code
DLC DLC DLC DLC
3
2
1
0
0
0
0
0
0
0
0
1
0
0
1
0
0
0
1
1
0
1
0
0
0
1
0
1
0
1
1
0
0
1
1
1
1
0
0
0
10
© 2009, Renesas Technology America, Inc., All Rights Reserved
Data Field
Content: Payload of Data Frame
Length: 0 to 8 bytes
MSB is transmitted first
Payload of Data Frame
(0, 1, 2, 3, 4, 5, 6, 7 or 8 bytes)
Data Field
11
© 2009, Renesas Technology America, Inc., All Rights Reserved
CRC Field
15-bit Cyclic Redundancy Check (CRC) value followed
by a recessive delimiter
CRC polynomial: x15+x14+x10+x8+x7+x4+x3+1
Generated by transmitter node’s hardware; verified in
each receiver node’s hardware
If receiver-generated CRC matches transmitted CRC,
receiver puts a dominant bit in ACK slot
If no match, receiver sends ‘NO’ vote AFTER upcoming
ACK delimiter
CRC Code
Del
15 bits
CRC 12
Field
© 2009, Renesas Technology America, Inc., All Rights Reserved
ACK Field
ACK Slot + ACK Delimiter
All receivers that receive valid messages report
successful reception by placing a dominant bit in
the ACK slot*
Receivers that do not get a valid message (indicated by
* Because every node
acknowledges messages, the
round-trip propagation delay is
the
primary distance limitation of
CAN.
Del
ACK
CRC mismatch) vote ‘NO’ by placing an error flag
after the delimiter
ACK Field
13
© 2009, Renesas Technology America, Inc., All Rights Reserved
End of Frame
Delimits the end of a Data Frame
Consists of seven recessive bits for Data Frame (also for
a Remote Frame)
Provides a short break in communication flow before
the next frame, allowing time for Error Frames, etc.
7 bits
End of Frame
14
© 2009, Renesas Technology America, Inc., All Rights Reserved
PERTIES
assing, 'Finish' button:
ailing, 'Finish' button:
w user to leave quiz:
may view slides after quiz:
may attempt quiz:
Goes to Next Slide
Goes to Slide
At any time
After passing quiz
Unlimited times
Types of Errors
Five types of errors, detected locally:
1. Bit error
Received bit at sender not equal to
transmitted bit
2. Bit-stuffing violation More than five consecutive bits with
same polarity
3. CRC error
4. Form error
Checksum violation
5. ACK error
No dominant bit in ACK slot, so sender
must retransmit Message Frame
Bit pulse distorted; invalid bit at
predetermined points in message frame
16
© 2009, Renesas Technology America, Inc., All Rights Reserved
Node Hardware Operating States
Depending on error detection, hardware is in:
Error Active State — Normal operating state; messages can be
transmitter and received.
Error Passive State — Despite frequent transmit and receive
problems, messages still can be transmitter and received.
Bus Off State — Serious problems transmitting messages; no
messages can be transmitted or received until hardware is
reset. This prevents a faulty node from causing a bus failure.
Summary of CAN Error Process
1. Error detected by node
2. Error frame immediately transmitted
3. Message cancelled at all nodes
4. Status of hardware at nodes updated
5. Message re-transmitted
17
© 2009, Renesas Technology America, Inc., All Rights Reserved
Implementing CAN Systems
Needed:
Firmware
CAN controller
CAN transceivers
A physical media
Bus length (meters)
Maximum bit rate*
40
1Mbps
100
500kbps
200
250kbps
500
125kbps
6km
10kbps
18
* CAN 2.0B
© 2009, Renesas Technology America, Inc., All Rights Reserved
CAN Hardware Designs
Two main CAN controller implementation strategies:
CAN controller
BasicCAN
FullCAN
Key differences between strategies:
How decision is made on whether or not a message
is of interest to a receiving node
How remote frames are answered
How messages are buffered
Implementation determines amount of processing load
put on host microcontroller
19
© 2009, Renesas Technology America, Inc., All Rights Reserved
Features of BasicCAN Networks
Transmit
Application fills complete Tx register, including ID, RTR,
data length, and data; every ID can be transmitted
Receive
Every CAN message can be received
Normally two receive buffers in FIFO structure
Global message filtering: Filter cannot be set up to pass
only the interesting messages; final filtering must be done
by the application
Remote
Frame
Handling
Remote frames are answered by the application
Overrun
Philosophy
Keep oldest message; newer messages will be lost
20
© 2009, Renesas Technology America, Inc., All Rights Reserved
Features of FullCAN Networks
Transmit
Transmit mailboxes initialized once
Only data bytes written before transmission
Receive
Only messages with the IDs defined in receive mailboxes
can be received
No double-buffering for mailboxes
Full acceptance filtering; only exact message IDs are
let through
Remote
Frame
Handling
Remote frames are answered automatically by
the controller
Overrun
Philosophy
Keep newest message; older messages with the
same ID will be lost
21
© 2009, Renesas Technology America, Inc., All Rights Reserved
PERTIES
assing, 'Finish' button:
ailing, 'Finish' button:
w user to leave quiz:
may view slides after quiz:
may attempt quiz:
Goes to Next Slide
Goes to Slide
At any time
After passing quiz
Unlimited times
Course Summary
• Types of CAN Message Frames
• Data Frame Details
• Bus Errors
• Implementation Strategies: BasicCAN vs. FullCAN
23
© 2009, Renesas Technology America, Inc., All Rights Reserved