The CAN Bus
The CAN Bus
in automotive applications. It has been found to be very useful in a wide variety distributed industrial systems as it has the following characteristics:
y y y y y y y
Uses a single terminated twisted pair cable Is multi master Maximum Signal frequency used is 1 Mbit/sec Length is typically 40M at 1Mbit/sec up to 10KM at 5Kbits/sec Has high reliability with extensive error checking Typical maximum data rate achievable is 40KBytes/sec Maximum latency of high priority message <120 sec at 1Mbit/sec
CAN is unusual in that the entities on the network, called nodes, are not given specific addresses. Instead, it is the messages themselves that have an identifier which also determines the messages' priority. Nodes then depending on their function transmit specific messages and look for specific message. For this reason there is no theoretical limit to the number of nodes although in practice it is ~64. Two specifications are in use:
y
2.0A sometimes known as Basic or Standard CAN with 11 bit message identifiers which was originally specified to operated at a maximum frequency of 250Kbit/sec ISO11519. 2.0B known as Full CAN or extended frame CAN with 29 bit message identifier which can be used at up to 1Mbit/sec - ISO 11898.
Signal Characteristics
CAN may be implemented over a number of physical media so long as the drivers are opencollector and each node can hear itself and others while transmitting (this is necessary for its message priority and error handling mechanisms). The most common media is a twisted pair 5v differential signal which will allow operations in high noise environments and with the right drivers will work even if one of the wires is open circuit. A number of transceiver chips are available the most popular probably being the Philips 82C251 as well as the TJA1040. When running Full CAN (ISO 11898-2) at its higher speeds it is necessary to terminate the bus at both ends with 120 Ohms. The resistors are not only there to prevent reflections but also to unload the open collector transceiver drivers. We recommend that you terminate the bus correctly in all circumstances.
Message formats
The CAN protocol uses a modified version of the Carrier Sense Multiple Access/Collision Avoidance (CSMA/CA) technique used on Ethernet. Should two messages determine that they are both trying to send at the same time then instead of both backing off and re-trying later as is done with Ethernet, in the CAN scheme, the transmitters detect which message has the highest priority and only the lower priority message gets delayed. This means that a high priority message is sure of getting through.
Data Frames
These are the normal message frames used to carry data. They contain the following fields -this is a simplified description as the controller takes care of the detail which is only of interest to those designing controllers (who should consult the spec) Start of frame (SOF) Message Identifier (MID) the Lower the value the Higher the priority of the message its length is either 11 or 29 bits long depending on the standard being used Remote Transmission Request (RTR) = 0 ----- see "Remote Frames" para below for non zero value Control field (CONTROL) this specifies the number of bytes of data to follow (0-8) Data Field (DATA) length 0 to 8 bytes CRC field containing a fifteen bit cyclic redundancy check code Acknowledge field (ACK) an empty slot which will be filled by any and every node that receives the frame it does NOT say that the node you intended the data for got it, just that at least one node on the whole network got it. End of Frame (EOF) The way in which message collision is avoided is that each node as it transmits its MID looks on the bus to see what everyone else is seeing. If it is in conflict with a higher priority message identifier (one with a lower number) then the higher priority messages bit will hold the signal down (a zero bit is said to be dominant) and the lower priority node will stop transmitting.
If you are writing diagnostic code and wish to not "exist" on the network as a node, just to spy on what is happening, then you will need to ensure that the interface you use can be set to a mode where it does not automatically set the ACK bit. The Peak interfaces and their Explorer diagnostic package can be set into such a mode.
Remote Frames
These are frames that are used to request that a particular message be put on the network - of course a node somewhere on the network has to be set up to recognise the request, get the data and put out a Message frame. This mechanism is used in polled networks. The fields are .... Start of frame (SOF) Message Identifier (MID) either 11 or 29 bits long depending on the chosen mode. Remote Transmission Request (RTR) = 1 Control field (CTRL) this specifies the number of bytes of data expected to be returned (0-8). CRC field containing a fifteen bit cyclic redundancy check code. Acknowledge field (ACK) an empty slot which will be filled by any and every node that receives the frame it does NOT say that the node you intended the data for got it, just that at least one node on the whole network got it. End of Frame (EOF)
Error checking
CAN is a very reliable system with multiple error checks Stuffing error - a transmitting node inserts a high after five consecutive low bits (and a low after five consecutive high). A receiving node that detects violation will flag a bit stuffing error. Bit error - A transmitting node always reads back the message as it is sending. If it detects a different bit value on the bus than the one it sent, and the bit is not part of the arbitration field or in the acknowledgement field, an error is detected. Checksum error - each receiving node checks CAN messages for checksum errors. Frame error - There are certain predefined bit values that must be transmitted at certain points within any CAN Message Frame. If a receiver detects an invalid bit in one of these positions a Form Error (sometimes also known as a Format Error) will be flagged. Acknowledgement Error - If a transmitter determines that a message has not been ACKnowledged then an ACK Error is flagged.