MCUXpresso SDK Documentation

lin_stack_slave

lin_stack_slave#

Overview#

The LIN (Local Interconnect Network) stack demo applications demonstrate signal transfer between two nodes, master node and slave node. And the lin_stack_slave demo is used to demonstrate how to use the lin stack as slave node. Both master and slave node must have implemented the timer that is used by timeout service routine every 500 us and master node uses the same timer to check for switch of the frame table scheduler every 5 ms, but the real period between frames may be larger than 5ms according to the configurations.

  • Shortly after the demo starts, the master sends a READ_BY_IDENTIFIER diagnostic request inside a master-request frame (PID 0x3C). The slave transport layer processes the request and automatically sends the slave’s product identity (supplier ID 0x001E, function ID 0x0001, variant 0x00) back to the master in a slave-response frame (PID 0x3D). The application prints a confirmation line when the request has been handled.

  • The master node is in NormalTable schedule table and it uses the LIN frame Motor1State_Cycl to receive data from slave node and send selection signal Motor1Selection command to slave node by Motor1Control.

  • If the command from master is STOP, slave will STOP current data count, and LED 3 is on.

  • If the command from master is INCREASE, slave will continue to increase the tick count every 500us, and LED 2 is on.

  • If the command from master is DECREASE, slave will continue to decrease the tick count every 500us, and LED 1 is on.

  • The value from slave will keep changing between MOTOR1_MAX_VALUE and MOTOR_MIN_VALUE after reset, unless user press slave button 1.

  • If the button 1 was pressed, the slave will change the tick count larger than MOTOR1_STOP_VALUE and send the data to master node.

  • If button 2 was pressed, the slave will set the tick count to 20, and start another loop count.

  • Once running successfully, the state of LEDs on master node and slave node will keep aligned.

  • If master button 2 was pressed while the bus is awake, the master sends a LIN 2.1 Sporadic frame with an indicator in bit 2 of the Motor1Control byte. The slave detects this indicator and increments its own MOTOR1_STOP_VALUE by 10, then prints a confirmation. MOTOR1_STOP_VALUE resets to the default (150) when a go-to-sleep signal is received from the master.

  • On evety 5th press of slave button 1, a system-error event with Motor1ErrorCode = 0x01 and Motor1ErrorValue = 5 is triggered. This clears the event-pending flag so the slave responds to the master’s next LIN 2.1 Event-triggered frame header with the PID of Motor1State_Event followed by the error data. After the ETF response is transmitted, the stack restores the flag automatically and the slave prints a confirmation.

Running the demo#

If communication is successful, press the SW3 button to increase the ticks count then you will see the LED red is ON. Then press the SW2 button to reset the ticks count then you will see the LED blue is ON. And slave node will print:

LIN slave demo start!
Slave will send data to master and receive command from master.
Slave will control the LED according to the command from master.
Diagnostic: READ_BY_IDENTIFIER request handled.
 -> LED 2 is ON!
 -> LED 1 is ON!
 -> LED 2 is ON!
 -> LED 1 is ON!
 <press slave button 1>
 -> LED 3 is ON!
 <press slave button 2>
 -> LED 2 is ON!
  <press master button 2>
Sporadic frame received: MOTOR1_STOP_VALUE raised to 160
 -> LED 1 is ON!
........
 <after pressing slave button 1 5 times>
Event-triggered frame sent: system error reported to master.

Supported Boards#

KW45B41Z-EVK
Overview

The LIN (Local Interconnect Network) demo application is built on Low Power UART. SW3 is used as button 1 to stop ticks count and SW2 is used as button 2 to restart the ticks count.

Hardware requirements
  • Two micro USB cables

  • Two KW45B41Z-EVK boards

  • Personal Computer

  • Power adapter 12 V

  • Three Dupont female-to-female wires

Board settings
  • Connect J11-1 of the two boards

  • Connect J11-2 of the two boards

  • Connect J11-4 of the two boards

  • Short the JP19-1 and JP19-2 with the jumper

  • Short the J1-1 and J2-2 with the jumper due to the autobaudrate feature is enabled by default

Prepare the Demo
  1. Connect a mini/micro USB cable between the PC host and the OpenSDA USB port on the boards.

  2. Open a serial terminal on PC for OpenSDA serial device with these settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  3. Download the program for slave node to the target board.

KW47-EVK
Overview

The LIN (Local Interconnect Network) demo application is built on Low Power UART. SW3 is used as button 1 to stop ticks count and SW2 is used as button 2 to restart the ticks count.

Hardware requirements
  • Two micro USB cables

  • Two KW47-EVK boards

  • Personal Computer

  • Power adapter 12 V

  • Three Dupont female-to-female wires

Board settings
  • Connect J11-1 of the two boards

  • Connect J11-2 of the two boards

  • Connect J11-4 of the two boards

  • Short the JP19-1 and JP19-2 with the jumper

  • Short the J1-1 and J2-17 with the jumper due to the autobaudrate feature is enabled by default

Prepare the Demo
  1. Connect a mini/micro USB cable between the PC host and the OpenSDA USB port on the boards.

  2. Open a serial terminal on PC for OpenSDA serial device with these settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  3. Download the program for slave node to the target board.

FRDM-MCXW70
Overview

The LIN (Local Interconnect Network) demo application is built on Low Power UART. SW3 is used as button 1 to stop ticks count and SW2 is used as button 2 to restart the ticks count.

Hardware requirements
  • Type-C USB cable

  • FRDM-MCXW70 Board

  • Personal Computer

  • Power adapter 12V

  • Three Dupont female-to-female wires

Board settings
  • Connect J18-1 of the two boards

  • Connect J18-2 of the two boards

  • Connect J18-4 of the two boards

  • Short the JP18-1(LPUART0_RX) and J19-3(PTB0_H) with the jumper due to the autobaudrate feature is enabled by default

  • U30 and U12C affects the PTB0_H signal, causing it to remain at a low level. Note: Short JP6 to disable U30 before running this example.

Prepare the Demo
  1. Connect a mini/micro USB cable between the PC host and the OpenSDA USB port on the boards.

  2. Open a serial terminal on PC for OpenSDA serial device with these settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  3. Download the program for slave node to the target board.

FRDM-KW43
Overview

The LIN (Local Interconnect Network) demo application is built on Low Power UART. SW3 is used as button 1 to stop ticks count and SW2 is used as button 2 to restart the ticks count.

Hardware requirements
  • Type-C USB cable

  • FRDM-KW43 Board

  • Personal Computer

  • Power adapter 12V

  • Three Dupont female-to-female wires

Board settings
  • Connect J18-1 of the two boards

  • Connect J18-2 of the two boards

  • Connect J18-4 of the two boards

  • Short the JP18-1(LPUART0_RX) and J19-3(PTB0_H) with the jumper due to the autobaudrate feature is enabled by default

  • U30 and U12C affects the PTB0_H signal, causing it to remain at a low level. Note: Short JP6 to disable U30 before running this example.

Prepare the Demo
  1. Connect a mini/micro USB cable between the PC host and the OpenSDA USB port on the boards.

  2. Open a serial terminal on PC for OpenSDA serial device with these settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  3. Download the program for slave node to the target board.