CAN Controller Area Network 29BIT ID Overview and Application Timothy E. Jackson
CAN Frame
CAN Frame IDENTIFIER DLC DATA FIELD Identifier = 29 bits + MAC DLC = Data Length Code 4 bits Indicates number of data bytes Data Field = 0 to 7 bytes Depends on the DLC value
Max frame length with bit stuffing = 127 bits CAN Frame CRC delimiter 1 bit Standard Format, 2.0A Max frame length with bit stuffing = 127 bits Arbitration Field Control Field Data Field 12 bits 6 bits 0 to 64 bits SOF Identifier 11bits RTR IDE r0 DLC 4bits CRC 15bits ACK Field 2bits EOF 7bits Bit Stuffing No Bit Stuffing SOF = Start Of Frame RTR = Remote Transmission Request IDE = Identifier Extension Bit DLC = Data Length Code CRC = Cyclic Redundancy Check ACK = Acknowledgement EOF = End Of Frame
Max frame length with bit stuffing = 150 bits CAN Frame CRC delimiter 1 bit Extended Format, 2.0B Max frame length with bit stuffing = 150 bits Arbitration Field Control Field Data Field 32 bits 6 bits 0 to 64 bits SOF Identifier 11bits SRR IDE Identifier Ext. 18bits RTR r1 r2 DLC 4bits CRC 15bits ACK Field 2bits EOF 7bits Bit Stuffing No Bit Stuffing SOF = Start Of Frame SRR = Substitute Remote Request IDE = Identifier Extension Bit RTR = Remote Transmission Request DLC = Data Length Code CRC = Cyclic Redundancy Check ACK = Acknowledgement EOF = End Of Frame
CAN Frame 32 bits 6 bits 0 to 64 bits Arbitration Field Control Field CRC delimiter 1 bit Arbitration Field Control Field Data Field 32 bits 6 bits 0 to 64 bits SOF Identifier 11bits SRR IDE Identifier Ext. 18bits RTR r1 r2 DLC 4bits CRC 15bits ACK Field 2bits EOF 7bits
CAN Frame Message Structure 29 Bit Identifier DLC DATA FIELD 29 bits 0 to 8 bytes PRI PGN SA PRI= Priority 3 bits PGN = Parameter Group Number, 18 bits SA = Source Address, 8 bits
How do I start using CAN right now? SAE J1939 Defined by the automotive industry Standards defined for the Layers 1,2,3,4, and 7
ISO Layers according to SAE J1939 Application Layer SAE J1939/71 SAE J1939/73 Layer 7 Presentation Layer Layer 6 Session Layer Layer 5 Transport Layer Layer 4 SAE J1939/21 Network Layer SAE J1939/31 Layer 3 Data Link Layer Layer 2 SAE J1939/21 Physical Layer SAE J1939/11 SAE J1939/12 Layer 1
ISO Layers Used In EAMCS Application Layer Layer 7 Data Link Layer Layer 2 Physical Layer Layer 1
Physical Layer SAE J1939/11 – High Speed Bus Connection Differential signal transmission Shielded twisted pair bus lines and ground 250k bits/sec 30 nodes max. Bus length = 40m max. or 131 ft. max. SAE J1939/12 – Variant Bus Connection Bus constructed using active termination For bus load = 1 (Using 29bit ID and 8 data bytes per frame, approx. 135bits/message) At a bitrate of 250kbps 1850 messages per second
Node A (EAMCS) Node B (UQM Inverter) 120Ω 120Ω
Example MSCAN Timing
Cont. Example MSCAN Timing 16Tq = SYNC_SEG + PropagationDelaySeg + TimeSeg1 + TimeSeg2 SYNC_SEG = 1Tq PropagationDelaySeg = 2Tq (Determined by bus characteristics) Pick, TimeSeg2 = 5Tq TimeSeg1 = 8Tq This gives a SJW range 0…3 so, I picked 2 Once values are determined, then apply to MSCAN registers
Data Link Layer SAE J1939/21 29 Bit ID PRI PGN SA 28…26 25 24 23…16 15…8 7…0 r DP PF DA/GE PRI= Priority 3 bits PGN = Parameter Group Number, 18 bits r = Reserved Bit, always 0 or dominant DP = Data Page PF = PDU format, (Protocol Data Unit) DA = Destination Address GE = Group Extension SA = Source Address, 8 bits
Example: EAMCS Message sent to UQM Inverter 29 Bit ID PRI r DP PDU Dest. Addr Source Addr 28…26 25 24 23…16 15…8 7…0 0x06 0x04 0xEF 0x02 0x01 Priority Defined by SAE Reserved for future use Defined by SAE PDU Defined by SAE DA Defined by User SA Defined by User
Application Layer SAE J1939/71 Defines the bytes in the data field
SAE HANDBOOK DATA
Example: Parameter Group Definition Electric Drive State Transmission Repetition Rate: 100ms Data Length: 8 bytes Data Page: 0 PDU format: 239 PDU specific: DA Default Priority: 4 Byte Definitions 1 Command 0x10 2,3 Actual Speed 4 Torque 5 Voltage 6 Current 7,8 System Error
Cont. Example: Parameter Group Definition Byte Definitions 1 Command 0x10 2,3 Actual Speed 4 Torque 5 Voltage 6 Current 7,8 System Error Definitions Command Actual Speed Torque Voltage Current System Error Byte 1 Byte 2 Byte 3 Byte 4 Byte 5 Byte 6 Byte 7 Byte 8 Data Field
Cont. Example: Parameter Group Decoding Using MSCAN (The Easy Way) Define a struct typedef struct{ INT8U command; INT16U actual_speed; INT8U torque; INT8U voltage; INT8U current; INT16U system_error; }ELEC_DRIVE_STATE; Command Actual Speed (MSB) Actual Speed (LSB) Torque Voltage Current System Error (MSB) System Error (LSB) CANRXFG[4] D a t F i e l d Create an Instance ELEC_DRIVE_STATE elec_drive_data; Take advantage of Struct copying routines elec_drive_data = *(ELEC_DRIVE_STATE*)(CANRXFG + 4); Now access the data fields using the corresponding struct member outhexw(&elec_drive_data.actual_speed); /* Print the 16bit hex value */
References Motorola Documentation MSCAN Block Guide V02.14, S12MSCANV2.pdf Bosch Documentation CAN Specification Version 2.0, can2spec.pdf Reference Texts Konrad Etschberger,Controller Area Network. Weingarten, Germany: IXXAT Automation GmbH, 2001 1997 SAE Handbook, Volume 2 Parts and Components. Warrendale, PA: Society of Automotive Engineers, 1997