CAN Communication using Microcontrollers

Updated on 2017/06/20 00:46

Syllabus

Concept of CAN based communication using microcontrollers

CAN (Controller Area Network)

  • It is extensively used in automotive but it has found applications everywhere.
    • CAN controller
    • CAN controller 2.0A -> 11bits ID
    • CAN controller 2.0 B -> 29bits ID
    • CAN FD -> flexible Data Rate
  • Look after the all features of CAN protocol with almost no intervention by host processor.
  • Need to configure the controller by writing to its registers, write data to controller.

Features of CAN

  • 11 or 29 bit Identification & from 0 to 8 bytes .
  • Peer to peer network. (Every node can see all messages from all other nodes but it can’t see its own)
  • Nodes are easy to add.( just two wires + ground)
  • Higher priority messages are sent first depending on the value of ID.(Lower ID has higher priority)
  • Automatic retransmission of defective frames.
  • Speed (10kbps to 1mbps)
  • Twisted differential pair provides excellent noise immunity & bus faults protection.
  • CAN system works with ground connection of different DC levels.
  • Multi-master
  • Inexpensive (cheap, good, fast )
  • Reliable & Robust

CANBUS speed

125 kbpsLow speed  500 m
1 mbpsHigh speed40 m
15 mbpsFlexible Data Rate10 m
  • CAN system layout or physical configuration main backbone
  • Main backbones & drops are comprised of a twisted pair of wires

CAN Physical Configuration

can_physical_configuration.jpg

CAN Signals

can_signal.jpg

The CAN specifications use the terms:

  • "dominant" bits = logic 0
  • "recessive" bits = logic 1 

The idle state is represented by the recessive level (“1”).

Note: If one node transmits a dominant bit and another node transmits a recessive bit then there is a collision and the dominant bit "wins".

CAN Frame

can_frame.jpg

CAN Frame

Details of the CAN Frame:

  • Start-of-frame bit: The start of a message frame is signaled by a dominant start-of-frame bit
  • 11-bit Message ID or 29-bit Message ID
  • Remote Transmission Request (RTR) bit: It is only set if the message is a data request frame (as opposed to a data frame)., a node may request the transmission of a specific message by another node in the system.
  • Data Length Code (DLC): It indicates the number of bytes of data transmitted. The data field can contain from zero to eight bytes of data, and is followed by the
  • 16-bit CRC field: containing a 15-bit cyclic redundancy check code which is used by the receiving node to detect errors, and a recessive delimiter bit.
  • The ACKnowledge field has two bits:
    • The first is the ACK Slot which is transmitted as a recessive bit, but will be overwritten with a dominant bit by any node that successfully receives the transmitted message.
    • The second bit is a recessive delimiter bit.
  • The end-of-frame field consists of seven recessive bits, and signals that error-free transmission of the message has been completed.
  • Intermission field consisting of three recessive bits, after which the bus may be considered to be free for use. Idle time on the bus may be of any length, including zero

IDE: Identifier Extensions

  • if IDE = 0 , then the ID is 11 bits
  • if IDE = 1, then the ID is 29 bits

ID: Identifier (11 or 29 bits as set by IDE field)
This port of CAN frame sets priority.

DLC: Data length code (4 - bits)
Specifies number of data bytes in the frame from 0 to 8.
Data bytes: 0 to 8 bytes

ID: Identifier (11 or 29 bits)
Used as a node address or to identify requests & responses.

  • 11-bits ID :- Standard CAN ID
  • 29-bits ID :- Extended CAN ID

ID0: Highest Priority

Data length

Data transmitted with CAN frame
0 0000 bytes
0 0011 bytes
0 0102 bytes
0 0113 bytes
0 1004 bytes
0 1015 bytes
0 1106 bytes
0 1117 bytes
1 0008 bytes

Applications of CANBUS

  • Automotive
  • Industrial machinery
  • Marine Applications
  • Military tanks
  • Medical instruments
  • Elevators

CAN Controller Architecture and Operation

Block diagram

can_controller.jpg

Block diagram of the NXP CAN controller

In block diagram the main points of all CAN controllers are:

  1. I/O Pins: These connect to the CAN transceiver chip pins RD1 and TD1 as already described.
  2. Bitstream Converters: CAN is a serial bus while the processor is parallel.  Conversion happens here.
  3. TXB buffer: The messages to be transmitted are written here.  ID, IDE, DLC and data (if any) go here.
  4. Acceptance Filter: This passes only specified messages to the processor via the FIFOs.  By default at RESET, these filters pass all messages to the FIFOs.  Your software must configure and enable them to filter messages.
  5. RXB Receive Buffer: Each buffer holds 1 CAN message.  They provide a buffering system to the processor.
  6. Control, Status, Bit Timing and Error management registers:  Your software must configure these registers, usually at initialization. Various flags and switches are found here. Examples are set CAN speed, request transmission, manage receive messages, enable interrupts and obtain diagnostic information

References

Tags:
Created by Admin on 2017/04/07 10:03