Jump to main content

# 1.8 FLEXCOM LIN

This example application shows how to use the FLEXCOM module in LIN mode.

## Description

In this example, the LIN host reads the state of the LED and the switch from the LIN client device every second by sending a LIN receive command. The LIN client responds with a data byte containing the state of the switch (Bit[0]) and the state of the LED (Bit[1]).

Upon receiving the response, the LIN host evaluates whether the switch LIN client is pressed or released. If the switch LIN client is released, the LIN host toggles the state of the received LED and instructs the LIN client to set the LED to the new state (turn off the LED if it was previously on, and vice versa) by sending a LIN transmit command.

If the switch LIN client is pressed, the LIN host turns on its own LED and does not instruct the LIN client to change the state of its LED.

LIN is only available for FLEXCOM 0 to 10.

## 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/flexcom/usart/flexcom_lin/master and apps/flexcom/usart/flexcom_lin/slave.

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

Project Name | Description
--- | ---
sam_a7d65_curiosity.X | MPLABX project for SAMA7D65 Curiosity Board
sam_a7d65_curiosity_pro.X | MPLABX project for SAMA7D65 Curiosity Pro Board

## Setting Up AT91Bootstrap Loader

To load the application binary onto the target device, we need to use at91bootstrap loader. Refer to the at91bootstrap loader documentation for details on how to configure, build and run bootstrap loader project and use it to bootstrap the application binaries.

## Setting Up the Hardware

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

Project Name | Description
--- | ---
sam_a7d65_curiosity.X | SAMA7D65 Curiosity Board
sam_a7d65_curiosity_pro.X | SAMA7D65 Curiosity Pro Board

### Setting Up SAMA7D65 Curiosity Development Board

Additional hardware required:

- Connect https://www.mikroe.com/lin-click into mikroBUS 1 socket
- Connect the USB port J3 on board to the computer using a micro USB cable (to power the board)

Setting up the board:

- The hardware setup requires two boards, one acting as the LIN Host and the other as the LIN Client
- Used pins, for information purpose:

  mikroBUS | LIN Click | SAMA7D65 Curiosity
  --- | --- | ---
  GND | GND | -
  CS | LIN_EN | PA15
  TX | RXD | PD8
  RX | TXD | PD9
  +3.3V | +3.3V | -
  +5V | +5V | For host only

- The host node should be enabled by the proper configuration of the MODE resistor on the click board
- Connect a wire from VS on the LIN Host click board to 5V
- Connect a wire from BUS on the LIN Host click board to BUS on the LIN Client click board
- Connect a wire from GND on the LIN Host click board to GND on the LIN Client click board
- Connect a wire from VS on the LIN Host click board to VS on the LIN Client click board
- Connect the Debug USB port on the board to the computer using a micro USB cable

### Setting Up SAMA7D65 Curiosity Development Pro Board

Additional hardware required:

- Connect https://www.mikroe.com/lin-click into mikroBUS 1 socket
- Connect the USB port J1 on board to the computer using a micro USB cable (to power the board)

Setting up the board:

- The hardware setup requires two boards, one acting as the LIN Host and the other as the LIN Client
- Used pins, for information purpose:

  mikroBUS | LIN Click | SAMA7D65 Curiosity
  --- | --- | ---
  GND | GND | -
  CS | LIN_EN | PA15
  TX | RXD | PD8
  RX | TXD | PD9
  +3.3V | +3.3V | -
  +5V | +5V | For host only

- The host node should be enabled by the proper configuration of the MODE resistor on the click board
- Connect a wire from VS on the LIN Host click board to 5V
- Connect a wire from BUS on the LIN Host click board to BUS on the LIN Client click board
- Connect a wire from GND on the LIN Host click board to GND on the LIN Client click board
- Connect a wire from VS on the LIN Host click board to VS on the LIN Client click board
- Connect the Debug USB port on the board to the computer using a micro USB cable

## Running the Application

1. Open the Terminal application (Ex.: Tera Term) on the computer.
2. Connect to the USB Serial COM port and configure the serial settings as follows:
   - Baud: 115200
   - Data: 8 Bits
   - Parity: None
   - Stop: 1 Bit
   - Flow Control: None
3. Build and Program the application using its IDE.
4. The LIN host device communicates with a LIN client device every second to monitor the status of a LED and a switch. The client device sends a data byte indicating the states of both components. The host device evaluates the switch's status: if released, it toggles the LED's state and instructs the client to update the LED. If the switch is pressed, the host activates its own LED without changing the client's LED state.

Rev: C