Upload
gopismiles1987
View
136
Download
8
Tags:
Embed Size (px)
Citation preview
CAN
04/09/23 1
SAM7
Controller Area Network
CAN
04/09/23 2
CAN Agenda
What is CAN ? Why CAN ? CAN Protocol CAN Higher Layer Protocols CAN Applications AT91 CAN Microcontrollers – Roadmap
CAN
04/09/23 3
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
CAN
04/09/23 4
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
CAN
04/09/23 5
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
CAN
04/09/23 6
CAN Protocol
Protocol -
CAN
04/09/23 7
ISO-OSI Reference Model
Protocol -
7. Application Layer
5. Session Layer
6. Presentation Layer
4. Transport Layer
3. Network Layer
2. Data Link Layer
1. Physical LayerCAN Protocol
HLPs: CANopen, DeviceNet, OSEK/VDX
Partially Implemented by High Layer Protocol (HLP)
CA
N L
ayer
s
CAN
04/09/23 8
ISO-OSI Reference Model (2)
Protocol -
CAN Controller
CAN Transceiver
CAN
04/09/23 9
CAN Bus Logic
Protocol -
Node 1 Node 2 Node 3 Bus
D D D D
D D r D
D r D D
D r r D
r D D D
r D r D
r r D D
r r r r
‘1’ Recessive (r)
‘0’ Dominant (D)
Two logic states on the CAN bus
Bus in dominant state
Bus in recessive stateor idle
Wired-AND Function
CAN
04/09/23 10
Typical CAN Node
Protocol -
µController CAN Controller
CAN Transceiver
CA
N B
usCAN_H
CAN_L
TXD
RXD
CAN Bus is a simple 2-wire differential serial bus
CAN Bus is terminated on each side by a 120 Ohm resistor
CAN
04/09/23 11
CAN Bit Coding & Bit Stuffing
Protocol -
Bit Coding : NRZ (Non-Return-To-Zero code) does not ensure enough edges for synchronization
Stuff Bits are inserted after 5 consecutive bits of the same level Stuff Bits have the inverse level of the previous bit. No deterministic encoding, frame length depends on transmitted data
Number of consecutive bitswith the same polarity
CAN
04/09/23 12
CAN Bus Access and Arbitration:CSMA/CD and AMP
Protocol -
CSMA/CD: Carrier Sense Multiple Access / Collision Detection AMP: Arbitration by Message Priority
CAN
04/09/23 13
CAN Bus Synchronization
Protocol -
Hard synchronization at Start Of Frame bit
Re-Synchronization on each Recessive to Dominant bit
CAN
04/09/23 14
CAN Bit Construction
Protocol -
CAN Bit Period Four Time Segments Each Time Segment represents a number of Time Quanta (TQ) 1 Time Quantum 1 period of CAN Controller Clock
1 Bit Time 8 to 25 Time Quanta
SYNC_SEG: synchronize the different nodes PROP_SEG: compensate for signal delays across the network PHASE_SEG1 & 2: compensate for edge phase errors
CAN
04/09/23 15
Relation between Baud Rate and Bus Length
Protocol -
CAN
04/09/23 16
Frame Formats
Protocol -
SOF: Start Of Frame CRC: Cyclic Redundancy Code ACK: Acknowledge EOF: End of Frame IFS: Inter Frame Space
CAN
04/09/23 17
Frame Formats (2)
Protocol -
CAN V2.0A Standard Frame: Identifier is 11 bits long
CAN V2.0B Extended Frame: Identifier is 29 bits long
Our CANs supports CAN V2.0A & CAN V2.0B Specification
ID: Identifier IDE: Identifier Extension RTR: Remote Transmission Request
SRR: Substitute Remote Request RB0/1: Reserved bits DLC: Data Length Code
CAN
04/09/23 18
Frame Formats (3)
Protocol -
Four different frame formats:
Data Frame has priority on Remote Frame
Remote Frame : RTR Recessive ‘1’ and No Data Field
Data Frame : RTR Dominant ‘0’
CAN
04/09/23 19
Frame Formats (4)
Protocol -
Error Frame: sent after a violation frame format
Overload Frame: prevents data overflow from a slower CAN
Overload Frames are not really used
CAN
04/09/23 20
Fault Confinement
Protocol -
TEC and REC counters allows to prevent from faulty nodes
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
CAN
04/09/23 21
Error Detection Analysis
Protocol -
One undetected error every 1000 years !!!
Error statistics depend on the entire environment Total number of nodes Physical layout EMI disturbance
Automotive example 2000 hours/year Baud rate: 500 kbps 25% bus load
CAN
04/09/23 22
CAN High Layer Protocols
HLP -
CAN
04/09/23 23
HLP Definition
HLP -
One undetected error every 1000 years !!!
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
CAN
04/09/23 24
CANopen
HLP -
CiA (CAN in Automation)
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
CAN
04/09/23 25
DeviceNet
HLP -
CANopen (Europe) – DeviceNet (USA)
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
04/09/23 26
CAN Kingdom
HLP -
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
CAN
04/09/23 27
SAE J1939
HLP -
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
CAN
04/09/23 28
X-by-wire systems &Time-triggered protocols
HLP -
Predictable new protocols Applications
Automotive, aircraft…
TTCAN: Time Triggered CAN: Robert Bosch GmbH, CiA.
FLexRay: General Motors, DaimlerChrysler, BMW, Motorola, Philips
Semiconductors and Bosch Automotive Group. TTP: Time Triggered Protocol:
PSA Peugeot Citroen, Audi,Volkswagen, Honeywell and Delphi Automotive Systems.
FlexRay is becoming the reference
CAN
04/09/23 29
OSEK/VDX
HLP -
Usually called OSEK
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
04/09/23 30
CAN Applications
Applications -
CAN
04/09/23 31
CAN: a Large Field of Applications
Applications -
Building Automation: Heating control, Air Conditioning, Security, Access & Light
Control… Domestic & Food distribution appliances
Washing machines, dishes cleaner, self-service bottle distributors…
Automotive & Transportation Dash Board, Power train & Car Body Train, bus and truck equipment…
Robotic Production Automation:
Control & link of production machines… Medical Agriculture
Harvester, seeding, sowing machines, tractor control...
CAN
04/09/23 32
AT91SAM7 CAN Embedded ControllersA1 - A2 - A3 - X
AT91SAM7 -
CAN
04/09/23 33
CAN Controllers Types
3 types of CAN controllers exist: CAN Controllers 2.0 Part A: standard frames CAN Controllers 2.0 Part B Passive or ‘extended frames passive’ CAN Controllers 2.0 Part B Active or ‘extended frames active’
CAN Implementations: 2 main implementations strategy BasicCAN: cheaper CAN Controller
• 1 or 2 Rx buffers (FIFO) and 1 Tx buffer• Minimal Filtering
FullCAN: high performance CAN Controllers• Set of buffers called Mailboxes• Dedicated Mailbox Filtering
Our CANs: 2.0A/2.0B (Active) & FullCAN
AT91SAM7 -
CAN
04/09/23 34
CAN Controllers Features Two different CAN implementations for the AT91SAM7 family:
CAN embedded in SAM7A1 & SAM7A2 (Europe Technologies CAN) CAN embedded in SAM7A3 & SAM7X (ATMEL Rousset 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
AT91SAM7 -
SAM7A1-A2 Specific / SAM7A3-X Specific
CAN
04/09/23 35
CAN Controllers Features (2) 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
AT91SAM7 -
CAN
04/09/23 36
AT91SAM7A3 – AT91SAM7XCAN Controller
SAM7A3 / SAM7X -
CAN
04/09/23 37
CAN on SAM7X-EK & SAM7A3-EK Boards
PMC has to be programmed 1st for CAN to work: Clock Enabling- Set the PMC_PCER (Peripheral Clock Enable Register).
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
SAM7A3 / SAM7X -
CAN
04/09/23 38
CAN Controller Structure
SAM7A3 / SAM7X -
CAN
04/09/23 39
CAN Initialization
SAM7A3 / SAM7X -
CANEN = 1: Enable CAN Controller Wait for bus synchronization (11 consecutive
recessive bits are scanned) WAKEUP flag is set
Status Registers
Error Flags
Mode Register
CANEN 0 ABM 2
ABM = 1: Enable Autobaud Mode Error counters are disabled Transmission is disabled
CAN
04/09/23 40
CAN Bit Timing Configuration
SAM7A3 / SAM7X -
Baudrate Register
BRP 16
Time Quantum = (BRP + 1) / MCK
TBIT =TSYNC + TPRS + TPHS1 + TPHS2
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
CAN
04/09/23 41
CAN Bit Timing Configuration (2)
SAM7A3 / SAM7X -
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)
IPT is 2 TQ for ATMEL CANs
Baudrate Register
SJW 12 PROPAG 8PHASE1 4 PHASE2 0
TPRS =TCSC * (PROPAG+1)
TPHS1 =TCSC * (PHASE1+1)
TPHS2 =TCSC * (PHASE2+1)
TSJW =TCSC * (SJW+1)
CAN
04/09/23 42
Low Power Mode
SAM7A3 / SAM7X -
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
Mode Register
LPM 1
Status Register
SLEEP 20 WAKEUP 21
CAN
04/09/23 43
Time Management Unit
SAM7A3 / SAM7X -
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).
Mode Register
TEOF 4TTM 5 TSTP 23
Status Register
TSTP = 1: A start or an end of frame has been detected
MTIMEMARK 0
Message Mode Register
The CAN controller offers optimized features useful to support the Time-Triggered protocols.
CAN
04/09/23 44
Time Management Unit (2)
SAM7A3 / SAM7X -
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
Transfer Cmd Reg
TIMRST 31 TOVF 22
Status Register Mode Register
TIMFRZ 6
CAN_TIMESTP register: copy of the CAN_TIM after a successful transfer
CAN
04/09/23 45
Data, Remote, Error & Overload Frames Handling
SAM7A3 / SAM7X -
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.
Mailbox Status Register
MABT 22
Mode Register
OVL 3 DRPT 7MRDY 23
CAN
04/09/23 46
Mailbox Organisation
SAM7A3 / SAM7X -
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
Mailbox Channel Buffer
CAN_MAMxCAN_MAMx
CAN_MMRxCAN_MMRx
CAN_MIDxCAN_MIDx
CAN_MFIDxCAN_MFIDx
CAN_MDLxCAN_MDLx
CAN_MSRxCAN_MSRx
CAN_MDHxCAN_MDHx
CAN_MCRxCAN_MCRx
Mailbox x
CAN
04/09/23 47
Message Acceptance Procedure
SAM7A3 / SAM7X -
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
Mailbox ID & Acceptance Mask Register
MIDE 29
CAN
04/09/23 48
Push / Pull Model
SAM7A3 / SAM7X -
Push Model: Classical Tx Rx Producer Tx Mailbox Consumer Rx Mailbox
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
With Consumer Producer mailboxes: 2 Mailboxes only !
CAN
04/09/23 49
Mailbox Object Type
SAM7A3 / SAM7X -
Five programmable type of mailboxes (MOT field in CAN_MMRx)
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.
Mailbox Mode Register
MOT 24
CAN
04/09/23 50
Mailbox Object Type (2)
SAM7A3 / SAM7X -
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.
Mailbox Mode Register
MOT 24
CAN
04/09/23 51
Mailbox Priority
SAM7A3 / SAM7X -
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.
Mailbox Mode Register
PRIOR 16
CAN
04/09/23 52
Transmit Mailbox Handling
SAM7A3 / SAM7X -
Mailbox Status Register
MRDY 23
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).
Mailbox Control Register
MACR 22MTCR 23 MDLC 16 MRTR 20
CAN
04/09/23 53
Receive Mailbox Handling
SAM7A3 / SAM7X -
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
Mailbox Control Register
MTCR 23
Mailbox Status Register
MMI 24MRDY 23
CAN
04/09/23 54
Receive with Overwrite Mailbox Handling
SAM7A3 / SAM7X -
Mailbox Transfer Command MTCR = 1: Allows to reset MRDY flag
MMI flag is set a new message has overwritten a previous one.
Mailbox Control Register
MTCR 23
Mailbox Status Register
MMI 24MRDY 23
CAN
04/09/23 55
Chaining Receive Mailboxes
SAM7A3 / SAM7X -
Allows to receive buffer split into several messages with the same ID buffer size > 8 bytes.
CAN
04/09/23 56
Producer Mailbox Handling
SAM7A3 / SAM7X -
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).
Mailbox Control Register
MACR 22
Mailbox Status Register
MMI 24MRDY 23MTCR 23
CAN
04/09/23 57
Consumer Mailbox Handling
SAM7A3 / SAM7X -
Mailbox Control Register
MTCR 23
Mailbox Status Register
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.
CAN
04/09/23 58
Multiple Transfer or Abort Requests
SAM7A3 / SAM7X -
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.