LIN Frame Format

NI-CAN

LIN Frame Format

LIN is a polled bus with a single master device and one or more slave devices. The master device contains both a master task and a slave task. Each slave device contains only a slave task. Communication over the LIN is controlled entirely by the master task in the master device.

The basic unit of transfer on the LIN bus is the frame, which is divided into a header and a response. The header is always transmitted by the master node and consists of three distinct fields: the Break, the Synchronization Field (Sync), and Identifier Field (ID). The response is transmitted by a slave task (which can reside in either the master node or a slave node) and consists of a data payload and a checksum.

Normally, the master task polls each slave task in a loop by transmitting a header, which consists of a Break-Sync-ID sequence. Prior to starting the LIN, each slave task is configured to either publish data to the bus or subscribe to data in response to each received header ID. Upon receiving the header, each slave task verifies ID parity and then checks the ID to determine whether it needs to publish or subscribe. If the slave task needs to publish a response, it transmits 1-8 data bytes to the bus followed by a checksum byte. If the slave task needs to subscribe, it reads the data payload and checksum byte from the bus and takes appropriate internal action. For standard slave-to-master communication, the master will broadcast the identifier to the network, and one and only one slave will respond with a data payload.

Master-to-slave communication is accomplished by a separate slave task which exists in the master node. This task self-receives all data published to the bus and responds as if it were an independent slave node. To transmit data bytes, the master must first update its internal slave task’s response with the data values it wants to transmit. The master would then publish the appropriate frame header and the internal slave task would transmit its data payload to the bus.

Break

Every LIN frame begins with the Break, comprised of 13 dominant bits (nominal) followed by a break delimiter of one bit (nominal) recessive. This serves as a start-of-frame notice to all nodes on the bus.

Sync

The Sync field is the second field transmitted by the master task in the header. Sync is defined as the character x55. The Sync field allows slave devices that perform automatic baud rate detection to measure the period of the baud rate and adjust their internal baud rate to synchronize with the bus.

ID

The ID field is the final field transmitted by the master task in the header. This field provides identification for each message on the network and ultimately determines which nodes in the network receive or respond to each transmission. All slave tasks continually listen for Identifier Fields, verify their parity and determine if they are publishers or subscribers for this particular identifier. LIN provides a total of 64 IDs. IDs 0-59 are used for signal-carrying (data) frames, 60-61 are used to carry diagnostic data, 62 is reserved for user-defined extensions, and 63 is reserved for future protocol enhancements. The ID is transmitted over the bus as one protected ID byte, with the lower 6 bits containing the raw ID and the upper two bits containing the parity.

The following figure shows how parity is calculated using the raw ID, and how the protected ID is formed from the combination of the parity bits and raw ID.

Protected ID(7:6) Protected ID(5:0)
P(1) P(0) ID(5:0)
¬ ID(1) Å ID(3) Å ID(4) Å ID(5) ID(0) Å ID(1) Å ID(2) Å ID(4) 0–63

Parity Calculation Method

Data Bytes

The Data Bytes field is transmitted by the slave task in the response. This field contains from 1 to 8 bytes of payload data bytes.

Checksum

The Checksum field is transmitted by the slave task in the response. LIN defines the use of one of two checksum algorithms to calculate the value in the 8-bit checksum field. Classic checksum is calculated by summing the data bytes alone, while Enhanced checksum is calculated by summing the data bytes and the protected ID.

The LIN 2.0 Specification defines the checksum calculation process as the summing of all values and subtraction of 255 every time the sum is greater than or equal to 256 (unlike modulo-255 or modulo-256). Per the LIN 2.0 Specification, classic checksum is for use with LIN 1.3 slave nodes and enhanced checksum with LIN 2.0 slave nodes. It further specifies that IDs 60–63 shall always use classic checksum. The NI LIN interface provides an attribute to set the checksum type to classic or enhanced. The default setting is classic. Per the LIN 2.0 Specification, IDs 60–63 always use classic checksum, regardless of the setting of the checksum attribute.

Creation of LIN Full Frames