Jump to main content

##

# 1.44 USART LIN Master

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

## Description

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

Upon receiving the response, LIN Master checks if the Switch status is in pressed or released state. If the switch is pressed, the LIN Master toggles the state of receieved LED status and asks the LIN slave 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/usart/usart_lin/master/firmware.

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

Project Name | Description
--- | ---
sam_e70_xult.X | MPLABX project for SAM E70 Xplained Ultra Evaluation Kit

## Setting Up the Hardware

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

Project Name | Description
--- | ---
sam_e70_xult.X | SAM E70 Xplained Ultra Evaluation Kit

### Setting Up SAM E70 Xplained Ultra Evaluation Kit

Hardware setup requires two boards, one acting as the LIN Master and the other as the LIN slave.

- Plug an LIN Click board into the MikroBus socket on the board.
- Master node should be enabled by proper configuration of MODE resistor on the click board.
- Click board should be enabled for 5V mode , by proper configuraion of VCC SEL resistor on the click board
- Connect a wire from "BUS" on LIN Master click board to "BUS" on LIN slave click board
- Connect a wire from "GND" on LIN Master click board to "GND" on LIN slave click board
- Connect a wire from "VS" on LIN Master click board to "VS" on LIN slave click board
- Connect a wire from "VS" on LIN Master click board to 5V.
- Connect the Debug USB port on the board to the computer using a micro USB cable

## Running the Application

1. Build and Program LIN master and LIN slave applications using its IDE. Path of the LIN Slave application within the repository is apps/usart/usart_lin/slave/firmware
2. Press switch on LIN Master board to start the communication. LIN Master will start reading LED and Switch status from the LIN slave every 1000 milliseconds
3. Press switch on the LIN Slave board. The LED on the LIN Slave board will toggle if the switch is pressed
4. The following table provides the LED and Switch names

   Board | LED Name | Switch Name
   --- | --- | ---
   SAM E70 Xplained Ultra Evaluation Kit | LED2 | SW400