AN1278
APPLICATION NOTE
LIN (LOCAL INTERCONNECT NETWORK) SOLUTIONS
by Microcontroller Division Applications
INTRODUCTION
Many mechanical components in the automotive sector have been replaced or are now being replaced by intelligent mechatronical systems. A lot of wires are needed to connect these components. To reduce the amount of wires and to handle communications between these systems, many car manufacturers have created different bus systems that are incompatible with each other.
In order to have a standard sub-bus, car manufacturers in Europe have formed a consortium to define a new communications standard for the automotive sector. The new bus, called LIN bus, was invented to be used in simple switching applications like car seats, door locks, sun roofs, rain sensors, mirrors and so on.
The LIN bus is a sub-bus system based on a serial communications protocol. The bus is a single master / multiple slave bus that uses a single wire to transmit data.
To reduce costs, components can be driven without crystal or ceramic resonators. Time synchronization permits the correct transmission and reception of data. The system is based on a UART / SCI hardware interface that is common to most microcontrollers.
The bus detects defective nodes in the network. Data checksum and parity check guarantee safety and error detection.
As a long-standing partner to the automotive industry, STMicroelectronics offers a complete range of LIN silicon products: slave and master LIN microcontrollers covering the protocol handler part and LIN transceivers for the physical line interface. For a quick start with LIN, STMicroelectronics supports you with LIN software enabling you to rapidly set up your first LIN communication and focus on your specific application requirements.
Figure 1. LIN Network Overview
CAN Bus MASTER
LIN Bus
|
|
|
|
|
|
|
SLAVE |
|
SLAVE |
|
SLAVE |
||
|
|
|
|
|
|
|
AN1278/0502 |
1/44 |
Table of Contents
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 LIN PROTOCOL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2 LIN PRODUCTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1 LIN MICROCONTROLLERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.1 LIN Slave MCUs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.1.2 LIN Master MCUs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2 LIN TRANSCEIVERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
. 9 |
||
2.2.1 |
L9637 |
K-Line Transceiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
9 |
2.2.2 |
L9638 |
LIN Transceiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
10 |
3 LIN SOFTWARE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.1 TYPES AND MACRO DEFINITIONS: LIB.H . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.1.1 Debug settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.1.2 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.1.3 Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2 PROTOCOL HANDLER: LIN.P/H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2.1 Type definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.2.2 User interface functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.2.3 Timeout handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.2.3.1 Initializing the timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.3 LIN CONFIGURATION FILE: LIN_CONFIG.H . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.4 APPLICATION INTERFACE: LIN_AI.C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 4 EXAMPLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.1 IMPLEMENTATION ON THE ST72254G2 - SOFTWARE EMULATED SCI . . . 25
4.1.1 Step by Step Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.2 IMPLEMENTATION ON THE ST72334N4 - HARDWARE SCI . . . . . . . . . . . . . 28
4.2.1 Step by Step Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4.2.1.1 lin_config.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4.2.1.2 lin_ai.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 4.2.1.3 Master data request (DataRequest_Notification) . . . . . . . . . . . . . 30 4.2.1.4 Data reception (DataReceived_Notification) . . . . . . . . . . . . . . . . 30
4.3 STMICROELECTRONICS LIN PACKAGE - EXAMPLE INSTALLATION . . . . 33
4.3.1 LIN package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 4.3.2 Quick start with STVD7 and Cosmic C Compiler . . . . . . . . . . . . . . . . . . . . 33
4.4 PERFORMANCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.4.1 Timing considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 4.4.2 Using the Emulated SCI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 4.4.2.1 Reception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 4.4.2.2 Transmission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
2/44
Table of Contents
4.4.3 Using the on-chip SCI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 4.4.3.1 Reception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 4.4.3.2 Transmission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
5 SUMMARY OF CHANGES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3/44
LIN (LOCAL INTERCONNECT NETWORK) SOLUTIONS
1 LIN PROTOCOL
The aim of this chapter is to give an overview of the LIN protocol and concept. For detailed and up-to-date information please refer to the official LIN homepage: www.lin-subbus.org where you can register for the LIN specification package.
The LIN specification package consists of three parts:
■The LIN protocol specification
■The LIN configuration language description
■The LIN API
The first part describes the LIN physical and data link layers. The second part describes the LIN configuration language. The LIN configuration language enables the user LIN network to be described in a file (how many nodes, how many frames, frame description, baudrate etc.). The goal of this specification is to ease communications between the parties involved in the development of a LIN network like car manufacturers and their suppliers. The third and last part is about the software implementation of the LIN protocol and specifies some points on how the software implementation has to be done.
The LIN concept uses a single master / multiple slave model. Only the master is able to initiate a communication. A LIN frame consists of a header and a response part. To initiate a communication with a slave the master sends the header part. If the master wants to send data to the slave it goes on sending the response part. If the master requests data from the slave the slave sends the response part.
Figure 2. Basics of LIN communication
Master to slave 1 |
Slave 1 |
|
Slave 2 |
|
|
||
Master |
|
|
|
|
|
|
Slave 2 to master |
LIN |
|
|
sent by: |
|
|
Master |
|
Bus |
|
|
|
|
|
|
Slave 1 |
1 LIN frame |
Header |
Response |
Slave 2 |
Direct communication between slaves is not possible. But as all nodes always listen to the bus, a master request can be used to handle slave-to-slave communications.
4/44
LIN (LOCAL INTERCONNECT NETWORK) SOLUTIONS
The LIN protocol is object-oriented and not address-oriented. The header contains the identifier which identifies the LIN frame and the data it contains. Different nodes may receive the same frame data.
The response part consists mainly of data of selectable length (1 to 8 bytes). The data are secured by an 8 bit checksum.
The LIN protocol is time-trigger oriented. The master periodically sends the same sequence of LIN frames. Each sequence, the master and the slaves update the data they send and receive. The sequence sent by the master may change depending on application events.
Example: The slave is a sensor measuring a analog value which is communicated to the master via LIN. The slave continuously measures its analog input independently from the LIN communication. In response to a master request (periodical) the slave sends the up-to-date/ last measured value of the analog input.
Figure 3. Time-triggered protocol
Master |
|
|
|
|
|
|
Slave 1 |
Slave 2 |
Analog |
||
|
|
|
|||
|
|
|
value |
1 sequence |
|
|
|
|
change |
||
LIN |
25 |
25 |
38 |
38 |
|
Bus |
|||||
|
|
|
|
||
|
Analog value:25 |
|
Analog value:38 |
In order to achieve a good level of security, different mechanisms exist like parity bits on the identifier or checksum on data bytes.
One important feature of the protocol is to enable the slave MCUs to run with low cost oscillators such as an integrated RC oscillator provided that the accuracy is better than +/-15%. For this purpose the header contains a sync field byte consisting of the constant 0x55. This byte enables each slave to measure the master bit time and to synchronize its clock accordingly.
In order to obtain very low power consumption, the master is able to send a sleep frame. Any node can go into low power mode. To wake up the network, any node can send a so-called wake-up signal.
5/44
LIN (LOCAL INTERCONNECT NETWORK) SOLUTIONS
Figure 4. Sleep mode - wake-up
Sleep mode |
|
Wake-up |
|
command |
|
signal |
|
“normal” mode |
Sleep mode |
Network |
“normal“ |
|
|
start-up |
mode |
6/44
LIN (LOCAL INTERCONNECT NETWORK) SOLUTIONS
2 LIN PRODUCTS
A typical LIN node consists of a microcontroller for handling the LIN protocol and a LIN transceiver for interfacing the digital part and the physical line (see Figure 5 . LIN bus topology). STMicroelectronics offers both kind of products.
Figure 5. LIN bus topology
|
|
LIN Bus |
|
|
|
TRANSCEIVER |
|
MASTER |
|
TX |
RX |
|
|
LIN Bus |
|
|
|
MICROCONTROLLER |
|
SLAVE |
SLAVE |
SLAVE |
|
2.1 LIN MICROCONTROLLERS
STMicroelectronics offers a wide range of microcontrollers suitable for master and/or slave nodes.
2.1.1 LIN Slave MCUs
Table 1. Very low cost LIN slave MCUs - full software solution - Flash/ROM MCUs
Features |
ST72104G1 |
ST72104G2 |
ST72216G1 |
ST72215G2 |
ST72254G1 |
ST72254G2 |
|
Program memory - |
4k |
8k |
4k |
8k |
4k |
8k |
|
bytes |
|||||||
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
RAM (stack) - bytes |
|
|
256 |
(128) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Watchdog |
Watchdog |
|
|
|
|
|
|
timer, |
|
|
||
|
Watchdog timer, One 16- |
timer, One |
Watchdog timer, Two 16- |
||||
Peripherals |
Two16-bit |
||||||
bit timer, SPI |
16-bit timer, |
bit timers, SPI, I2C, ADC |
|||||
|
timers, SPI, |
||||||
|
|
|
SPI, ADC |
ADC |
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
Operating Supply |
|
|
3.2V to 5.5V |
|
|
||
|
|
|
|
||||
CPU Frequency |
|
Up to 8MHz (with oscillator up to 16 MHz) |
|
||||
|
|
|
|
|
|
|
|
Operating Tempera- |
|
-40°C to +85°C (-40°C to +105/125°C optional) |
|
||||
ture |
|
|
|||||
|
|
|
|
|
|
||
|
|
|
|
|
|
||
Packages |
|
|
SO28 / SDIP32 |
|
|
||
|
|
|
|
|
|
|
7/44
LIN (LOCAL INTERCONNECT NETWORK) SOLUTIONS
Table 2. Low cost LIN slave MCUs with hardware SCI - Flash/ROM MCUs
Features |
|
ST72124J2 |
ST72314J2 |
ST72314J4 |
|
ST72314N2 |
|
ST72314N4 |
|
ST72334J2 |
|
ST72334J4 |
|
ST72334N2 |
|
ST72334N4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Program memory |
|
8k |
8k |
16k |
|
8k |
|
16k |
|
8k |
|
16k |
|
8k |
|
16k |
|
- bytes |
|
|
|
|
|
|
|
||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RAM (stack) - |
|
384 |
384 |
512 |
384 |
|
512 |
|
384 |
512 |
|
384 |
|
512 |
|||
bytes |
|
(256) |
(256) |
(256) |
(256) |
|
(256) |
|
(256) |
(256) |
|
(256) |
|
(256) |
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
Peripherals |
|
|
|
|
Watchdog |
|
timer, |
Two 16-bit timers, SPI, SCI |
|
|
|
|
|||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- |
|
|
|
|
|
ADC |
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
Operating Supply |
|
|
|
|
|
|
|
3.0V to 5.5V |
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
||||||
CPU Frequency |
|
|
|
|
Up to 8MHz (with up to 16MHz oscillator) |
|
|
|
|
||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Operating Tem- |
|
|
|
|
-40°C to +85°C (-40°C to +105/125°C optional) |
|
|
|
|
||||||||
perature |
|
|
|
|
|
|
|
|
|||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
Packages |
|
|
TQFP44/SDIP42 |
TQF64/SDIP56 |
|
TQF44/SDIP42 |
|
TQF64/SDIP56 |
|||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2.1.2 LIN Master MCUs |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||
Table 3. EPROM/OTP/ROM MCUs |
|
|
|
|
|
|
|
|
|
|
|
|
|||||
|
|
|
|
|
|
|
|
|
|
|
|
||||||
Features |
|
|
ST72511R9 |
|
|
|
ST72511R7 |
|
|
ST72511R6 |
|
||||||
Program memory - |
|
|
60k |
|
|
|
48k |
|
|
|
|
32k |
|
||||
bytes |
|
|
|
|
|
|
|
|
|
|
|||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|||||||
RAM (stack) - bytes |
|
|
2048 (256) |
|
|
1536 (256) |
|
|
1024 (256) |
|
|||||||
|
|
|
|
|
|
|
|||||||||||
Peripherals |
|
|
Watchdog timer, |
Two 16-bit timers, 8-bit PWM ART, SPI, ADC |
|
||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||
Operating Supply |
|
|
|
|
|
|
|
3.0V to 5.5V |
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
|||||||||
CPU Frequency |
|
|
|
Up to 8MHz (with oscillator up to 16 MHz) |
|
|
|
|
|||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Operating Tempera- |
|
|
|
-40°C to +85°C (-40°C to +105/125°C optional) |
|
||||||||||||
ture |
|
|
|
|
|||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
Packages |
|
|
|
|
|
|
|
TQFP64 |
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Table 4. Flash, ROM MCUs (ST7 core)
Features |
ST72521R/M9 |
ST72521R/M7 |
ST72521R/M6 |
ST72521R5 |
ST72521R4 |
||
|
|
|
|
|
|
|
|
Program memory - |
60k |
48k |
32k |
24k |
16k |
||
bytes |
|||||||
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
RAM (stack) - bytes |
2048 (256) |
1536 (256) |
1024 (256) |
768 (256) |
512 (256) |
||
|
|
|
|
|
|
|
|
|
|
Watchdog timer, 16-bit timers, SPI, SCI, 10-bit ADC, CAN |
|||||
Peripherals |
|
|
|
|
|
|
|
|
8-bit PWM ART, I2C |
8-bit PWM |
|
|
|||
|
|
ART |
|
|
|||
|
|
|
|
|
|
||
|
|
|
|
|
|
||
Operating Supply |
|
|
2.7V to 5.5V |
|
|
||
|
|
|
|||||
CPU Frequency |
16 to 50kHz (with 32 to 100kHz oscillator), 500 to 8 MHz (with 1 to 16 MHz oscil- |
||||||
lator), 2 to 8 MHz (with 2 to 4 MHz oscillator and PLL) |
|||||||
|
|
||||||
|
|
|
|
|
|
||
Operating Tempera- |
0°C to 70°C/-40°C to +85°C/-40°C to +105°C/-40°C to +125°C/ |
||||||
ture |
|||||||
|
|
|
|
|
|||
|
|
|
|
||||
Packages |
|
TQFP80(M), TQFP64 (R) |
|
||||
|
|
|
|
|
|
|
8/44
LIN (LOCAL INTERCONNECT NETWORK) SOLUTIONS
Table 5. Flash, ROM MCUs (ST9 core)
Features |
ST92F150JD |
ST92F150JC |
|
ST92F124J |
|
ST92F124 |
|
|
|
|
|
|
|
FLASH - bytes |
128K |
60/128K |
|
60/128K |
|
60/128K |
|
|
|
|
|
|
|
RAM - bytes |
6K |
2/4K |
|
2/4K |
|
2/4K |
|
|
|
|
|
|
|
EEPROM - bytes |
1K |
1K |
|
1K |
|
1K |
|
|
|
|
|
|
|
Timers |
2MFT, 2 EFT, STIM, |
2MFT, 0/2 EFT, STIM, WD |
|
|||
WD |
|
|||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial Interface |
2 SCI, SPI, I²C |
|
|
1/2 SCI, SPI, I²C |
|
|
|
|
|
|
|
|
|
ADC |
16 x 10 bits |
|
|
8/16 x 10 bits |
|
|
|
|
|
|
|
|
|
Network Interface |
2 CAN, J1850 |
CAN, J1850 |
|
J1850 |
|
- |
|
|
|
|
|
|
|
Temp. Range |
|
-40°C to 125°C or |
-40°C to 85°C |
|
|
|
|
|
|
|
|
|
|
Package |
P/TQFP100 |
|
P/TQFP100 and TQFP64 |
|
||
|
|
|
|
|
|
|
Note: The master MCUs listed above have all an on-chip CAN peripheral. This corresponds to the initial LIN concept: the LIN network as sub-network of CAN. However any other MCUs (listed above as slave for example) can be used to implement a master node.
2.2 LIN TRANSCEIVERS
To ensure the physical behaviour of the LIN bus STMicroelectronics also offers K-Line drivers and a dedicated LIN Bus Transceiver.
2.2.1 L9637 K-Line Transceiver
The L9637 K-Line transceiver is a monolithic integrated circuit containing standard ISO 9141 compatible interface functions. Its features are listed below.
■Operating power supply voltage range 4.5V £ VS £ 36V (40V for transients)
■Reverse supply battery protected down to VS ³ -24V
■Stand-by mode with very low current consumption ISSB 1mA @Vcc 0.5V
■Low quiescent current in OFF condition ISOFF = 120mA
■TTL compatible TX input
■Bidirectional K-I/O pin with supply voltage dependent input threshold
■Overtemperature shut down function selective to K-I/O pin
■Wide input and output voltage range -24V £ VK £ VS
■K output current limitation, typical IK = 60mA
■Defined OFF output status in under voltage condition and VS or GND interruption
■Controlled output slope for low EMI
■High input impedance for open VS or GND connection
■Defined output on status of LO or RX for open LI or K inputs
■Defined K output off for TX input open
9/44
LIN (LOCAL INTERCONNECT NETWORK) SOLUTIONS
■Integrated pull up resistors for TX, RX and LO
■EMI robustness optimized
2.2.2 L9638 LIN Transceiver
The L9638 LIN transceiver is a monolithic integrated circuit fulfilling the LIN specification.
Its features are listed below.
■Wake up capability by:
-LIN bus
-External signal (edge triggered)
■System wake up functions:
-Inhibit output
-RxD output
■Quiescent current less than 25µA
■Fail safe functions implemented
■Pin compatible to L9637
Figure 6. L9638 block diagram
VS |
|
|
|
|
Int.5V |
Internal |
|
|
|
Voltage |
|
|
|
Regulator |
|
RXD |
|
Glitch |
LIN |
|
Filter |
||
TXD |
|
|
|
EN |
|
Control |
|
|
|
Logic |
INH |
WUP |
Glitch |
Protection |
|
Filter |
|
||
|
|
|
|
|
|
|
GND |
10/44 |
|
|
|
LIN (LOCAL INTERCONNECT NETWORK) SOLUTIONS
The following figure (Figure 7) shows a typical application of the L9638 LIN transceiver together with the ST72124J microcontroller and a voltage regulator.
Figure 7. Application of L9638 with ST72124J Microcontroller
LIN Node
GND
Vbatt |
|
|
|
|
|
Vs |
voltage |
Vout |
|
Vdd |
|
|||||||||
|
|
|
|
|
|
|
||||||||||||||
|
|
|
|
|
|
|
|
|
reset |
|
||||||||||
|
|
|
|
|
|
|
|
|
|
|||||||||||
|
|
|
|
|
|
|
|
|
||||||||||||
|
|
|
|
|
|
|
|
regulator RES |
|
|
||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||
|
|
|
|
|
|
|
|
|
|
EN |
GND |
|
ST72124J |
|
||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MCU |
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vs |
|
INH |
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
LIN |
|
EN |
|
I/O pin |
|
|||||||
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
transceiver |
|
|
|
|
|
|
|||||||
LIN |
|
|
|
|
|
|
LIN |
|
L9638 |
|
TxD |
|
TDI |
|
||||||
|
|
|
|
|
|
|
|
RxD |
|
RDO |
|
|||||||||
|
|
|
|
|
|
|
|
|
WUP |
|
|
|
|
GND |
|
|||||
|
|
|
|
|
Vdd |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The voltage regulator supplies the application and generates the MCU reset signal. The LIN transceiver is the physical line interface between the SCI (Serial Communication Interface) TDI and RDO pins of the microcontroller and the LIN bus line. The microcontroller handles the LIN protocol and the application functions.
In order to lower power consumption the microcontroller is able to switch off the LIN transceiver via the L9638 “EN” input. The transceiver is then able to switch off the voltage regulator by connecting its “INH” output to the “EN” input of the voltage regulator. In this state any activity on the LIN bus will cause the L9638 to wake the voltage regulator up via the “INH” pin. Another wake-up source is the “WUP” pin of the L9638 that can be used for contact sensing. Any edge on this pin will also wake up the regulator.
11/44
LIN (LOCAL INTERCONNECT NETWORK) SOLUTIONS
3 LIN SOFTWARE
Table 6. Software Overview
Version |
2.0 |
Supported nodes |
slave |
|
|
Supported MCUs |
all ST7 MCUs |
|
|
LIN protocol specification revision |
rev 1.2 |
|
|
The LIN standard includes the specification of the communication protocol but also the use of associated tools.
STMicroelectronics supports the development of your LIN application by providing ready-to- use LIN software. This software only handles the communication protocol part. For a complete software development tool solution you can contact LIN specialist third party tools manufacturers like VCT (http://www.vct.se) or Vector (http://www.vector-informatik.de).
The software supports LIN slave nodes. It consists of 4 files:
–lin.c/h: protocol handler code
–lin_config.c: LIN parameter configuration file
–lin_ai.c: application interface
A fifth additional file is delivered:
– lib.h: library file (macros, types definition)
The software supports the COSMIC C compiler.
Figure 8. Software Architecture
|
|
application |
|
|
APPLICATION |
specifics |
lin-ai.c |
|
|
|
|
|
|
|
LIN |
|
|
|
MESSAGE |
lin config.h |
|
lin.c |
interrupt |
|
|
|
|
|
|
HARDWARE |
|
12/44 |
|
|
|
LIN (LOCAL INTERCONNECT NETWORK) SOLUTIONS
The software is interrupt driven. As soon as a message begins on the bus, an interrupt is generated and automatically handles the protocol. This means that the protocol handler is totally autonomous. It runs in the background. When the received frame is decoded by the software this is notified to the application in the lin_ai.c. In this file the user is able to customize the behaviour of the application upon reception of a frame for example.
3.1 TYPES AND MACRO DEFINITIONS: LIB.H
3.1.1 Debug settings
see 4.4.1 Timing considerations
3.1.2 Types
The software uses predefined types for 1-byte and 2-byte variables.
The name used for the one-byte type is “uByte“.
The name used the two-byte type is “uWord”.
Beside these, a third type is used to define two-byte variables that can also be accessed high byte or low byte only.
typedef union {
unsigned int w_form;
struct {
unsigned char high, low;
}b_form;
}TwoBytes;
These types are defined in the lib.h file.
3.1.3 Macros
Three macros for register bit access are defined:
–SetBit(var,pos): Set bit “pos” of “var” variable
–ClrBit(var,pos): Clear bit “pos” of “var” variable
–ValBit(var,pos): Test bit “pos” of “var” variable. Return “0” if reset another value otherwise.
3.2 PROTOCOL HANDLER: LIN.P/H
The lin.p file contains the protocol handler. The user has no access to this file. It should simply be linked to the rest of the application. The lin.p file is encrypted and can therefore not be read but must be compiled and linked to the rest of the application.
The lin.h contains the definition of new types and the prototypes of the functions defined in lin.c.
13/44
LIN (LOCAL INTERCONNECT NETWORK) SOLUTIONS
3.2.1 Type definition t_error
typedef enum {NO_ERROR,BIT_ERROR,ID_PARITY_ERROR,CHECKSUM_ERROR, NO_ID_MATCH,TIMEOUT_ERROR,DATA_RECEIVED,DATA_REQUEST, WAKE_UP,UART_ERROR,SYNCH_BREAK_ERROR}t_error;
defines the different error code values that the software functions are able to return.
t_message_direction
typedef enum {ID_DATAREQUEST,ID_DATASENT}t_message_direction;
This type is used internally in lin.c and in lin_drv.c.
t_id_list
typedef struct{
uByte id;
t_message_direction dir;
uByte length;} t_id_list;
defines the type of an identifier list.
t_one_databyte_output
typedef struct{
t_error error_code;
uByte data_byte;} t_one_databyte_output;
defines a type of function return value consisting of an error code made up of error type and a data byte.
t_header
typedef struct
{
uByte identifier;
uByte length;} t_header;
A LIN frame consists of a header and a response. This typedef defines the header part type.
t_response
typedef struct
{
uByte data[8];
uByte checksum;} t_response;
A LIN frame consists of a header and a response. This typedef defines the response part type.
3.2.2 User interface functions
To integrate this software into your application software you have to link 3 or 4 functions defined in lin.c to your project.
14/44