The LIN bus 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 bus 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, synchronization (sync), and identifier (ID). The response, which is transmitted by a slave task and can reside in either the master node or a slave node, 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 one to eight 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 broadcasts the identifier to the network, and only one slave responds with a data payload.
Master-to-slave communication is accomplished by a separate slave task 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 then publishes the appropriate frame header, and the internal slave task transmits its data payload to the bus.
Figure 2. LIN Message Frame
Every LIN frame begins with the break, which comprises 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.
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 rates to synchronize with the bus.
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 ID fields, verify their parities, and determine if they are publishers or subscribers for this particular identifier. The LIN bus provides a total of 64 IDs. IDs 0 to 59 are used for signal-carrying (data) frames, 60 and 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 six bits containing the raw ID and the upper two bits containing the parity.
|ID(1) ^ ID(3) ^ ID(4) ^ ID(5)
||ID(0) ^ ID(1) ^ ID(2) ^ ID(4)
Table 2. Parity Calculation Method
4. Data Bytes
The data bytes field is transmitted by the slave task in the response. This field contains from one to eight bytes of payload data bytes.
The checksum field is transmitted by the slave task in the response. The LIN bus defines the use of one of two checksum algorithms to calculate the value in the eight-bit checksum field. Classic checksum is calculated by summing the data bytes alone, and 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 is for use with LIN 2.0 slave nodes. It further specifies that IDs 60 through 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 through 63 always use classic checksum, regardless of the setting of the checksum attribute.
Figure 3 illustrates how a master task header and a slave task response combine to create a LIN full frame.
Figure 3. Creation of LIN Frames