Académique Documents
Professionnel Documents
Culture Documents
SAM7
04/15/11 1
CAN
CAN Agenda
What is CAN ?
Why CAN ?
CAN Protocol
CAN Higher Layer Protocols
CAN Applications
AT91 CAN Microcontrollers – Roadmap
04/15/11 2
CAN
What is CAN ?
Controller Area Network
Invented by Robert Bosch GmbH in 1980 for automotive
applications
Asynchronous Serial Bus
Simple 2-wire differential bus
Absence of node addressing
• Message identifier specifies contents and priority
• Lowest message identifier has highest priority
Non-destructive arbitration system by CSMA with collision
detection
Multi-master / Broadcasting concept
Sophisticated error detection & handling system
04/15/11 3
CAN
What is CAN ?
The CAN is an ISO standard (ISO 11898) for serial communication
Today CAN has gained widespread use:
Industrial Automation
Automotive, …etc.
The CAN standard includes:
Physical layer
Data-link layer
• Some message types
• Arbitration rules for bus access
• Methods for fault detection and fault confinement
04/15/11 4
CAN
Why CAN ?
Mature Standard
CAN protocol more than 16 years
Numerous CAN products and tools on the market
Hardware implementation of the protocol
Combination of error handling and fault confinement with high
transmission speed (up to 1Mb/s)
Simple Transmission Medium
Twisted pair of wires is the standard, but also just one wire will
work
Other links works, too: Opto - or radio links
Excellent Error Handling
CRC error detection mechanism
Fault Confinement
Built-in feature to prevent faulty node to block system
Most used protocol in industrial and automotive world
04/15/11 5
Protocol - CAN
CAN Protocol
04/15/11 6
Protocol - CAN
6. Presentation Layer
CAN Layers
3. Network Layer
04/15/11 7
Protocol - CAN
CAN Controller
CAN Transceiver
04/15/11 8
Protocol - CAN
TXD CAN_H
CAN Bus
µController CAN CAN
Controller Transceiver
RXD CAN_L
04/15/11 11
Protocol - CAN
04/15/11 12
Protocol - CAN
04/15/11 13
Protocol - CAN
04/15/11 14
Protocol - CAN
04/15/11 15
Protocol - CAN
Frame Formats
04/15/11 16
Protocol - CAN
04/15/11 18
Protocol - CAN
04/15/11 19
Protocol - CAN
Fault Confinement
04/15/11 20
Protocol - CAN
Automotive example
2000 hours/year
Baud rate: 500 kbps
25% bus load
04/15/11 21
HLP - CAN
04/15/11 22
HLP - CAN
HLP Definition
CAN protocol defines only the physical and a low data link layer !
The HLP defines:
Start-up behavior
Definition of message identifiers for the different nodes
Flow control
Transportation of messages > 8bytes
Definition of contents of Data Frames
Status reporting in the system
04/15/11 23
HLP - CAN
CANopen
Features
CANopen is a subset from CAL (CAN Application Layer) developed by CiA
Auto configuration the network
Easy access to all device parameters
Device synchronization
Cyclic and event-driven data transfer
Synchronous reading or setting of inputs, outputs or parameters
Applications
Machine Automation
Advantages
Accommodating the integration of very small sensors and actuators
Open and vendor independent
Supports inter-operability of different devices
High speed real-time capability
DeviceNet
Features
Created by Allen-Bradley (Rockwell Automation nowadays), now
presented by the users group ODVA (Open DeviceNet Vendor
Association)
Power and signal on the same network cable
Bus addressing by: Peer-to-Peer with multi-cast & Multi-Master & Master-
Slave
Supports only standard CAN
Applications
Machine Automation
Advantages
Low cost communication link and vendor independent
Removal and replacement of devices from the network under power
CAN Kingdom
CAN Kingdom is more than a HLP (Meta Protocol):
Introduced by KVASER, Sweden
A ‘King’ (system designer) takes the full responsibility of the system
The King is represented by the Capital (supervising node)s
CAN Kingdom provides simple unique identification of system nodes
Applications
Machine Automation
Advantages
Designed for safety critical applications
Real time performance
Scalability
Integration of DeviceNet modules in CAN Kingdom possible
04/15/11 26
HLP - CAN
SAE J1939
Features
Developed by Society of Automotive Engineers heavy trucks and bus
division (SAE)
Use of the 29 identifiers
Support of real-time close loop control
Applications
Light to heavy trucks
Agriculture equipment e.g. tractors, harvester etc…
Engines for public work
04/15/11 27
HLP - CAN
OSEK/VDX
Initiative of:
BMW, Bosch, DaimlerChrysler, Opel, Siemens,VW & IIIT of the
University of Karlsruhe / PSA and Renault
Goal: Portability and re-usability of the application software
OSEK/VDX includes:
Communication (Data exchange within and between Control Units)
Network Management (Configuration determination and monitoring)
Operating System (Real-time executive for ECU software)
Applications
Automotive
Advantages: Saving in costs and development time
CAN Applications
04/15/11 30
Applications - CAN
04/15/11 31
AT91SAM7 - CAN
04/15/11 32
AT91SAM7 - CAN
AT91SAM7A1:
1 CAN Controller 2.0A and 2.0B FullCAN with 16 Mailboxes
AT91SAM7A2:
4 CAN Controllers 2.0A and 2.0B FullCAN
• 1 with 32 Mailboxes, 3 with 16 Mailboxes
AT91SAM7A3:
2 CAN Controllers 2.0A and 2.0B FullCAN with 16 Mailboxes
AT91SAM7X:
1 CAN Controller 2.0A and 2.0B FullCAN with 8 Mailboxes
AT91SAM7A3 – AT91SAM7X
CAN Controller
04/15/11 36
SAM7A3 / SAM7X - CAN
04/15/11 37
SAM7A3 / SAM7X - CAN
04/15/11 38
SAM7A3 / SAM7X - CAN
CAN Initialization
Status Registers Mode Register
0 2
Error Flags CANEN ABM
04/15/11 39
SAM7A3 / SAM7X - CAN
Sample Point: point in time at which the bus level is read as the value of that
respective bit.
1 Time Quantum 1 period of CAN Controller Clock
Time Quantum = (BRP + 1) / MCK
SYNC_SEG is 1 TQ long.
04/15/11 42
SAM7A3 / SAM7X - CAN
The CAN controller offers optimized features useful to support the Time-
Triggered protocols.
Time Management Unit can operate in two modes:
Time Stamping Mode (TTM = 0): the value of the internal timer (CAN_TIM)
is captured in the CAN Timestamp register (CAN_TIMESTP) at each:
• start of frame (TEOF = 0)
• end of frame (TEOF = 1)
04/15/11 44
SAM7A3 / SAM7X - CAN
Data & Remote Frames can be sent/received thanks to the different mailboxes:
A successful transfer raises the Mailbox Ready flag (MRDY) in the mailbox
status register.
When a transmit mailbox looses bus arbitration, the transfer request remains
pending.
Disable Repeat DRPT = 1:
• Transfer request is aborted if the transmit mailbox looses bus arbitration.
• Mailbox Abort flag (MABT) in the mailbox status register raises.
Overload Frames can be generated by setting OVL flag in the Mode Register:
OVL = 1: an overload is generated after each successful reception.
04/15/11 45
SAM7A3 / SAM7X - CAN
Mailbox Organisation
Mailbox x
CAN_MMRx
CAN_MMRx
Eight 32-bit registers by mailbox
CAN_MAMx
CAN_MAMx
Mailbox x Mode Register CAN_MIDx
CAN_MIDx
Mailbox x Acceptance Mask Register
Mailbox x ID Register CAN_MFIDx
CAN_MFIDx
Mailbox x Family ID Register
CAN_MSRx
CAN_MSRx
Mailbox x Status Register
Mailbox x Data Low Register CAN_MDLx
CAN_MDLx
Mailbox x Data High Register
Mailbox x Control Register CAN_MDHx
CAN_MDHx
CAN_MCRx
CAN_MCRx
04/15/11 47
SAM7A3 / SAM7X - CAN
Pull Model:
Producer Producer Mailbox
Consumer Consumer Mailbox
Consumer transmit a remote frame
to the Producer.
Producer transmit the answer to the
Consumer.
Pull Model:
With Tx Rx mailboxes: 1 Tx+ 1 Rx Mailbox for each node 4 Mailboxes
Receive mailbox:
The first message received is stored in mailbox data registers.
Other messages are ignored by this mailbox.
Receive with Overwrite mailbox:
The first message received is stored in mailbox data registers.
The next message overwrites the previous one.
Consumer mailbox (Enhanced Reception Mailbox):
Sends a remote frame to a producer mailbox.
Waits automatically for a data frame with the same ID from a producer mailbox.
04/15/11 49
SAM7A3 / SAM7X - CAN
Transmit mailbox:
Sends either a remote frame or a data frame.
Producer mailbox (Enhanced Transmit Mailbox):
Waits for a remote frame from a consumer mailbox.
Once the remote frame received, sends automatically a data frame with the same
ID to the consumer mailbox.
04/15/11 50
SAM7A3 / SAM7X - CAN
Mailbox Priority
Mailbox Mode Register
16
PRIOR
Reception Modes:
In this modes, the mailbox with the lowest number is serviced first.
Transmission Modes:
Mailbox with the highest priority PRIOR lowest value.
When several mailboxes try to transmit a message at the same time, the mailbox with
the highest priority is services first.
If at least two mailboxes have the same priority (same PRIOR value), the mailbox with
the lowest number is serviced first.
04/15/11 51
SAM7A3 / SAM7X - CAN
Size of the message is defined in the Mailbox Data Length Code field (MDLC)
Mailbox Transfer Command Request (MTCR = 1):
Allows transmission of the current message.
Message can be aborted (MACR =1).
Mailbox Remote Transmission Request (MRTR = 1):
Allows to send a remote frame (MDLC value is ignored).
04/15/11 52
SAM7A3 / SAM7X - CAN
04/15/11 54
SAM7A3 / SAM7X - CAN
Allows to receive buffer split into several messages with the same ID buffer size > 8 bytes.
04/15/11 55
SAM7A3 / SAM7X - CAN
04/15/11 56
SAM7A3 / SAM7X - CAN
04/15/11 57
SAM7A3 / SAM7X - CAN
The CAN Transfer Command Register (CAN_TCR) allows to perform several transfer
requests at the same time.
The CAN Abort Command Register (CAN_ACR) allows to perform several abort
requests at the same time.
04/15/11 58