Skip to content

xyderos/can-bus-notes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Can Bus Notes

The vehicle is the human body, CAN is the nervous system, the nodes are the organs

In short

  • Based on multi master broadcast, the message is not one on one, rather broadcast it to the whole network

  • A node can either send or receive, cannot do both together

  • There is the notion of important messages

    • via a priority scheme based on the ID of each node

    • The lower the ID, the higher the priority

  • Ability to detect signal errors

    • First version of CAN could disconnect faulty nodes
  • Fully distributed

    • Information can be obtained from each node
  • No complex wiring, single lined

  • No security

  • Uses serial port

  • Either control actuators or give feedback

  • Transmits serially into the bus

  • If the bus is idle (TTL= 5V), any node can begin transmitting

Two early hardware versions

  • Basic CAN

    • Basic CAN utilized a single message buffer

    • Standard CAN controllers had up to 16 message buffers

      • Used for both reading and writing
    • The received message goes through acceptance filtering

      • Decide whether to accept or ignore it

      • This is happening on the software level

      • Bit masking is used to ignore messages based on specific identifiers

        • Reduces software load on each node
  • Full CAN

    • Every message is accompanied with either 8 or 16 memory buffers

    • Hardware is performing message filtering

    • Buffers

      • Specific buffers are made to accept specific identifiers

      • Allows more processing time per message

      • Better data consistency because of the one on one buffer to message

    • Limited in the amount of frames that can be received

    • More computational chips per node

  • Now

    • Manufacturers combine the frame handling and acceptance filtering strengths of both
  • An arising issue was the bandwidth CAN offered

    • CAN data link layer had to be updated and CAN FD arose

      • Fixed Bandwidth, 12 Mbit/sec

      • Fixed payload size, 64 bytes

      • As long as there are nodes that do not need to be synchronized, the bandwidth can be increased

Each node has

  1. Host processor

    • Decides what received messages mean and which messages to transmit itself

    • Sensors or actuators can be connected to the processor

  2. CAN controller

    • Stores the bits in a buffer until a whole message is available when receiving

    • The host processor stores the bits in the CAN CONTROLLER and transmits them serially into the bus

  3. Transceiver

    • Adapts signal levels from the bus to level the CAN controller expects

    • Protects the CAN controller

    • Converts the received from the CAN controller signals to a signal that should be sent to the bus

Data transmission

  • If two nodes begin transmitting at the same time, the highest priority will overwrite

  • If one node transmits a dominant bit (0) and another one a recessive bit (1)

    • Dominant wins
  • If any node transmits a high voltage, everyone will see it

    • Asserts priority

    • No delay

  • The lower priority message attempts to re-transmits six bit clocks after the end of the dominant message

  • When we talk about a differential bus

    • The principles of Carrier Sense Multiple Access/Bitwise Arbitration are applied

      • If two nodes start transmitting on the same time, we need to decide which one will go first
    • During arbitration each transmitting node monitors the bus state

    • Compares the received bit with the transmitted bit

      • If a dominant bit is received when a recessive bit is transmitted

        • The node stops transmitting
    • Arbitration is happening during the transmission of the ID field

      • When each node starts transmitting

        • At the same time sends an ID with a dominant 0

          • In the high bit
    • As soon as their ID has higher priority

      • They will send 1 and receive 0

        • Time to back off
    • At the end of ID transmission, all nodes but 1 will back off

      • Will send the message

Example of the priority scheme

Assume 11 bit CAN IDs transmit at the same time

  • 0x000000011111

  • 0x000000100000

  1. Both transmit the first 6 zeroes

    No arbitration is being made so far

  2. When the 7th bit is transmitted

    1. The node with id of 16 transmits 1 for its ID (recessive)

    2. The node with id of 15 transmits 0 for its ID (dominant)

  3. The node with ID of 16 realizes that it lost its arbitration

  4. Allows node with ID of 15 to go ahead

Timing

  • Each node has its own clock

  • No clock is sent during data transmission

  • Synchronization happens by dividing each bit of the frame into a number of segments

    • Synchronization

    • Propagation

    • Phase 1

    • Phase 2

  • Length of each segment depends on the network and node conditions

  • The sample point usually falls into either phase 1 or phase 2

Messages

  • Hardware

    • Two wires

      • CAN High

      • CAN Low

      • Both carry messages from nodes and connect the BUS terminators at each end

        • The bus terminators are powered and grounded to create a difference of voltage providing the functionality of serial network operation

        • Twisted quad cabling configuration

          • Both CAN High and CAN Low wires are twisted

            • Reduces electromagnetic interference and thus less errors
  • A maximum of 30 nodes can be attached to a single section of the BUS

  • A maximum of 254 nodes connected to the BUS in general

    • Since the data signal is 8 bytes

      • Address 255 is null

      • Address 256 indicates a broadcast to all the nodes in the network

    • Broadcasting each message to each node

      • Reduces complex wiring

      • Local nodes implement the filters mentioned above

        • Receive specific messages, the ones they are interested to
  • Format

    • Start of Frame (SoF)

      • 1 bit dominant 0

        • Signals that the node is about to send

          • Alert the other nodes to be ready to listen
    • CAN Identifier

      • Contain information about the sender

        • Message priority

          • The smaller value the higher priority

          • Source address

      • CAN 2.0 is 11 bits

      • Later versions are 29 bits extended

        • 11 bits for the first part of the unique identifier

          • Also represents message priority

          • Substitute remote request

            • Optional

            • Must be 1

          • Identifier Extension Bit (IDE)

            • Optional

            • Must be 1

          • 18 bits are the second part of the data

            • Also represents priority
    • Remote Transmission Request (RTR)

      • 1 bit value indicating whether or not we are receiving or sending a message to a specific node
    • Control

      • 6 bits in length

        • First bit indicates if we use the 11 bit ID or the 29 bit ID

        • The second one is reserved

        • 4 of which denote the size of the message to be transmitted

          • 0 to 8 bytes
    • Data

      • Contains all the CAN signals
    • CRC

      • 15 bits that checks data integrity

      • 1 bit is recessive (1)

    • Acknowledgement (ACK)

      • 2 bit which indicates that the CRC found no issues

      • First bit is 1 if

        • The transmitter sends 1

        • Any receiver can assert dominant

      • Second bit is 1

    • End of Frame (EoF)

      • 7 bit cap on that signals the end of transmission

        • Acts as padding?

        • Must be 1

The actual CAN Frame consists of two parts

  • CAN ID

  • Data

Types of messages

  • Data frame

    • Data transmission message
  • Error frame

    • A message that violates CAN formatting

      • Signals an error in data transfer
    • The original sender destroys a frame with an error message

      • Then re-transmits
    • All controllers are listening for potential errors

      • The one who found it, transmits an error flag

        • Halting the traffic
    • The rest of the nodes receive the error

      • Active error flag

        • Six dominant bits

          • Detected an error in state ERROR-ACTIVE
      • Passive error flag

        • Six recessive bits

          • Detected in error state ERROR-PASSIVE
      • Transmit 8 recessive bits (error flag)

        • Aka Error Delimiter Flag (EDF)

          • Clear the bus before taking action

            • The most common response is to disregard the erroneous message
    • Each node keeps a record of detected errors

      • Via two registers

        • The ones the node itself was responsible in the Transmit Error Counter

          • When the transmitter detects an error in a message, it increments the counter

            • Faster rate than the receiving nodes since the transmitter emits system faults in most cases

            • When you exceed a limit, the node goes into a Passive Error State where it will not broadcast messages to the bus.

            • When you exceed a second limit, it goes into a BUS OFF STATE where it is removed from the network traffic

            • With this logic, you can both detect errors and limit them in the network

        • The ones other nodes we responsible in the Receiver Error Counter

  • Remote frame

    • Request data

    • The RTR bit is transmitted as a dominant bit in the data frame

    • In the remote frame there is no data payload

  • Overload frame

    • Signals that a node is overloaded

      • First bit time during an intermission
    • Detection of a dominant bit during intermission

      • One bit after the dominant bit

        • Trigger delays
    • Two bit fields

      • Overload flag

        • The overload flag has 6 dominant bits

          • Active Error Flag

            • Destroys the form of the intermission field

            • All other stations detect the overload condition and thus start transmitting the overload

      • Overload delimiter

        • 8 recessive bits

          • Same form as the error frame

OSI

  • Physical layer

    • Encoding/Decoding

    • Synchronization

    • Timing

  • Data link layer

    • Acceptance filtering

    • Overload notification

    • Recovery management

    • Data encapsulation

    • Frame coding (stuffing/destuffing)

    • Error handling

    • Acknowledgements

  • Application layer

    Network management which directs when or how CAN nodes are on or off are included in the application layer

  • Node supervision is another functionality of the network management

    • Detect nodes that are missing due to faulty condition, power loss

      • In order to detect which nodes are not transmitting messages periodically

        • A client/server scheme is used

          • The server sends a message periodically to a monitoring client

          • If an interruption occurs based on a time limit, we have an off-line status for this node

  • Break up data for transmission and reassembling them on the receiving end

    • Usually this is part of the transport layer

      • Eg CANOpen, DeviceNet

Typically layers 3 to 6 (network, transport, session and presentation) are not explicitly implemented

  • It is usually partially implemented in the application layer eg network and transport

    • Will not sacrifice functionality

A thing to keep in mind is that, there might and should not be a flat structure within the nodes

  • The subsystems approach should be adopted since it increases capabilities and functionality in a small sub module

  • A star serial bus configuration is usually implemented

  • High Speed CAN:

    • The CAN HIGH and CAN LOW communicate with speeds up to 1 Mbps

      • Eg safety critical systems

      • Wired in a linear serial bus configuration

  • Low Speed CAN:

    • 125 Kbps
  • Typically there are custom pre-made CAN protocol stacks

    • CAN Application layer, NMEA2000, CAN FD.
  • The need to be identified

    • Every node is assigned an ID

    • This dictates priority between messages that arrived at the same time

Logging/Metrics

  • Do not measure data directly with instruments

    • Approximate results can be calculated based on the theoretical relationships

      • Between specific metrics and other parameters that are measured by sensors

        • Usually found in plug and play tools

          • While the estimates are inexact, one can obtain very accurate measurements

            • Firstly calibrate the internal sensors with precision to external sensors

              • This allows a reduction in the number of the sensors and the overall cost in general

Based on all the factors above, we can extract the result that due to its inter connectivity and decentralized communication, we have an efficient communication pathway and thus an invaluable asset in real time data collection

ISO 11898

  • Data link layer

  • Physical layer for High Speed medium attachment (HS-PMA)

  • Physical layer for fault tolerant, low speed medium dependent interface

  • ISO 11898-1

    • Two format options

      • Classical CAN Frame format

        • 1 Mbps

        • 8 bytes per frame

      • CAN Flexible Data Rate Format

  • ISO11898-2

    • HS-PMA specifications

      • Multiplexing data for immediate use

      • Low power mode and selective wake up mode

  • ISO11898-3

    • Set up of the data exchange between nodes

J1939

Specializes how data are exchanged in heavy duty vehicles

  • Cross companies protocol

  • Consistent data logging

  • 250 Kbps first version

  • 500 Kbps + 29 bits used for the ID

Message extensions

  • 11 bits start

  • 18 bits PGN (Parameter Group Number)

    • Function specific frame

    • Provides more detail about the message content

    • 0x00FF00 to 0x00FFFF are reserved for business logic use

  • The message parameters are identified by Suspect Parameter Numbers

    • Specific SPNs correlate to specific PGNs

      • Their encoded data including

        • Bit start

        • Total length

        • Scale

        • Offset

        • Units

      • Physical value = offset + scale * raw value in decimal

  • Request via a Remote frame

    • Eg for diagnostics via a CAN data logger

      • PGN 59904

        • 3 bytes of data, request the specific PGN

        • Priority is 6

  • Multi packets are available also

    • More than 8 bytes

J1939 transport protocol

  • Broadcast Announce Message (BAM) message

    • Goes to the entire network

      • A possible structure of a BAM message

        • 0x20, 1st byte, control byte, BAM

        • 0x2700, 2nd-3rd byte, size of message in bytes

        • 0x06, 4th byte, number of packets

        • 0xFF, 5th byte, reserved

        • 0x00FEE3, 6 to 8th byte, PGN indicated

      • Specifies

        • PGN

        • Data frames to be sent

        • Length

        • Max 255 frames of data

  • Data transfer

    • A possible data transfer

      • 0x01, 1st byte, specifies the sequence number

      • Rest is just data

    • Specifies

      • Specifies the sequence number as a byte

      • 7 bytes of data

      • Last frame has the remaining data plus recessive bits as padding

  • Connection mode

    • Intended for a specific device

A lot of PGNs are available only by polling

OBD2

Essentially, this is the vehicle's self diagnostic system

  • Support a broad range of standard Parameter IDs

Q : How to log these kind of data?

A :

  1. Connect the OBD2 Logger

  2. Request for frames

  3. Get the response frames

  4. Decode raw data

OBD2 Frame structure

  • CAN ID

    • 11 bits, distinguish between request and response

      • 0X7DF for request

      • 0X7F8-0X7FF for response

      • For the 29 bit identifier, we use 0x18DB33F1 as a request

      • And we receive Ox18DAF100 to 0x18DAF1FF

  • Length of bytes

    • 03 to 06
  • Mode

    • Between 01 and 0A

    • Responses replace the 0 with a 4

    • Eg 01 to request current data

    • Different modes that we can operate from 01 to 10

      1. Show current data

      2. Show frozen data

      3. Show stored Diagnostic Trouble Codes (DTCs)

      4. Clear DTCs and stored values

      5. Test results for oxygen sensors

      6. Test results for system monitoring

      7. Show pending DTCs

      8. Control operation of on board systems

      9. Request vehicle information

      10. Permanent DTCs

  • PID

    • For each mode there is a set of specific PIDs

      • Eg 0D for the vehicle speed
    • A-B-C-D

      • Usually data bytes, need to be converted before used
  • There is another slot but is unused