Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
181
Добавлен:
01.03.2016
Размер:
3.56 Mб
Скачать

Universal asynchronous receiver transmitter (UART)

RM0016

 

 

22.4LIN mode functional description

In LIN mode, 8-bit data format with 1 stop bit is required in accordance with the LIN standard.

To configure these settings, clear the M bit in UART_CR1 register and clear the STOP[1:0] bits in the UART_CR3 register.

22.4.1Master mode

UART initialization

Procedure:

1.Select the desired baudrate by programming the UART_BRR2 and UART_BRR1 registers.

2.Enable LIN mode by setting the LINEN bit in the UART_CR3 register.

3.Enable the transmitter and receiver by setting the TEN and REN bits in the UART_CR2 register.

LIN header transmission

According to the LIN protocol, any communication on the LIN bus is triggered by the Master sending a Header, followed by the response. The Header is transmitted by the Master Task (master node) while the data are transmitted by the Slave task of a node (master node or one of the slave nodes).

Procedure without error monitoring:

1.Request Break + Delimiter transmission (13 dominant bits and 1 recessive bit) by setting the SBK bit in the UART_CR2 register.

2.Request Synch Field transmission by writing 0x55 in the UART_DR register.

3.Wait for the TC flag in the UART_SR register.

4.Request Identifier Field transmission by writing the protected identifier value in the UART_DR register.

5.Wait for the TC flag in the UART_SR register.

Procedure with error monitoring:

1.Request Break + Delimiter transmission (13 dominant bits and 1 recessive bit) by setting the SBK bit in the UART_CR2 register;

2.Wait for the LBDF flag in the UART_CR4 register.

3.Request Synch Field transmission by writing 0x55 into UART_DR register.

4.Wait for the RXNE flag in the UART_SR register and read back the UART_DR register.

5.Request Identifier Field transmission by writing the protected identifier value in the UART_DR register.

6.Wait for the RXNE flag in the UART_SR register and read back the UART_DR register.

The LBDF flag is set only if a valid Break + Delimiter has been received back on the UART_RX pin.

334/454

Doc ID 14587 Rev 9

RM0016

Universal asynchronous receiver transmitter (UART)

 

 

LIN break and delimiter detection

The UART features a break detection circuit which is totally independent from the normal UART receiver. A break can be detected whenever it occurs, during idle state or during a frame.

When the receiver is enabled (REN=1 in UART_CR2), the circuit looks at the UART_RX input for a start signal. The method for detecting start bits is the same when searching break characters or data. After a start bit has been detected, the circuit samples the next bits exactly like for the data (on the 8th, 9th and 10th samples). If 10 bits (when the LBDL = 0 in UART_CR4) or 11 bits (when LBDL=1 in UART_CR4) are detected as ‘0’, and are followed by a delimiter character, the LBDF flag is set in UART_CR4. If the LBDIEN bit=1, an interrupt is generated.

If a ‘1’ is sampled before the 10 or 11 have occurred, the break detection circuit cancels the current detection and searches for a start bit again. If LIN mode is disabled (LINEN=0), the receiver continues working as a normal UART, without taking into account the break detection.

If LIN mode is enabled (LINEN=1), as soon as a framing error occurs (i.e. stop bit detected at ‘0’, which will be the case for any break frame), the receiver stops until the break detection circuit receives either a ‘1’, if the break word was not complete, or a delimiter character if a break has been detected.

The behavior of the break detector state machine and the break flag is shown in Figure 130: Break detection in LIN mode (11-bit break length - LBDL bit is set) on page 336.

The LBDF flag is used in master mode, in slave mode the LHDF flag is used instead.

Examples of break frames are given on Figure 131: Break detection in LIN mode vs framing error detection on page 337.

Doc ID 14587 Rev 9

335/454

Universal asynchronous receiver transmitter (UART)

RM0016

 

 

Figure 130. Break detection in LIN mode (11-bit break length - LBDL bit is set)

Case 1: break signal not long enough => break discarded, LBDF is not set

RX line

 

 

 

 

“Short” Break Frame

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Capture Strobe

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Break State machine

Idle

Bit0

Bit1

Bit2

Bit3

Bit4

Bit5

Bit6

Bit7

 

Bit8

Bit9

Bit10

 

 

Idle

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Read Samples

 

0

 

0

0

0

0

0

0

0

 

0

0

1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

delimiter

 

 

 

 

 

 

Case 2: break signal just long enough => break detected, LBDF is set

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Break Frame

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

RX line

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Capture Strobe

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

delimiter is immediate

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Break State machine

 

Idle

Bit0

Bit1

Bit2

Bit3

Bit4

Bit5

Bit6

Bit7

 

Bit8

Bit9

B10

 

 

 

 

Idle

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Read Samples

 

0

 

0

0

0

0

0

0

0

 

0

0

0

 

 

 

 

 

 

 

 

LBDF

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Case 3: break signal long enough => break detected, LBDF is set

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Break Frame

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

RX line

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Capture Strobe

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Break State machine

 

Idle

Bit0

Bit1

Bit2

Bit3

Bit4

Bit5

Bit6

Bit7

 

Bit8

Bit9

Bit10

 

wait delimiter

delimiter

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Read Samples

 

0

 

0

0

0

0

0

0

0

 

0

0

0

 

 

 

 

 

 

 

 

LBDF

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

336/454

Doc ID 14587 Rev 9

RM0016

Universal asynchronous receiver transmitter (UART)

 

 

Figure 131. Break detection in LIN mode vs framing error detection

In these examples, we suppose that LBDL=1 (11-bit break length), M=0 (8-bit data)

Case 1: break occurring after an Idle

RX line

 

 

data 1

IDLE

 

BREAK

 

data2 (0x55)

data 3 (header)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1 data time

 

1 data time

 

RXNE / FE

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LBDF

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Case 2: break occurring while a data is being received

RX line

 

 

data 1

data 2

 

 

BREAK

 

data2 (0x55)

data 3 (header)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1 data time

 

 

1 data time

 

RXNE / FE

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LBDF

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Response transmission (master is the publisher of the response)

The response is composed of bytes with a standard UART format: 8-bit data, 1 stop bit, no parity.

In order to send n data bytes, the application must repeat the following sequence n times: 1. Write data in UART_DR register

2. Wait for RXNE flag in UART_SR register

3. Check for readback value by reading the UART_DR register

Response reception (master is the subscriber of the response)

In order to receive n data bytes, the application must repeat following sequence n times: 1. Wait for the RXNE flag in the UART_SR register

2. Read the UART_DR register

 

Discard response (slave to slave communication)

 

In case of slave to slave communication and if the master does not need to check errors in

 

the response, the application can ignore the RXNE flag till the next frame slot. The RXNE

 

and OR flags should be cleared before starting the next Break transmission.

Note:

Receiving back a Break will also set the RXNE and FE flags before setting the LBDF flag.

 

Therefore, if the RX interrupt is used, it's better to disable it (by clearing the RIEN bit in the

 

UART_CR2 register) before sending the Break, to avoid an additional interrupt. In case of

 

slave to slave communication, RIEN bit can be cleared once the header has been

 

transmitted.

Doc ID 14587 Rev 9

337/454

Соседние файлы в папке Минимум документации STM8_1