1.38 SERCOM USART LIN Host

This example application demonstrates how to use the SERCOM USART peripheral in LIN Host mode.

Description

In this example, the LIN Host reads LED and Switch status of the LIN client every 250 milliseconds by sending a LIN receive command. The LIN client responds with 1 byte data containing the Switch status (Bit[0]) and LED status (Bit[1]) followed by the Checksum byte.

Upon receiving the response, LIN Host checks if the Switch status is in pressed or released state. If the switch is pressed, the LIN Host toggles the state of received LED status and asks the LIN client to set the LED to the new state (set LED to OFF state if LED was previously ON and vice versa) by sending a LIN transmit command.

PID for reading LED and Switch status - 0x80 (Frame ID - 0x00).

PID for writing LED status - 0xC1 (Frame ID - 0x01).

The example uses enhanced checksum.

Downloading and Building the Application

To clone or download this application from Github, go to the main page of this repository and then click Clone button to clone this repository or download as zip file. This content can also be downloaded using content manager by following these instructions.

Path of the application within the repository is apps/sercom/usart/usart_lin/master/firmware.

To build the application, refer to the following table and open the project using its IDE.

Project NameDescription
sam_c21n_xpro.XMPLABX project for SAMC21N Xplained Pro Evaluation Kit

Setting Up the Hardware

The following table shows the target hardware for the application projects.

Project NameDescription
sam_c21n_xpro.XSAMC21N Xplained Pro Evaluation Kit

Hardware setup requires two boards, one acting as the LIN Host and the other as the LIN Client.

Setting Up SAMC21N Xplained Pro Evaluation Kit

  • Enable Host node pull-up by mounting the jumper on J501 connector
  • Mount the jumper on J500 connector to power the LIN transceiver from the on board VCC.
  • Connect a wire from “LIN” on J503 on LIN Host board to “LIN” on J503 on LIN client board
  • Connect a wire from “GND” on J503 on LIN Host board to “GND” on J503 on LIN client board
  • Connect the Debug USB port on the board to the computer using a micro USB cable

Running the Application

  1. Build and Program LIN host and LIN client applications using its IDE. Path of the LIN Client application within the repository is apps/sercom/usart/usart_lin/slave/firmware.
  2. Press switch on LIN Host board to start the communication. LIN Host will start reading LED and Switch status from the LIN client every 250 milliseconds.
  3. Press switch on the LIN Client board. The LED on the LIN Client board will toggle if the switch is pressed.
The following table provides the Switch and LED names:
BoardSwitch NameLED Name
SAMC21N Xplained Pro Evaluation KitSW0LED0