Jump to main content

# 1.13 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 5.

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

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

Project Name | Description
--- | ---
sam_9x75_curiosity.X | MPLABX project for SAM9X75 Curiosity Development 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_9x75_curiosity.X | SAM9X75 Curiosity Development Board

### Setting Up SAM9X75 Curiosity Development Board

Additional hardware required:

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

Setting up the board:

- Connect a programming cable from JTAG connector J12 on board to programmer(J-32 Debugger)
- Connect programmer(J-32 Debugger) to computer using a micro USB cable
- Connect the USB port J1 on board to the computer using a micro USB cable (to power the board)
- The hardware setup requires two boards, one acting as the LIN Host and the other as the LIN Client
- Connect the LIN Click board to the mikroBUS socket on the board
- Used pins, for information purpose:

  mikroBUS | LIN Click | 9x75 Curiosity
  --- | --- | ---
  GND | GND | -
  CS | LIN_EN | PC24
  TX | RXD | PA28
  RX | TXD | PA29
  +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 SAM9X75 Curiosity Pro Development Board

Additional hardware required:

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

Setting up the board:

- Connect a programming cable from JTAG connector J64 on board to programmer(J-32 Debugger)
- Connect programmer(J-32 Debugger) to computer using a micro USB cable
- 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 | 9x75 Curiosity
  --- | --- | ---
  GND | GND | -
  CS | LIN_EN | PC19
  TX | RXD | PA28
  RX | TXD | PA29
  +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

## 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: E