ST AN1278 APPLICATION NOTE

AN1278
APPLICATION NOTE
LIN (LOCAL INTERCONNE CT 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 compone nts. To red uce the amount of wires an d to hand le commu nicati ons betwee n thes e systems, many car m anufacturer s have created different bus syst ems that are incom patible 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. T he new bus, called LIN bus, was invented to be used in sim ple switchin g applications like c ar seats, d oor loc ks, 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 syn­chronization 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 ne twork. Data chec ksum and pa rity check guarantee safety and error detection.
As a long-standing partner to the automoti ve industry, STMicroele ctronics offers a comple te range of LIN silicon products: slave and master LIN micro controllers covering the p rotocol handler part and LIN transceivers for the physical line interface. For a quick start w ith 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
SLAVE
SLAVE
LIN Bus
SLAVE
AN1278/0502 1/44
1
Table of Contents
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1 LIN PROTOCO L . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 LIN PRODUCTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1 LIN MICROCONTROLLER S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.1 LIN Slave MCU s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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 SOFTWAR E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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 CONFIG URATION FILE: LIN_CONFIG.H . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4 APPLICATION INTERFACE: LIN_AI.C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4 EXAMPLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.1 IMPLEMENTATION ON THE ST72254G2 - SOFTWARE EMULA TED SCI . . . 25
4.1.1 Step by Step Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.2 IMPLEMENTATION ON THE S T72334N 4 - 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 Co smic 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
44
2/44
2
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
1
LIN (LOCAL INTERCONNECT NETWORK) SOLUTIONS
1 LIN PROTOCOL
The aim of this chapter is to give an overview of the LIN pr otocol and concept. For detail ed and up-to-date information please ref er to the official LIN hom epage : 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 t his spec ification is t o ea se comm unications be tween the p arties inv olved in the development of a LIN ne twork like c ar m anu factur ers and the ir suppl iers. The th ird an d l ast part is abo ut t he sof twa re impl em en tati on of the L IN pro toco l a nd spe cif ies som e po ints 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 par t. To init iate a c ommu­nication 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 re quests data from the slave the slave sends the response part.
Figure 2. Basics of LIN communicatio n
Master to slave 1
Slave 1
Slave 2
Master
Slave 2 to master
sent by: LIN Bus
Master Slave 1
1 LIN frame
Header Response
Slave 2
Direct com mu ni cat ion b et wee n sl aves is n ot pos si ble . B ut a s al l n ode s a l way s li sten t o the bus, a master request can be used to handle slave-to-slave communications.
4/44
LIN (LOCAL INTERCONNECT NE TWORK) SOLUTIONS
The LIN protocol is object-oriented and not address-oriented. The header contains the identi­fier which ident ifies the LI N f rame and t he data i t c onta ins. Diffe rent no des m ay r ecei ve t he same frame data.
The response part consists mainly of data of selectable length (1 to 8 bytes). The data are se­cured by an 8 bit checksum.
The LIN protocol is time-trigger oriented. The master periodically sends the same sequence of LIN fram es. Each s equ ence , the m ast er an d the slav es upd ate t he da ta th ey se nd an d re­ceive. 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 m aster req uest (periodical) the slave sends the u p-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 Bus
25
Analog value:25
25
38 38
Analog value:38
In order to achieve a good level of security, different mechani sms 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 oscilla­tors such as an integrated RC oscillator provided that the accuracy is better than +/-15%. For this purpose the header contains a sync field byte c onsisting 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
command
“normal” mode Sleep mode
Wake-up
signal
Network start-up
“normal“
mode
6/44
LIN (LOCAL INTERCONNECT NE TWORK) SOLUTIONS
2 LIN PRODUCTS
A typical LIN node consists of a microcontroller for handling the LIN protocol and a LIN trans­ceiver for interfacing the digital part and the physical line (see Figure 5 . LIN bus topo logy ). STMicroelectronics offers both kind of products.
Figure 5. LIN bus topo logy
LIN Bus
TRANSCEIVER
MASTER
LIN Bus
RXTX
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 ­bytes
RAM (stack) - bytes 256 (128)
Peripherals
Operating Supply 3.2V to 5.5V CPU Frequency Up to 8MHz (with oscillator up to 16 MHz) Operating Tempera-
ture Packages SO28 / SDIP32
4k 8k 4k 8k 4k 8k
Watchdog
timer,
Two16-bit
timers, SPI,
ADC
Watchdog timer, Two 16-
bit timers, SPI, I2C, ADC
Watchdog timer, One 16-
bit timer, SPI
-40°C to +85°C (-40°C to +105/125°C optional)
Watchdog
timer, One
16-bit timer,
SPI, ADC
7/44
LIN (LOCAL INTERCONNECT NETWORK) SOLUTIONS
Table 2. Low cost LIN slave MCUs with hardware SCI - Flash/ROM MCUs
Features
ST72124J2
Program memory
- bytes RAM (stack) -
bytes Peripherals Operating Supply 3.0V to 5.5V
CPU Frequency Up to 8MHz (with up to 16MHz oscillator) Operating Tem-
perature Packages TQFP44/SDIP42 TQF64/SDIP56 TQF44/SDIP42 TQF64/SDIP56
8k 8k 16k 8k 16k 8k 16k 8k 16k
384
(256)
-ADC
ST72314J2
384
(256)
ST72314J4
512
(256)
Watchdog timer, Two 16-bit timers, SPI, SCI
-40°C to +85°C (-40°C to +105/125°C optional)
ST72314N2
384
(256)
ST72314N4
512
(256)
ST72334J2
384
(256)
ST72334J4
512
(256)
ST72334N2
384
(256)
512
(256)
2.1.2 LIN Master MCUs Table 3. EPROM/OTP/R OM MCUs
Features ST72511R9 ST72511R7 ST72511R6
Program memory ­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-
ture Packages TQFP64
60k 48k 32k
-40°C to +85°C (-40°C to +105/125°C optional)
ST72334N4
Table 4. Flash, ROM MCUs (ST7 core)
Features ST72521R/M9 ST 72521R/ M 7 ST72521R/M6 ST72521R5 ST72521R4
Program memory ­bytes
RAM (stack) - bytes 2048 (256) 1536 (256) 1024 (256) 768 (256) 512 (256)
Peripherals
Operating Supply 2.7V to 5.5V CPU Frequency Operating Tempera-
ture Packages TQFP80(M), TQFP64 (R)
8/44
60k 48k 32k 24k 16k
Watchdog timer, 16-bit timers, SPI, SCI, 10-bit ADC, CAN
8-bit PWM ART, I2C
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)
0°C to 70°C/-40°C to +85°C/-40°C to +105°C/-40°C to +125°C/
8-bit PWM
ART
LIN (LOCAL INTERCONNECT NE TWORK) 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 - bytes1K 1K1K1K
Timers
2MFT, 2 EFT, STIM,
WD
2MFT, 0/2 EFT, STIM, 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 / TQ FP100 and TQ FP64
Note: The master MCUs listed abov e have all an on-chip CAN peripher al. This corresponds to the initi al LIN conc ept: t he LI N netw ork a s sub- netw ork of CAN . How eve r any ot her M CUs (listed above as slave for example) can be used to implement a master node.
2.2 LIN TRANSCEIVER S
To ensure the physical behaviour of the LIN bus STMicroelectronics also offers K-Line dr ivers 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 V
Reverse supply battery protected down to V
Stand-by mode with very low current consumption IS
Low quiescent current in OFF condition IS
TTL compatible TX input
Bidirectional K-I/O pin with supply voltage dependent input threshold
Overtemperature shut down function selec tive to K-I/O pin
Wide input and output voltage range -24V V
K output current limitation, typical I
Defined OFF output status in under voltage condition and V
Controlled output slope for low EMI
= 60mA
K
OFF
36V (40V for transients )
S
-24V
S
1µA @Vcc 0.5V
SB
= 120µA
V
K
S
or GND interruption
S
High input impedance for open V
Defined output on status of LO or RX for open LI or K inputs
Defined K output off for TX input open
or GND connection
S
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
V
S
Int.5V
RXD
T
D
X
EN
WUP
Glitch Filter
Internal Voltage Regulator
Glitch Filter
Control
Logic
Protection
LIN
INH
10/44
GND
LIN (LOCAL INTERCONNECT NE TWORK) SOLUTIONS
The following figure (Fig ure 7) shows a t ypical applic ation of the L9 638 L IN tran sceiv er to­gether with the ST72124J microcontroller and a voltage regulator.
Figure 7. Application of L9638 with ST72124J Microcontroller
LIN Node
GND
Vbatt
voltage
Vs
regulator
EN
Vout
RES
GND
Vdd
reset
ST72124J
MCU
Vs
INH
EN
I/O pin
LIN
LIN
LIN
Vdd
transceiver
L9638
WUP
TxD RxD
TDI
RDO
GND
The voltage regulator supplies the application an d generates the MCU reset signal. The LIN transcei ver is th e physic al line inte rface betw een the SC I (Seria l Com munic ation In terfac e) 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 co nsumption the microco ntroller is able t o switch o ff the LIN trans­ceiver via the L9638 “EN” input. The transceiver i s then abl e to switch off the voltage regulator by connecting its “INH” output to the “EN” i nput of the v oltage regulator. In this s tate any ac­tivity on the LIN bus wi ll cause the L9638 to wake the voltage r egulator up v ia the “INH” p in. Another wake-up source is the “W UP” pin of the L9638 that can be used for contact sens ing. Any edge on this pin will also wake up the regulator.
11/44
LIN (LOCAL INTERCONNECT NETWORK) SOLUTIONS
3 LIN SOFTW ARE
Table 6. Software Overview
Version 2.0 Support ed nodes slave Supported MCUs all ST 7 MC U s 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 supp orts the deve lopm ent of y our L IN app lication by prov iding re ady-to­use LIN software. This software only handles the communication protocol part. For a complete software development t ool solution y ou can con tact LIN s pecialist t hird p arty tools ma nufac ­turers 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 comp iler.
Figure 8. Software Architecture
application
APPLICATION
specif ics
lin.c
lin_config.h
lin-ai.c
LIN
MESSAGE
interrupt
12/44
HARDWARE
LIN (LOCAL INTERCONNECT NE TWORK) SOLUTIONS
The software is interrupt driven. As soon as a message begins on the bus, an inter rupt is gen­erated and automatically handles the protocol. T his m eans 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 be­haviour 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 con tains th e definition of new typ es and th e protot ypes of th e 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 l ink 3 or 4 functions de­fined in lin.c to your project.
14/44
Loading...
+ 30 hidden pages