Riding the LIN Bus

The LIN bus is a low cost alternative to CAN
illustration: freeimages.com

Recently, we were asked to work on a customer project involving LIN (Local Interconnect Network) communication.  Our team has quite a bit of experience working with CAN (Controller Area Network) systems, so it was interesting to learn the intricacies of LIN as a lower cost alternative to CAN.

LIN was developed by a group of automotive companies to make it easier to get data from controls and sensors to and from controlling computers.  Automotive manufacturers have been using LIN networks for years for things like power locks and engine sensors. The manufacturer we work with is using LIN for some in-cab controls. Controls from simple things like lights and turn signals to more complicated things like hydraulic levers are using LIN to get the information from the control to the control computer. This is an ideal use for this technology.

The way that LIN networks work is based on one node (electronic device) on the LIN bus being in charge and the remaining nodes obeying its commands. The controlling node is referred to as the master and the other nodes are called slaves. In the case of the equipment that we were dealing with, the computer controller is the master and the operator controls (and in a few cases, sensors) are the slaves. This is typical. Each LIN bus can have only one master but up to 16 slaves.

The master does most of the work. It schedules commands, sends commands to, and receives responses from, each of the other nodes. Most of those commands are requests for the slave nodes’ data. Each message is called a frame. Each frame has two parts: a header and a response.

The header is like the address on a postcard. As each postcard address contains specific data in specific locations, this is true with LIN frame headers as well. Each header has: a Break, Sync, Space, Identifier, and Response Space. The Break is used to give all of the listening nodes time to know that this will be the beginning of a new message. The Sync is a byte with a value of 0x55 (binary 01010101) that gives each node a chance to detect the clock frequency. The Space or Inter-Byte Space is optional and if used is between the Break and Sync, between the Sync and Identifier, and between each data byte. The Identifier defines one command. It can be to one slave or several (or in rare cases even to the master itself).  The Response Space is the gap between the Identifier and the Data.

The Response is the data sent back from the slave node. It has two parts: Data and Checksum. Data from each node is a predefined 0 to 8 bytes of information. The Checksum is a single data byte that is calculated from either the Data or the Identifier and the Data. On a slave, typically the hardware used takes care of everything but the Data.

We learned a lot about the inner workings of LIN during the course of development, but that is not necessarily the important part. Because the hardware and system drivers handle the lower levels of networking, the software developer’s role is to use the LIN bus to get the information and use it to control the various aspects of the equipment. The details of the bus itself are necessary to know, but the information passed through the bus is more important.  Just like a postcard, you have to know how to address and write one, but your message is the important part.