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

RM0016

Universal asynchronous receiver transmitter (UART)

 

 

22.3.2Transmitter

The transmitter can send data words of either 8 or 9 bits depending on the M bit status. When the M bit is set, word length is 9 bits and the 9th bit (the MSB) has to be stored in the T8 bit in the UART_CR1 register.

When the transmit enable bit (TEN) is set, the data in the transmit shift register is output on the UART_TX pin and the corresponding clock pulses are output on the UART_CK pin.

Character transmission

During an UART transmission, data shifts out least significant bit first on the UART_TX pin. In this mode, the UART_DR register consists of a buffer (TDR) between the internal bus and the transmit shift register (see Figure 110).

Every character is preceded by a start bit which is a logic level low for one bit period. The character is terminated by a configurable number of stop bits.

The following stop bits are supported by UART.

Note: 1 The TEN bit should not be reset during transmission of data.Resetting the TEN bit during the transmission will corrupt the data on the UART_TX pin as the baud rate counters will get frozen.The current data being transmitted will be lost.

2An idle frame will be sent after the TEN bit is enabled.

Configurable stop bits

The number of stop bits to be transmitted with every character can be programmed in Control register 3, bits 5,4.

1 stop bit: This is the default value of number of stop bits.

2 Stop bits: This is supported by normal mode UART.

1.5 Stop bits: To be used in Smartcard mode only.

 

An idle frame transmission will include the stop bits.

 

A break transmission consists of 10 low bits followed by the configured number of stop bits

 

(when m = 0) and 11 low bits followed by the configured number of stop bits (when m = 1). It

 

is not possible to transmit long breaks (break of length greater than 10/11 low bits).

Note:

In LIN mode (see Section 22.3.8 on page 326), a standard 13-bit break is always generated.

Doc ID 14587 Rev 9

315/454

Universal asynchronous receiver transmitter (UART)

RM0016

 

 

Figure 115. Configurable stop bits

8-bit Word length (M bit is reset)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Possible

 

Next Data Frame

 

 

 

 

 

 

 

Data Frame

 

 

 

 

Parity

 

 

 

 

 

 

 

Start

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Bit

 

Next

 

 

Bit0

Bit1

Bit2

Bit3

Bit4

Bit5

Bit6

 

 

Bit7

 

Stop

Start

 

 

 

 

 

Bit

 

 

 

Bit

Bit

 

 

 

CLOCK

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

****

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

**

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

** LBCL bit controls last data clock pulse

a) 1 Stop Bit

 

 

 

 

 

 

 

 

 

 

 

 

Possible

 

 

 

Next Data Frame

 

 

 

 

 

Data Frame

 

 

 

 

Parity

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Bit

 

 

 

Next

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Start

Bit0

 

Bit1

Bit2

 

Bit3

Bit4

Bit5

Bit6

 

Bit7

 

 

 

Start

 

 

 

 

Bit

 

 

 

 

 

 

Bit

 

 

 

 

b) 1 1/2 stop Bits *

 

 

 

 

 

 

 

 

 

1 1/2 stop bits

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Possible

 

 

 

Next Data Frame

 

 

 

 

 

Data Frame

 

 

 

 

 

Parity

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Bit

 

 

 

 

Next

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Start

Bit0

 

Bit1

Bit2

 

Bit3

Bit4

Bit5

Bit6

 

Bit7

2 Stop

 

Start

 

 

 

 

 

Bit

 

 

 

Bits

 

 

Bit

 

 

 

c) 2 Stop Bits

Procedure:

1.Program the M bit in UART_CR1 to define the word length.

2.Program the number of stop bits in UART_CR3.

3.Select the desired baud rate by programming the baud rate registers in the following order:

a)UART_BRR2

b)UART_BRR1

4.Set the TEN bit in UART_CR2 to enable transmitter mode.

5.Write the data to send in the UART_DR register (this clears the TXE bit). Repeat this for each data to be transmitted in case of single buffer.

6.Once the last data is written to the UART_DR register, wait until TC is set to ‘1’, which indicates that the last data transmission is complete. This last step is required, for instance, to avoid last data transmission corruption when disabling the UART or entering Halt mode.

316/454

Doc ID 14587 Rev 9

RM0016

Universal asynchronous receiver transmitter (UART)

 

 

Single byte communication

Clearing the TXE bit is always performed by a write to the data register.

The TXE bit is set by hardware and it indicates:

The data has been moved from TDR to the shift register and the data transmission has started.

The TDR register is empty.

The next data can be written in the UART_DR register without overwriting the previous data.

This flag generates an interrupt if the TIEN bit is set.

When a transmission is taking place, a write instruction to the UART_DR register stores the data in the TDR register. The data is copied in the shift register at the end of the current transmission.

When no transmission is taking place, a write instruction to the UART_DR register places the data directly in the shift register, the data transmission starts, and the TXE bit is immediately set.

If a frame transmission is complete (after the stop bit) and the TXE bit is set, the TC bit is set. An interrupt is generated if the TCIEN is set in the UART_CR2 register. After writing the last data in the UART_DR register, it is mandatory to wait until TC is set to ‘1’ before entering Halt mode or disabling the UART (see Figure 116: TC/TXE behavior when transmitting).

The following software sequence is required to clear the TC bit:

1.Read from the UART_SR register

2.Write to the UART_DR register

Figure 116. TC/TXE behavior when transmitting

 

Idle preamble

Frame 1

 

Frame 2

 

Frame 3

TX line

 

 

 

 

 

 

 

 

 

Set by hardware and

 

Set by hardware and

 

 

 

TXE flag

 

cleared by software

 

cleared by software

Set by hardware

 

USART_DR

F1

F2

 

F3

 

 

 

TC flag

 

 

 

 

 

 

 

Software

Software waits until TXE = 1

 

TC is not set

TC is not set

TC is

set because

enables the

 

and writes F2 into DR

because TXE = 0

because TXE = 0

 

TXE = 1

USART

 

 

 

 

 

 

 

 

Software waits until TXE = 1

Software waits until TXE = 1

 

Software waits until TC = 1

 

 

and writes F1 into DR

and writes F3 into DR

 

 

 

 

 

Set

by hardware

 

ai17121b

 

 

 

1. This example assumes that several other transmissions occur after TE has been set.

Note:

The TC bit can also be cleared by writing a ‘0’ to it. This clear sequence is recommended

 

only for multibuffer communication.

Doc ID 14587 Rev 9

317/454

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