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

Universal asynchronous receiver transmitter (UART)

RM0016

 

 

22.4.2Slave mode with automatic resynchronization disabled

Note:

This feature is only available in UART2, UART3 and UART4.

 

UART initialization

Procedure:

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

2.Enable transmitter and receiver by setting TEN and REN bits in UART_CR2 register,

3.Enable LSLV bit in UART_CR6 register,

4.Enable LIN mode by setting LINEN bit in UART_CR3 register,

LIN Header reception

According to the LIN protocol, a slave node must wait for a valid header, coming from the master node. Then application has to take following action, depending on the header Identifier value:

Receive the response

Transmit the response

Ignore the response and wait for next header

When a LIN Header is received:

The LHDF flag in the UART_CR6 register indicates that a LIN Header has been detected.

An interrupt is generated if the LHDIEN bit in the UART_CR6 register is set.

The LIN Identifier is available in the UART_DR register.

Note:

It is recommended to put UART in mute mode by setting RWU bit. This mode allows

 

detection of headers only and prevents the reception of any other characters.

 

Setting the PCEN bit in the UART_CR2 register while LIN is in slave mode enables the

 

Identifier parity check. The PE flag in the UART_CR6 register is set together with the LHDF

 

flag in the UART_CR6 register if the Identifier parity is not correct.

 

Response transmission (slave is the publisher of the response)

In order to send n data bytes, the application must repeat following sequence n times:

1.Write data in the UART_DR register

2.Wait for the RXNE flag in the UART_SR register

3.Check for readback value by reading the UART_DR register

Once response transmission is completed, software can set the RWU bit.

Response reception (slave 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

Once response reception is completed, software can set the RWU bit.

338/454

Doc ID 14587 Rev 9

RM0016

Universal asynchronous receiver transmitter (UART)

 

 

Discard response

Software can set the RWU bit immediately.

LIN Slave parity

In LIN Slave mode (LINEN and LSLV bits are set) LIN parity checking can be enabled by setting the PCEN bit. An interrupt is generated if an ID parity error occurs (PE bit rises) and the PIEN bit is set.

In this case, the parity bits of the LIN Identifier Field are checked. The identifier character is recognized as the third received character after a break character (included):

Figure 132. LIN identifier field parity bits

parity bits

LIN Break

LIN Synch

Identifier

 

Field

Field

The bits involved are the two MSB positions (7th and 8th bits) of the identifier character. The check is performed as specified by the LIN specification:

Figure 133. LIN identifier field parity check

start bit

 

 

 

 

parity bits

stop bit

 

 

 

 

 

 

 

 

 

 

 

identifier bits

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ID0

ID1

ID2

ID3

ID4

ID5

P0

P1

 

Identifier Field

P0= ID0 ID1 ID2 ID4

M = 0

P1= ID1 ID3 ID4 ID5

LIN header error detection

The LIN Header Error Flag indicates that an invalid LIN Header has been detected.

When a LIN Header Error occurs:

The LHE flag is set

An interrupt is generated if the RIEN bit in the UART_CR2 register is set.

The LHE bit is reset by an access to the UART_SR register followed by a read of the UART_DR register.

Doc ID 14587 Rev 9

339/454

Universal asynchronous receiver transmitter (UART)

RM0016

 

 

 

 

LHE is set if one of the following conditions occurs:

 

 

Break Delimiter is too short

 

 

Synch Field is different from 55h

 

 

Framing error in Synch Field or Identifier Field

 

 

A LIN header reception time-out

 

Note:

If a LIN header error occurs, the LSF bit in the UART_CR6 register must be cleared by

 

software

 

LIN header time-out error

The UART automatically monitors the THEADER_MAX condition given by the LIN protocol.

If the entire Header (up to and including the STOP bit of the LIN Identifier Field) is not received within the maximum time limit of 57 bit times then a LIN Header Error is signaled and the LHE bit is set in the UART_SR register.

Figure 134. LIN header reception time-out

LIN Synch

LIN Synch

Identifier

Break

Field

Field

THEADER

The time-out counter is enabled at each break detection. It is stopped in the following conditions:

A LIN Identifier Field has been received

An LHE error occurred (other than a time-out error).

A software reset of LSF bit (transition from high to low) occurred during the analysis of the LIN Synch Field

If LHE bit is set due to this error during the LIN Synch Field (if LASE bit = 1) then the UART goes into a blocked state (the LSF bit is set).

If LHE bit is set due to this error during Fields other than LIN Synch Field or if LASE bit is reset then the current received Header is discarded and the UART searches for a new Break Field.

Note on LIN Header time-out limit

According to the LIN specification, the maximum length of a LIN Header which does not cause a time-out is equal to:

1.4 * (34 + 1) = 49 TBIT_MASTER.

TBIT_MASTER refers to the master baud rate.

340/454

Doc ID 14587 Rev 9

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