Using the LIN in Traveo II Family

About this document

Scope and purpose

This application note describes how to use Local Interconnect Network (LIN) for Traveo II family MCU. The LIN block of Traveo II supports the serial interface protocols LIN and UART. The LIN block supports the autonomous transfer of the LIN frame, to reduce CPU processing.

Associated Part Family

Traveo™ II Family CYT2/CYT3/CYT4 Series

Intended audience

This document is intended for anyone who uses the local interconnect network (LIN) driver of the Traveo II family.

General Description

LIN System Connection Diagram

The LIN protocol works on the concept of single master and multiple slaves and uses a single wire-bus for communication. Figure 1 shows the principle setup of LIN cluster with two LIN nodes.

Figure 1 Example of Environment for the LIN Master/Slave

Message Frame Format

As shown in Figure 2, LIN message frame has a:

Figure 2 LIN Message Frame Format

See the Architecture TRM for details of the LIN message frame format.

Baud Rate Setting

The baud rate, derived from the PERI clock, can be configured for each channel individually. PERI clock is input to the LIN block via the peripheral clock divider. The baud rate is configured by the peripheral clock divider value. Furthermore, there is a fixed signal oversampling factor of 16 in the LIN channel. Therefore, the baud rate is calculated as shown in Equation 1.

Equation 1
Baud Rate = PERI clock / (16 × Divider value)

Equation 2 shows an example for the calculation of the divider setting value when PERI clock is 24 MHz and the required LIN baud rate is 20 kbps (20 kHz).

Equation 2
Divider value = PERI clock / (16 × Baud Rate) = 24 MHz / (16 × 20 kHz) = 75

See Clocking System in the Architecture TRM for details of the PERI clock, peripheral clock divider, and divider value settings.

LIN Communication Example

This section describes how to implementation of the LIN communication using the Sample Driver Library (SDL). The code snippets in this application note are part of SDL. See Other References for the SDL.

SDL has a configuration part and a driver part. The configuration part configures the parameter values for the desired operation. The driver part configures each register based on the parameter values in the configuration part. You can configure the configuration part according to your system.

As the LIN is a deterministic in principle, the LIN Master has the scheduler that is activated periodically by the reference timer and controls the bus activity. Every frame is transmitted according to the predefined slots. Each LIN frame starts with the master header.

Furthermore, LIN Master has a schedule table, which is divided into time slots. The schedule is finished, when all time slots response frames are passed. A repetition of the table is executed by retriggering the scheduler, but the master node also has the flexibility to replace the schedule table by another one.

In the schedule table, the communication type of each time slot such as frame ID, message type, data length, and type of check sum used for the response is predetermined. The message type defines the response transmitter. If there are multiple slaves, then the message type defines the slave which will transmit a response.

In LIN communication, two checksum types are supported: classic mode and enhanced mode. In classic mode, the PID field is not included in the checksum calculation, only the data fields are included in the calculation; whereas in enhanced mode, the PID field is included along with the data fields in the checksum calculation. The checksum type is can be selected using the CHECKSUM_ENHANCED bit in the LIN_CH_CTL register. See the Registers TRM for details of checksum type.

Table 1 Example of a Scheduled Table

Time Slot ID Message Type Data Length Checksum Type
1 0x01 Slave Response 8 Enhanced
2 0x02 Master Response 8 Enhanced
3 0x10 Slave Response 1 Enhanced
4 0x11 Master Response 1 Enhanced
5 0x20 Slave-to-Slave 1 Enhanced

In this example, the schedule table consists of five time slots 1 to 5.

The message type of time slot 1 is a slave response and data length are 8. Therefore, when the header is transmitted by scheduler trigger, the LIN slave transmits response data of 8 bytes to the master.

In time slot 4, there is a master response with one byte data length. The master node transmits 1 byte of data along with the header to the slave nodes.

Time slot 5 defines a slave-to-slave response. In this case, the response is only between dedicated slave nodes and the master can ignore the response.

Figure 3 shows LIN communication example between the master node and slave node as per the schedule listed in Table 1.

Figure 3 Communication Between LIN Master and Slave

1. The master transmits a header with ID = 0x01 after the scheduler activation.

2. After receiving the header, the slave transmits the response of 8 bytes to the master according to schedule table (time slot 1).

3. When the master receives the response, the frame in time slot 1 is completed and the master waits for the next scheduler activation.

4. When scheduler is activated, the master transmits the header with ID = 0x02.

5. The master transmits a response of 8 bytes to the slave after transmitting header (time slot 2) and the master waits for the next scheduler activation.

6. This operation procedure is repeated until the last time slot 5.

7. After the operation of time slot 5 is completed, the next time the scheduler is activated starting with time slot 1.

LIN Message Transfer

In the SDL, to support different message types such as transmission and reception of header/response, the handling of the LIN master or LIN slave operation mode is implicitly done by following commands:

These commands are configured corresponding to the message type in Table 1. For details, see section 4 and section 5.

Event Generation

The LIN block generates interrupt events such as transmission completion, reception completion, and error detection. Each LIN channel has its dedicated interrupt signal and its own interrupt registers: LIN_CH_INTR, LIN_CH_INTR_SET, LIN_CH_INTR_MASK, and LIN_CH_INTR_MASKED. In this implementation example, INTR_MASK controls interrupt generation, and the LIN_CH_CMD.INTR_MASKD register checks the interrupt source.

Table 2 List of Send/Receive Events
Send/Receive Events Master Slave
TX_HEADER_DONE -
RX_HEADER_DONE
TX_RESPONSE_DONE -
TX_WAKEUP_DONE
RX_RESPONSE_DONE
RX_BREAK_WAKEUP_DONE -
RX_HEADER_SYNC_DONE -
Table 3 List of Error Events
Error Events Master Slave
RX_NOISE_DETECT
TIMEOUT
TX_RESPONSE_BIT_ERROR -
RX_HEADER_SYNC_ERROR
RX_RESPONSE_FRAME_ERROR
RX_RESPONSE_CHECKSUM_ERROR
TX_HEADER_BIT_ERROR -

The related interrupt registers have a bit corresponding to these events. The software can control the generation of events by setting or clearing the corresponding bits.

See the Architecture TRM and Registers TRM for details of events and each interrupt register.

Example of Master Operation

This section shows an example implementation of a LIN Master using Table 1. In the SDL, you can manage the state machine using commands. Figure 4 shows the operation of LIN Master state machine.

Figure 4 LIN Master State Machine

LIN Master state machine has the following four states.

The software determines the state according to the message type of the schedule table, and sets the command sequence according to the current state.

Table 4 Correspondence of Message Type, State, and Command Sequence Settings in LIN Master Node

Message Type State Command TX_HEADER RX_HEADER TX_RESPONSE RX_RESPONSE
Slave Response LIN_STATE_TX_HEADER_RX_RESPONSE - 1 0 0 1
Master Response LIN_STATE_TX_HEADER_TX_RESPONSE - 1 0 1 0
Slave-to-Slave LIN_STATE_TX_HEADER - 1 0 0 0

The following is an example of initialization and interrupt control to execute these processes.

LIN Master Initialization

Figure 5 shows the flow example for LIN Master Initialization.

Figure 5 LIN Master Initialize Flow Example

(1) Initialize LIN Master.

(2) Enable LIN Channel.

Software enables the external LIN transceiver after port setting is completed. This example does not control the external LIN transceiver because LIN_CH_CTL0.AUTO_EN is set to “0” in step 4 of this setup procedure. In this case, the software can control the EN-pin via the register bit TX_RX_STATUS.EN_OUT. If the LIN_EN_OUT pin for this deployed channel is not available on the MCU, EN-pin on the transceiver can be also controlled by a normal GPIO output.

(3) Initialize software state machine.

Set current state to lin_state=LIN_STATE_IDLE.

(4) Start the timer for starting the scheduler.

The communication starts automatically when the scheduler starts by this setting.

For details for clock setting, port setting, and Interrupt Controller setting, see the Architecture TRM and Registers TRM.

Use Case

This section describes a use case of LIN Master Initialization with the following parameters.

Configuration and Example

Table 5 lists the parameters of the configuration part in SDL for LIN Master Initialization.

Table 5 List of LIN Master Initialization Parameters
Parameters Description Setting Value
For CLK CY_LINCHO_PCLK Peripheral Clock Number PCLK_LINO_CLOCK_CH_ENO
For LIN Master or Slave Mode true (Master Mode)
LIN transceiver auto enable: true (Enable)
Break/wakeup length (minus 1) in bit periods: 13ul (13-1 = 12 bit)
Break delimiter length: LinBreakDelimiterLength1bits (1 bit)
STOP bit periods LinOneStopBit (1 bit)
RX filter true
Define using LIN Channel Number Assigned to LINO channel 0

Code Listing 1 demonstrates an example program to initialize the LIN Master in the configuration part.

Code Listing 1 demonstrates an example program to initialize the LIN Master in the configuration part.

Code Listing 2 demonstrates an example of SchedulerInit.

Code Listing 3 demonstrates an example program to configure LIN in the driver part.

The following description will help you understand the register notation of the driver part of SDL:

Example of LIN Communication of LIN Master

When the LIN communication starts, the interrupt activates the master scheduler handler. Figure 6 shows example of how the master schedule handler works.

Figure 6 Example of Master Schedule Handler

The following is the application software operation for the scheduler:

Use Case

This section describes an example of determining the message type and performing LIN Master Communication.

Configuration and Example

Table 6 lists the parameters of the configuration part in SDL for LIN Communication (LIN Master)

Table 6 List of LIN Communication Parameters
Parameters Description Setting Value
For LIN msgContext[] ID/ Message Type 0x01ul / LIN_RX_RESPONSE
0x02ul / LIN_TX_RESPONSE
0x10ul / LIN_RX_RESPONSE
0x11ul / LIN_TX_RESPONSE
0x20ul / LIN_TX_HEADER
Checksum Type LinChecksumTypeExtended
Data Length 8ul or 1ul
CY_LINCHO_TYPE Define using LIN Channel Number Assigned to LINO channel 0

Code Listing 4 demonstrates an example program to communicate LIN in the configuration part.

Example of LIN Master Interrupt Handling

When an interrupt set by the scheduler occurs, LIN Master IRQ handler is activated. Figure 7 shows example to how the LIN Master IRQ handler works.

Figure 7 Example of LIN Master IRQ Handler

The following is the application software operation for the LIN master IRQ handler:

Use Case

This section describes an example in which the LIN Master Handler determines the interrupt factor, clears the interrupt factor, and executes the processing for current state.

Configuration and Example

Table 7 lists the parameters of the configuration part in SDL for LIN Master Interrupt Handler.

Table 7 List of LIN Master Interrupt Handler Parameters
Parameters Description Setting Value
For Interrupt irq_cfg.sysIntSrc System interrupt index number CY_LINCHO_IRQN
irq_cfg.intIdx CPU interrupt number CPUIntIdx3_IRQn
irq_cfg.isEnabled CPU interrupt enable true (0x1)
For LIN CY_LINCHO_TYPE Define using LIN Channel Number Assigned to LINO channel 0

Code Listing 13 demonstrates an example program to interrupt LIN in the configuration part.

Example of Slave Operation

This section shows an example implementation of the LIN Slave. The LIN Slave transmits or receives information depending on the schedule table from the LIN protocol analyzer that acts like a master. LIN Slave IRQ Handler includes a table; see Table 8 for an example of message frame ID processing and this information is used in Figure 11. The LIN Slave receives the header from the LIN master. Upon receiving the header, the response field corresponding to the received PID will be transmitted or received as shown in Table 8. To support these different message types, the handling of the LIN Slave operation is implicitly done by command sequences, as listed in the “LIN Slave Command Sequence” table in the Architecture TRM.

Table 8 Message Frame ID Processing Table of LIN Slave
ID Message Type Data Length Checksum Type
0x01 Master Response 8 Enhanced
0x02 Slave Response 8 Enhanced
0x10 Master Response 1 Enhanced
0x11 Slave Response 1 Enhanced

In this example, the software manages the configuration of command sequences using a state machine. Figure 8 shows the state machine for the LIN Slave. The arrows from T0 to T6 are the triggers for state transition.

Figure 8 LIN Slave State Machine

LIN slave state machine has following four states:

The software determines the state according to the message type of Table 8 and sets the command sequence according to the current state. Table 9 shows the relationship between message type, states, and command sequence.

Table 9 Correspondence between Message Type, State, and Command Sequence Settings in LIN Slave
Message Type State TX_HEADER RX_HEADER TX_RESPONSE RX_RESPONSE
Slave Response LIN_STATE_TX_RESPONSE 0 1 1 1
Master Response LIN_STATE_RX_RESPONSE 0 1 0 1

The following is an example of initialization and interrupt control to execute these processes.

LIN Slave Initialization

Figure 9 shows the flow example for LIN Slave Initialization.

Figure 9 LIN Slave Initialize Flow Example

(1) Initialize LIN Slave.

(2) Enable LIN Channel.

Software enables the external LIN transceiver after port setting is completed. This LIN example does not control the external LIN transceiver because LIN_CH_CTL0.AUTO_EN is set to “0” in (1) of this setup procedure. In this case, the software can control the EN-pin via the register bit TX_RX_STATUS.EN_OUT. If the LIN_EN_OUT pin for this deployed channel is not available on the MCU, the EN-pin on the transceiver can be also controlled by a normal GPIO output.

(3) Initialize the software state machine.

Set the current state to lin_state=LIN_STATE_IDLE.

For details for Clock setting, port setting, and Interrupt Controller setting, see the Architecture TRM and Registers TRM.

Use Case

This section describes a use case of LIN Slave Initialization with the following parameters.

Configuration and Example

Table 10 lists the parameters of the configuration part in SDL for LIN Master Initialization.

Table 10 List of LIN Slave Initialization Parameters
Parameters Description Setting Value
For CLK CY_LINCHO_PCLK Peripheral Clock Number PCLK_LINO_CLOCK_CH_ENO
For LIN Master or Slave Mode false (Slave Mode)
LIN transceiver auto enable: true (Enable)
Break/wakeup length (minus 1) in bit periods: 11ul (11-1 = 10 bit)
Break delimiter length: LinBreakDelimiterLength1bits (1 bit)
STOP bit periods LinOneStopBit (1 bit)
RX filter true
CY_LINCHO_TYPE Define using LIN Channel Number Assigned to LINO channel 0

Code Listing 17 demonstrates an example program to initialize LIN Slave in the configuration part.

Example of LIN Slave Interrupt Handling

When an interrupt is set by header from master, LIN Slave IRQ handler is activated. Figure 10 shows an example of how the LIN Slave IRQ handler works. This flow is used in Code Listing 18.

Figure 10 Example of LIN Slave IRQ Handler

For the LIN Slave IRQ handler, the application software operation is as follows.

Figure 11 shows how the message type and checksum type operations are performed. This flow is used in the case of jumping from (6) -1 in Figure 10 and in Code Listing 20.

Glossary

Glossary
Terms Description
LIN Local Interconnect Network
LIN transceiver LIN bus is interfaced with external transceivers through a three-pin interface including an enable function, and supports master and slave functionality.
GPIO General Purpose Input/Output
AUTOSAR AUTomotive Open System Architecture
Header Consists of break field, SYNC field, and PID field, transmitted only by the master. See the LIN Message Frame Format section in the LIN chapter of the Architecture TRM for details.
Response Consists of a maximum of 8 data fields and checksum field, transmitted by the master and the slave. See the LIN Message Frame Format section in the LIN chapter of the Architecture TRM for details.
MMIO Memory Mapped I/O
PID Protected Identifier
PERI clock PERipheral Interconnect clock
Message type The message type indicates whether the source of the response is a master or slave. Slave-to-slave means that a slave node transmits the response and another slave receives the response.
Master response The master node transmits the header and transmits the response. This type can be used to control slave nodes. See the “LIN Message Transfer” section in the LIN chapter of the Architecture TRM for details.
Slave response The master node transmits the header. A slave node transmits the response and the master node receives the response. This type can be used to observe slave node status. See the LIN Message Transfer section in the LIN chapter of the Architecture TRM for details.
Slave to slave The master node transmits the header. A slave node transmits the response and another slave receives the response. See the LIN Message Transfer section in the LIN chapter of the Architecture TRM for details.
Data Length Number of data fields in the response (not including the checksum). It is set by LIN_CH_CTL1 register DATA_NR [2:0] bits
Checksum Type There are classic and enhanced modes. In case of classic mode, PID field is not included in the checksum calculation. In case of enhanced mode, PID field is included in the checksum calculation.
ISR Interrupt Service Routine
IRQ Interrupt ReQuest

Related Documents

The following are the Traveo™ II family series datasheets and Technical Reference Manuals. Contact Technical Support to obtain these documents.

Other References

Infineon provides the Sample Driver Library (SDL) including startup as sample software to access various peripherals. SDL also serves as a reference to customers for drivers that are not covered by the official AUTOSAR products. The SDL cannot be used for production purposes because it does not qualify to any automotive standards. The code snippets in this application note are part of the SDL. Contact Technical Support to obtain the SDL.

Revision history

Revision history
Revision ECN No. Submit Date Description of Change
* 6422550 07/11/2019 New application note
*A 6849662 04/09/2020 Changed target parts number (CYT2/CYT4 series)
Added target parts number (CYT3 series)
*B 7035535 2020-12-02 Added example of SDL Code and description.
MOVED TO INFINEON TEMPLATE.

PDF preview unavailable. Download the PDF instead.

002-25346 AN225346 - Using the LIN in Traveo II Family Microsoft Word 2019

Related Documents

Preview Infineon Traveo II SAR ADC Configuration and Usage Guide
Infineon's application note AN219755 details the configuration and usage of the Successive Approximation Register (SAR) Analog-to-Digital Converter (ADC) within the Traveo II microcontroller family. It covers essential features like software and hardware triggering, group processing, averaging, range detection, pulse detection, diagnosis, and calibration, providing practical guidance and code examples for developers working with these advanced MCUs.
Preview Infineon Traveo II Family: TCPWM Timer, Counter, and PWM Application Guide
This application note from Infineon (formerly Cypress) provides a comprehensive guide on using the Timer, Counter, and Pulse Width Modulator (TCPWM) component in the Traveo II family of microcontrollers, covering configuration, modes, and examples.
Preview Low Power Mode Procedure in Traveo II Family
This application note from Infineon (formerly Cypress) details the low-power modes, transition procedures, and related operations for the Traveo II family of microcontrollers (MCUs), including Sleep, DeepSleep, and Hibernate modes, WDT settings, Cyclic Wakeup, and CAN Wakeup.
Preview Getting Started with Traveo II Family MCUs
This application note provides an overview of the Traveo II family of microcontrollers, including their feature sets and development environment. It covers the CYT2, CYT3, and CYT4 series MCUs, detailing their Arm Cortex-M based CPU cores, memory, and peripheral functions. The document also guides users on setting up the development environment and utilizing the Sample Driver Library (SDL).
Preview Infineon CYT2B7 Datasheet: 32-bit Arm Cortex-M4F Microcontroller
Comprehensive datasheet for the Infineon CYT2B7 microcontroller, detailing its features, specifications, and capabilities for automotive applications. Includes information on CPU subsystems, memory, peripherals, power modes, and more.
Preview Infineon Traveo II SAR ADC Customer Training Workshop
Explore Infineon's Traveo II SAR ADC through this customer training workshop. Learn about its 12-bit resolution, 1 Msps sample rate, advanced features like averaging and diagnostics, system architecture, and automotive applications. Ideal for engineers designing embedded systems.
Preview Infineon TLE987x EvalBoard Rev1.2 User Manual for Embedded Power ICs
Comprehensive user manual for the Infineon TLE987x EvalBoard Rev1.2, designed for evaluating TLE987x Embedded Power ICs. Covers hardware features, software toolchain, debugging, jumper settings, and technical specifications for BLDC motor control applications.
Preview Traveo II Program and Debug Interface Training
A customer training workshop detailing the Traveo II microcontroller's program and debug interface, covering target products, system architecture, multi-core debug capabilities, tracing features, and programmer/IDE compatibility.