Electronic Design

Drive Local Interconnect Network With PC-Type UART Device

A new single-wire serial communication system, called the Local Interconnect Network (LIN), is intended for electronic control units in vehicles (www.lin-subbus.org). Using a PC UART for LIN provides a convenient and low-cost solution for developing and testing LIN devices.

Excluding the wakeup signal, a LIN message begins with a Break Marker of at least 13 bits and a Stop Marker of 1 bit or more, followed by a standard 8N1-coding data stream. Generally, a low-level driver is needed to access the UART hardware and interrupts to generate a startup signal that's compliant with the timing constraints defined by the LIN specification. The technique used here generates the signal via the standard Microsoft VCOMM driver.

The circuit in the figure is based on a modified K-Line interface. It's connected to a standard PC COM port. Two D-type flip-flops (IC4A and IC4B) are connected in series and used as a delay line to generate the startup signal. The TXD signal supplies both the LIN data and the delay line's clock. Diodes D2 and D3, plus resistor R2, form an AND gate, so that either TXD or IC4B can pull the LIN bus low.

The PC starts the LIN message by toggling the RTS line to reset both the D-type flip-flops that pull the LIN bus low. Next, TXD immediately starts transmission. The first two bytes are used to shift 1s through both D-type flip-flops, so that a proper startup signal is generated. Then the LIN bus is controlled only by the TXD signal after the second byte has been transmitted. The timing of the LIN messages is well maintained by the standard VCOMM driver at any baud rate.

The following procedure demonstrates how to implement a LIN master using Win32 API functions. The COM port is initialized in the following steps:

  1. Open the COM port by calling CreateFile.
  2. Initialize the COM port by calling SetupComm.
  3. Set up the COM port by calling SetCommState, SetCommTimeouts.
  4. Set and then clear RTS by calling EscapeCommFunction to reset both D-type flip-flops to 0.
  5. Send 0xDF, which includes two rising edges, to TXD by calling WriteFile and FlushFileBuffers. Then both D-type flip-flops are set to 1, and the LIN bus becomes 1.

The LIN message header is generated by the following COM port manipulations (see the waveforms in the figure):

  1. Enter the "Critical Section" to prevent the long delays caused by switching to other threads.
  2. Set and then clear RTS by calling EscapeCommFunction to reset both D-type flip-flops to 0.
  3. Send 0xF0, 0xF0, 0x55, and LIN message ID to TXD by calling WriteFile and FlushFileBuffers. This generates a 15-bit break marker, followed by a 5-bit stop marker, and 0x55, and the ID.
  4. Leave the "Critical Section" to avoid blocking other threads.
  5. Read back the received data to empty the receiving buffer and verify the data sent. Only three bytes—0 (break), 0x55, and ID—are available.
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.