At91sam7 - Can
At91sam7 - Can
At91sam7 - Can
08/18/11
CAN
CAN Agenda
What is CAN ? Why CAN ? CAN Protocol CAN Higher Layer Protocols CAN Applications AT91 CAN Microcontrollers Roadmap
08/18/11
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
08/18/11
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
08/18/11
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
5
08/18/11
Protocol - CAN
CAN Protocol
08/18/11
Protocol - CAN
6. Presentation Layer
CAN Layers
08/18/11
Protocol - CAN
CAN Controller
CAN Transceiver
08/18/11
Protocol - CAN
Node 2 D D r r D D r r
Node 3 D r D r D r D r
Wired-AND Function
Protocol - CAN
Controller
CAN Bus is a simple 2-wire differential serial bus CAN Bus is terminated on each side by a 120 Ohm resistor
08/18/11
10
CAN Bus
TXD
CAN_H
Protocol - CAN
08/18/11
11
Protocol - CAN
08/18/11
CSMA/CD: Carrier Sense Multiple Access / Collision Detection AMP: Arbitration by Message Priority
12
Protocol - CAN
08/18/11
13
Protocol - CAN
SYNC_SEG: synchronize the different nodes PROP_SEG: compensate for signal delays across the network PHASE_SEG1 & 2: compensate for edge phase errors 1 Bit Time 8 to 25 Time Quanta
08/18/11
14
Protocol - CAN
08/18/11
15
Protocol - CAN
Frame Formats
SOF: Start Of Frame CRC: Cyclic Redundancy Code ACK: Acknowledge EOF: End of Frame IFS: Inter Frame Space
08/18/11
16
Protocol - CAN
SRR: Substitute Remote Request RB0/1: Reserved bits DLC: Data Length Code
Protocol - CAN
Protocol - CAN
Protocol - CAN
Fault Confinement
CAN Node Error States: Error Active: Normal state, node can send all frames (error frames included) Error passive: Node can send all frames excluding error frames Bus off: Node is isolated from bus Internal Counters: TEC & REC TEC: Transmit Error Counter REC: Receive Error Counter
Protocol - CAN
HLP - CAN
08/18/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
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
HLP - CAN
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 & MasterSlave 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
HLP - CAN
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
08/18/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
08/18/11
27
HLP - CAN
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
Applications - CAN
CAN Applications
08/18/11
30
Applications - CAN
08/18/11
AT91SAM7 - CAN
08/18/11
32
AT91SAM7 - CAN
AT91SAM7 - CAN
AT91SAM7 - CAN
s s
s s s
Fully Compliant with CAN 2.0 Part A and 2.0 Part B High Speed CAN: Bit Rates up to 1Mbit/s Data, Remote, Error and Overload Frame Handling Mailboxes with the Following Properties: Standard or Extended ID Programmable for Each Message Mailbox Configurable in Receive (with Overwrite or Not) or Transmit Modes Producer & Consumer Mailbox Feature Independent 29-bit Identifier and Mask Defined for Each Mailbox Uses a 16-bit / 32-bit Timestamp on Receive and Transmit Messages Hardware Concatenation of ID Masked Bitfields To Speed Up Family ID Processing Global 16-bit / 32-bit Internal Timer for Time stamping Priority Management between Transmission Mailboxes: Mailbox number prioritization Message ID prioritization Autobaud Mode Automatic retransmission of corrupted messages Low Power Mode and Programmable Wake-up SAM7A1-A2 Specific / SAM7A3-X Specific
08/18/11
35
08/18/11
36
s s s s s
PIO CAN_TX and CAN_RX have to be configured in peripherals. CAN Transceiver must be enabled through a PIO configured in Output. CAN Internal Timer is 16-bit long. 8 Mailboxes for SAM7X 16 Mailboxes for SAM7A3
08/18/11
37
08/18/11
38
CAN Initialization
Status Registers Mode Register
Error Flags
CANEN
ABM
CANEN = 1: Enable CAN Controller Wait for bus synchronization (11 consecutive recessive bits are scanned) WAKEUP flag is set
ABM = 1: Enable Autobaud Mode Error counters are disabled Transmission is disabled
08/18/11
39
BRP
16
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
SJW
12
PROPAG
PHASE1
PHASE2
Nominal Bit Time: 8 to 25 TQ long. Information Processing Time (IPT): time required to determine the bit level of a sampled bit. SYNC_SEG is 1 TQ long. PROP_SEG: 1 to 8 TQ PHASE_SEG1: 1 to 8 TQ PHASE_SEG2 = Max(IPT, PHASE_SEG1) SJW = Min(PHASE_SEG1, 4TQ)
TPRS =TCSC * (PROPAG+1) TPHS1 =TCSC * (PHASE1+1) TPHS2 =TCSC * (PHASE2+1) TSJW =TCSC * (SJW+1)
LPM
SLEEP
20
WAKEUP 21
Low Power Mode: Send or receive messages is disabled (Mailboxes inactive) Enter Low Power Mode: Set LPM flag All pending transmit messages are sent before Wait for SLEEP signal raising Internal Counter (CAN_TIM) is reset and stuck to 0x0000. The user can disable CAN Clock (PMC) Exit Low Power Mode: Enable CAN Clock (PMC) Clear LPM flag Wait for bus synchronization WAKEUP signal raising All pending transmit messages are sent before Internal Counter is reset and stuck to 0
08/18/11
42
TTM
TEOF
TSTP
23
MTIMEMARK
The CAN controller offers optimized features useful to support the TimeTriggered 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) Time Triggered Mode (TTM = 1): a mailbox transfer operation is processed when the internal counter reaches the mailbox trigger value (MTIMEMARK field in corresponding mailbox CAN_MMR).
08/18/11
TIMRST
31
TOVF
22
TIMFRZ
CAN_TIM register: Free-running 16-bit timer TIMRST = 1: Allows to clear the counter TIMFRZ = 1: Allows to freeze the counter TOVF = 1: A timer overflow is detected CAN_TIMESTP register: copy of the CAN_TIM after a successful transfer
08/18/11
44
MRDY
23
MABT
OVL
DRPT
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. Error Frames are automatically handled by the macro. Overload Frames can be generated by setting OVL flag in the Mode Register: OVL = 1: an overload is generated after each successful reception.
45
08/18/11
Mailbox Organisation
Mailbox x
CAN_MMRx CAN_MMRx Eight 32-bit registers by mailbox Mailbox x Mode Register Mailbox x Acceptance Mask Register Mailbox x ID Register Mailbox x Family ID Register Mailbox x Status Register Mailbox x Data Low Register Mailbox x Data High Register Mailbox x Control Register CAN_MAMx CAN_MAMx CAN_MIDx CAN_MIDx CAN_MFIDx CAN_MFIDx CAN_MSRx CAN_MSRx CAN_MDLx CAN_MDLx CAN_MDHx CAN_MDHx CAN_MCRx CAN_MCRx
MIDE
29
CAN_MIDx: defines the message ID MIDE = 0: standard message MIDE = 1: standard or extended message CAN_MAMx: defines the mask ID value Allows a mailbox to receive different messages ID. CAN_MFIDx: concatenation of ID & mask ID Speed up message ID decoding
08/18/11
47
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
08/18/11
MOT
24
Reception Mailbox Types: 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.
08/18/11
49
MOT
24
Transmission Mailbox Types: 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.
08/18/11
50
Mailbox Priority
Mailbox Mode Register
PRIOR
16
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.
08/18/11
51
MTCR
23
MACR
22
MDLC
MRTR
20
MRDY
23
08/18/11
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).
52
MTCR
23
MRDY
23
MMI
24
08/18/11
Mailbox Transfer Command MTCR = 1: Allows reception of the next message. When MRDY flag is set, mailbox data registers content is available. MMI flag is set a message has been lost by the mailbox
53
MTCR
23
MRDY
23
MMI
24
08/18/11
Mailbox Transfer Command MTCR = 1: Allows to reset MRDY flag MMI flag is set a new message has overwritten a previous one.
54
Allows to receive buffer split into several messages with the same ID buffer size > 8 bytes.
08/18/11
55
MTCR
23
MACR
MRDY
23
MMI
24
Mailbox Transfer Command MTCR = 1: Allows to wait for a remote frame reception Data is automatically sent after the reception of a remote frame MRDY remains at 0 as long as the message has not been transmitted or aborted (MACR =1).
56
08/18/11
MTCR
23
MRDY
23
Mailbox Transfer Command MTCR = 1: Allows to send a remote frame. Then, waits automatically for a data frame from a producer mailbox. MRDY remains at 0 as long as the data frame has not been received or aborted.
08/18/11
57
08/18/11
58