CAN and LIN Overview
This topic provides an overview of CAN and LIN concepts.
In the past few decades, the need for improvements in automotive technology has led to increased use of electronic control systems for functions such as engine timing, anti-lock brake systems, and distributorless ignition. With conventional wiring, data is exchanged in these systems using dedicated signal lines. As the complexity and number of devices has increased, using dedicated signal lines has become increasingly difficult and expensive. To overcome the limitations of conventional automotive wiring, Bosch developed the Controller Area Network (CAN) in the mid-1980s. Using CAN, devices (controllers, sensors, and actuators) are connected on a common serial bus.
As CAN implementations increased in the automotive industry, CAN was standardized internationally as ISO 11898.
CAN Data Frame
The data frame is the fundamental unit of data transfer on a CAN network. The following figure shows a simplified view of the CAN data frame.
When multiple CAN devices transmit a frame at the same time, the identifier (ID) resolves the collision. The highest priority ID continues, and the lower priority IDs retry immediately afterward. The ISO 11898 CAN standard specifies two ID formats: the standard format of 11 bits and the extended format of 29 bits.
The ID is followed by a data length code that specifies the number of data bytes in the frame. The length ranges from 0 to 8 data bytes. The ID value determines the meaning of the data bytes.
CAN Remote Frame
In addition to the data frame, the CAN standard specifies the remote frame. The remote frame includes the ID, but no data bytes. A CAN device transmits the remote frame to request that another device transmit the associated data frame for the ID. In other words, the remote frame provides a mechanism to poll for data.
The preceding information provides a simplified description of CAN frames. The CAN frame format includes many other fields, such as error checking and acknowledgement. For more detailed information on the ISO 11898 CAN standard, refer to Summary of the CAN Standard in the NI-CAN Help.
The LIN network uses a Master/Slave approach, comprised of a LIN Master and one or more LIN Slaves. The following figure shows the LIN message frame.
LIN Message Frame
The message header consists of a break used to identify the start of the frame, the sync field used by the slave node for clock synchronization, and an identifier. The identifier (ID) consists of a 6-bit message ID and a 2-bit parity field. The ID denotes a specific message address, but not the destination. Upon reception and interpretation of the ID one slave will begin the message response. The message response consists of 1-8 data bytes of data and an 8-bit checksum.
The sequencing of message frames is controlled by the master and is fixed in a schedule. The schedule may be changed as needed.
The proceeding information provides a simplified description of the LIN message frame. For more details on the LIN message frame and on the LIN specification, refer to Summary of the LIN Standard in the NI-CAN Help.
NI-CAN Software Overview
The NI-CAN software provides full-featured Application Programming Interfaces (APIs), plus tools for configuration and analysis within National Instruments Measurement & Automation Explorer (MAX). You can use the NI-CAN APIs to develop applications that are customized to your test and simulation requirements for your CAN and LIN hardware.
Frame API for CAN and LIN
The frame is the fundamental unit of data transfer on a CAN or LIN network. The NI-CAN Frame API provides a set of functions to write and read CAN or LIN frames. Within the Frame API, the data bytes of each frame are not interpreted, but are transferred in their raw format. For example, you can transmit a CAN data frame by calling a write function with the ID, length, and array of data bytes. For more information, refer to the NI-CAN Help at Help»Help Topics»NI-CAN»Hardware and Software Manual.
Channel API for CAN
A typical CAN data frame contains multiple values encoded as raw fields. The following figure shows an example set of fields for a 6-byte data frame.
Bytes 1 to 2 contain a CruiseCtrlSetSpeed field that represents a vehicle speed in kilometers per hour (km/h). Most CAN devices do not transmit values as floating-point units such as 115.6 km/h. Therefore, this field consists of a 16-bit unsigned integer in which each increment represents 0.0039 km/h. For example, if the field contains the value 25000, that represents (25000 * 0.0039) = 97.5 km/h.
Bytes 3 to 4 contain another unsigned integer Vehicle Speed that represents speed in km/h. Bytes 0 and 5 contain various Boolean fields for which 1 indicates "on" and 0 indicates "off."
When you use the NI-CAN Frame API to read CAN data frames, you must write code in your application to convert each raw field to physical units such as km/h. The NI-CAN Channel API enables you to specify this conversion information at configuration time instead of within your application. This configuration information can be imported from Vector CANdb files, or specified directly in MAX.
For each ID you read or write on the CAN network, you specify a number of fields. For each field, you specify its location in the frame, size in bits, and a formula to convert to/from floating-point units. In other words, you specify the meaning of various fields in each CAN data frame. In NI-CAN terminology, a data frame for which the individual fields are described is called a message.
In other National Instruments software products such as NI-DAQ and FieldPoint, an application reads or writes a floating-point value using a channel, which is typically converted to/from a raw value in the measurement hardware. The NI-CAN Channel API also uses the term channel to refer to floating-point values converted to/from raw fields in messages. In CAN products of other vendors, this concept is often referred to as a signal. When a CAN message is received, NI-CAN converts the raw fields into physical units, which you then obtain using the Channel API read function. When you call the Channel API write function, you provide floating-point values in physical units, which NI-CAN converts into raw fields and transmits as a CAN message.
For more information, refer to the NI-CAN Help at Help»Help Topics»NI-CAN»Hardware and Software Manual.