What is LIN bus?
With can, why can there be Lin? What are the differences between can and Lin? What are the advantages of Lin?
Some of the LIN bus based content, the key points extracted, here to share with you. Here you may ask, “don’t we all have can bus? Where does this LIN bus come from? ” In fact, the reason is very simple, that is, can bus is too expensive! If can bus is used everywhere, the bus architecture cost of the whole vehicle will become very high! In some places, such as car body electronic accessories (such as windows, rear-view mirrors, headlights, car locks, etc.), we don’t need messages to be “high-speed” as transmitted on CAN bus! Major manufacturers have studied this LIN bus as soon as they hit the forehead! This paper focuses on: why can have Lin, the difference between can and Lin, what are the advantages of Lin?
1. What is LIN bus? Lin (local interconnect network) bus is a low-cost serial communication protocol based on UART / SCI (universal asynchronous transceiver / serial interface). Its target is the low-end communication between the nodes of the car body network module, which is mainly used for the serial communication between intelligent sensors and actuators, which is just the part not required by the bandwidth and function of CAN bus.
2. Can / LIN bus difference because Lin network does not exist independently in automobile, it is usually connected with upper can network to form Can-Lin gateway node.
2.1. The master-slave relationship of LIN bus. LIN bus adopts single line transmission mode, and applies single host and multiple slaves The bus level is generally 12V and the maximum transmission rate is 20kbps. Due to the limitation of physical layer, a Lin network can connect up to 16 nodes.
The bus task is responsible for:
Scheduling the transmission order of frames on the bus
Monitoring data, processing errors
As a standard clock reference (not asynchronous communication?)
Receive the bus wake-up command from the slave node
The slave task cannot directly send data to the bus. After receiving the frame header sent by the master node, it needs to judge according to the information contained in the frame header
Neither receive nor reply
The network consists of a master node and several slave nodes
Using LIN bus can greatly reduce the cost (both can and Lin need transceivers, but Lin belongs to the single wire system, which can be saved on the harness)
The transmission is deterministic and the propagation time can be calculated in advance
Lin has predictable EMC (electromagnetic compatibility) performance. In order to limit the strength of EMC, Lin protocol stipulates that the maximum transmission rate is 20kbps
LIN bus provides signal configuration, processing, identification and diagnosis functions (these are not provided by UART, but how is Lin implemented?)
3. Lin message frame structure Lin message frame includes two parts: header and response. The host is responsible for sending to the frame header; the slave is responsible for receiving the frame header and making analysis, and then deciding whether to send a response or receive a response or not.
The (host) frame header structure includes synchronization interval segment, synchronization segment, PID segment (protected ID) and the response part includes data segment and validation segment. Where “0” is the dominant level and “1” is the recessive level, which is similar to can bus. Implement “line and” on the bus: when at least one node of the bus sends explicit level, the bus presents explicit level; when all nodes send implicit level or do not send information, the bus presents implicit level, that is, explicit level plays a leading role.
3.1.1. Synchronization interval the synchronization interval is composed of at least 13 bits of dominant level, because all gaps in the frame or the bus remain recessive level when it is idle. So the synchronization interval can mark the beginning of a frame. The interval of synchronous interval is at least 1 bit recessive level.
3.1.2. The falling edge below Lin synchronization in synchronization section is the judgment mark, and byte 0x55 (01010101b) is used for synchronization. The slave node can not use high-precision clock, and the resulting deviation needs to be adjusted through the synchronization segment.
3.1.3. The first six bits of the protected ID in PID segment are called frame ID, which is called protected ID after adding two parity check codes. The value range of frame ID is from 0x00 to 0x3f, a total of 64 frames. The frame ID identifies the category and destination of the frame. The slave task will respond (receive / send / ignore) according to the frame header ID. The validity of P 0 and p 1 were as follows
LIN bus divides the message into signal carrying frame, diagnosis frame and reserved frame according to the frame ID number.
PS: slave response frame is a complete frame, which is different from “response” in frame structure (master node)!
3.1.4. Data segment data segment can contain 1-8 bytes, including two data types, signal and diagnostic messages. The signal is transmitted by the signal carrying frame, and the diagnosis message is transmitted by the diagnosis frame.
The protocol does not specify which part to display the information of data length code (which is different from can bus). The content and length of data are agreed in advance by the system designer according to the frame ID.
The data on the bus is broadcast and can be received by any node, but it is not useful for every node (same as can). Which node is responsible for publishing and answering depends on the software configuration of the application layer. Generally speaking, there is only one publishing node on the bus for the response in a frame, otherwise there will be an error. Event trigger frame exception, there may be 0, 1, multiple publishing nodes.
3.1.5. Validity and validity
The purpose of validation and segmentation is to validate the content of frame transmission. Validity is divided into standard validity and enhanced validity. The host node manages whether to use the standard or enhanced model, and the publishing node and the listening node judge which model to use according to the frame ID.
4. LIN bus waveform
5. Communication of LIN bus the figure above shows the communication mode of LIN bus. It can be seen that whenever the frame header is always released by the host node, when the host node wants to release data, the whole frame is sent by the host node. When the slave node wants to publish data, the frame header part is published by the host node, and the response part is published by the slave node In this way, other nodes can receive a complete message frame. It can be directly observed that the communication of LIN bus is initiated by the host node. As long as the configuration of each node is reasonably specified, there will be no bus conflict (conflict resolution schedule is used when event triggers frame conflict).
5.1. Unconditional frame an unconditional frame is a frame with a single publishing node, and its header will be unconditionally answered no matter whether the signal changes or not.
As shown in the figure above, in frame id = 0x30, the publishing node of the response part is slave node 1, and the listening node is the host node, which is used to report its own status to the host node; in frame id = 0x31, the response part is the host node, and the listening part is the slave node, which is used to send messages from the host node to the slave node; In frame id = 0x32, the sending node of response part is slave node 2, and the listening node is slave node 1. The communication between application and slave node.
5.2. Event trigger frame event trigger frame is a frame used by the master node to query whether the signal of each slave node changes in a frame gap. When there are multiple publishing nodes, the conflict is resolved through the conflict resolution schedule.
When the frequency of the slave node signal changes is low, the host task will take up a certain bandwidth to query each node information again and again. In order to reduce the bandwidth consumption, the concept of event triggered frame is introduced. Its main principle is: when the information state of the slave node does not change, the slave node can not respond to the frame header sent by the host; when there are multiple node information changes at the same time, the response event triggers the frame header, which will cause the bus conflict. When the host node detects a conflict, it will query the conflict resolution schedule to send unconditional frames to each node in turn (only one node can respond to the unconditional frame) to determine the information state of the slave node.
Multiple unconditional frames associated with event triggered frames need to meet the following five conditions:
The number of data bytes contained in the data segment is equal in length, using the same validation and type. The first byte of the data segment is the protected ID of the unconditional frame, so that we can know which unconditional frame the response is sent from, which is issued by different slave nodes and cannot be in the same schedule as the time triggered frame
5.2.1. Incidental frame incidental frame is the frame that the host node starts to send to the bus when its own signal changes in the same frame slot. When there are multiple associated response signals changing, arbitration is carried out by a pre-set priority. Similar to event triggered frames, incidental frames also define a group of unconditional frames. It is stipulated that occasional frames can only be published by host nodes.
There are three situations in the transmission of occasional frames
When no signal changes in the associated unconditional frame, the host does not need to send even the frame header.
When an associated unconditional frame signal changes, the frame is sent.
When a plurality of unconditional frames have signal changes, they are sent according to the priority specified in advance.
5.2.2. Diagnosis frame diagnosis frame includes host request frame and slave response frame, which is mainly used for configuration, identification and diagnosis. Host request frame id = 0x3c, the publishing node of response part is host node; slave response frame id = 0x3d, the publishing node of response part is slave node. The data segment is specified as 8 bytes, all of which adopt the standard and validation.
5.2.3. Reserved frame id = 0x3e and 0x3f for future expansion.
5.3. Schedule schedule is the schedule of frames, which specifies the transmission order and time of frames on the bus. The schedule is located in the host node, and the host tasks are scheduled according to the needs of the application. There can be multiple schedules. Generally, when it’s time for a schedule to be executed, it starts from the entry of the schedule. When it’s time for the last frame of the schedule, if no new schedule is started, it returns to the first frame of the current schedule to start execution; It is also possible to interrupt the execution of a schedule and jump to another schedule before returning. For example, the event trigger frame is a typical example.
6. Implementation of state machine 6.1. Host state machine
6.2. The slave state machine is responsible for publishing or answering the response state of frames, including connecting two state machines: synchronization interval and synchronization segment checker, and frame processor.
6.3. Slave task state machine
Vernacular LIN bus
Physically, there is only one wire, and all the associated nodes are connected. There is only one master device and N multiple slave devices. The contents of each node to communicate are numbered in advance.
It’s like a party with one microphone, one host, n guests, and each topic has a number.
The order of expression is like this,
Before the party starts, everyone sleeps, sleeps, idles
Host, put the microphone on the drum, knock – stop – knock – stop – Knock stop-
So everyone was woken up and the party began
The party is all about conversation and repetition of the following steps
T1 the host shut down the microphone for a while
T2 host tried the topic, huhuhuhuhuhu — LIN bus synchronization
T3 host said, the following is the speech by the PID number of people – LIN bus PID
T4 people with PID begin to talk about the data of d0, D1, D2, D3, D4, D5, D6, D7 LIN bus
T5 has the PID person, then said like this – LIN bus CRC
After repeating this many times, the host
E1 host shut down the microphone for a while
E2 host tried the topic, whoosh whoosh – LIN bus synchronization
E3 host said, the following is the PID number is the sleep of the speech (on his own) – LIN bus PID
E4 people with PID begin to talk about go to sleep – LIN bus data, up to 8 bytes
E5 PID people, and then said that this is it – LIN bus CRC
In this way, the party is over, everyone sleep sleep rest rest
Funny end, a little bit of keywords
. Physically, there is only one line, multi node transmission, and no conflict detection. What should I do? Master equipment scheduling
. How about the speed? Compared with can, more than 10 Kbps is not high, but the connected device has such a large amount of information, just right
. How about the price? It’s cheap. A physical tracer, a CPU with UART and some software. It’s done
. How about the safety factor, PID with verification, data with CRC verification, can find the error, report
. How about the scalability? Use two specific PIDs as the data link layer and create a large packet TP layer on the upper layer,
The TP layer supports a diagnostic function, so it can do something else
. How about the compatibility of different versions? If the main device version is high, it can be managed and coordinated well
On the contrary, the slave device version is high, which is a bit wasteful