20.4.2.2 LIN/J2602
The UART provides support for the Local Interconnect Network (LIN) protocol for both Commander and Responder processes to reduce software overhead. The LIN protocol is typically used in automotive applications and packages bytes into message frames. The LIN protocol has two types of processes: Commander and Responder. A network can have only one Commander and multiple Responders. The Commander process transmits a header containing a command that the Responder(s) can respond to. The Commander process part of a LIN message frame consists of the following:
- Break character (11 bits minimum received, 13 transmitted)
- Delimiter bit
- Sync byte (0x55)
- Protected ID (PID) field
The Responder processes, then completes, the message frame by transmitting the requested data and checksum.
- Data (up to eight bytes)
- Checksum
The UART has two LIN modes, Commander/Responder and Responder Only, selected by the MODE[3:0] bits (UxCON[3:0]). The Commander/Responder mode allows a single instance of a UART to handle both Commander and Responder software processes.
A LIN frame starts with the Commander process sending a Break, followed by a Sync to allow the receiver to synchronize the baud rate to the transmitter. The PID byte follows and is used by the Responder to determine if, or how, to respond. A Responder process then responds with up to eight bytes of data and a checksum. A LIN frame is shown in Figure 20-13.
The PID byte consists of six bits of data and two parity bits, P0 followed by P1. The PID value is written to Parameter 1 (P1[5:0]), and the parity bits are automatically calculated. Parameter 1 can only be written when the transmitter is Idle. The parity bits are calculated as follows:
P0 = PID[0] XOR PID[1] XOR PID[2] XOR PID[4] P1 = NOT (PID[1] XOR PID[3] XOR PID[4] XOR PID[5]) |
The UART automatically calculates the checksum. Two types of LIN checksums
are supported and selected by the C0EN bit (UxCON[19]). When C0EN = 0
(default), the legacy LIN checksum method is used, which uses only data bytes. When C0EN =
1
, the checksum also includes the PID. The checksum is calculated by
adding the number of data bytes, defined by Parameter 2, adding the carry result and
finally inverting the sum.
Table 20-7 provides an example checksum calculation for a LIN frame of four data bytes in length, with data values of 0x4A, 0x55, 0x93 and 0xE5.
Action | Hex | Carry | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
---|---|---|---|---|---|---|---|---|---|---|
0x4A | 0x4A | 0 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | |
+0x55 Add Carry | 0x9F 0x9F | 0 | 1 1 | 0 0 | 0 0 | 1 1 | 1 1 | 1 1 | 1 1 | 1 1 |
+0x93 Add Carry | 0x132 0x33 | 1 | 0 0 | 0 0 | 1 1 | 1 1 | 0 0 | 0 0 | 1 1 | 0 1 |
+0xE5 Add Carry | 0x118 0x19 | 1 | 0 0 | 0 0 | 0 0 | 1 1 | 1 1 | 0 0 | 0 0 | 0 1 |
Invert | 0xE6(1) | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | |
Receiver Verification | ||||||||||
Check Local + Received | 0x19(2)+0xE6(1) |
- This is the checksum value transmitted as the last byte.
- This is the checksum value calculated by the receiver.
For a transmit and receive operation, the calculated checksum is stored in UxCHK.