19. Universal synchronous asynchronous receiver transmitter (USART)

19.1 USART introduction

The universal synchronous asynchronous receiver transmitter (USART) offers a flexible means of full-duplex data exchange with external equipment requiring an industry standard NRZ asynchronous serial data format. The USART offers a very wide range of baud rates using a fractional baud rate generator.

It supports synchronous one-way communication and half-duplex single wire communication. It also supports the LIN (local interconnection network), Smartcard Protocol and IrDA (infrared data association) SIR ENDEC specifications, and modem operations (CTS/RTS). It allows multiprocessor communication.

High speed data communication is possible by using the DMA for multibuffer configuration.

19.2 USART main features

19.3 USART functional description

The interface is externally connected to another device by three pins (see Figure 167 ). Any USART bidirectional communication requires a minimum of two pins: Receive Data In (RX) and Transmit Data Out (TX):

RX: Receive Data Input is the serial data input. Oversampling techniques are used for data recovery by discriminating between valid incoming data and noise.

TX: Transmit Data Output. When the transmitter is disabled, the output pin returns to its I/O port configuration. When the transmitter is enabled and nothing is to be transmitted, the TX pin is at high level. In single-wire and smartcard modes, this I/O is used to transmit and receive the data (at USART level, data are then received on SW_RX).

Through these pins, serial data is transmitted and received in normal USART mode as frames comprising:

Refer to Section 19.6: USART registers on page 544 for the definitions of each bit.

The following pin is required to interface in synchronous mode:

The following pins are required in Hardware flow control mode:

Figure 167. USART block diagram

Detailed block diagram of the USART showing internal components like registers (TDR, RDR), shift registers, control units, and the baud rate generator. It includes external pins for TX, RX, RTS, CTS, and IrDA signals, as well as internal control registers (CR1, CR2, CR3, GTPR) and their bit fields.

The diagram illustrates the internal architecture of the USART. At the top, the Transmit data register (TDR) and Receive data register (RDR) are shown, which interface with the CPU or DMA via PWDATA (Write) and PRDATA (Read). These registers connect to Transmit and Receive Shift Registers . The IrDA SIR ENDEC block handles TX , RX , SW_RX , IrDA_OUT , and IrDA_IN signals. A Hardware flow controller manages RTS and CTS signals. Control registers CR1 , CR2 , CR3 , and GTPR configure the USART's operation. CR1 includes bits for TXEIE, TCIE, RXNEIE, IDLEIE, TE, RE, RWU, and SBK. CR2 includes USART Address, UE, M, WAKE, PCE, PS, and PEIE. CR3 includes DMAT, DMAR, SCEN, NACK, HD, IRLP, and IREN. GTPR includes GT and PSC. The SCLK control block generates the CK signal. The Transmit control , Wake-up unit , and Receiver control blocks manage the data flow. The USART interrupt control block generates interrupts based on the SR (Status Register) flags: CTS, LBD, TXE, TC, RXNE, IDLE, ORE, NF, FE, and PE. The USART_BRR block contains the Transmitter rate control and Receiver rate control , which are configured by DIV_Mantissa and DIV_Fraction registers. The baud rate is calculated using the formula:

\[ \text{USARTDIV} = \text{DIV\_Mantissa} + (\text{DIV\_Fraction} / 8 \times (2 - \text{OVER8})) \]

The SAMPLING DIVIDER is calculated as \( / [8 \times (2 - \text{OVER8})] \) . The /USARTDIV register is derived from the \( f_{PCLKx}(x=1,2) \) clock frequency.

Detailed block diagram of the USART showing internal components like registers (TDR, RDR), shift registers, control units, and the baud rate generator. It includes external pins for TX, RX, RTS, CTS, and IrDA signals, as well as internal control registers (CR1, CR2, CR3, GTPR) and their bit fields.

ai16099b

19.3.1 USART character description

Word length may be selected as being either 8 or 9 bits by programming the M bit in the USART_CR1 register (see Figure 168 ).

The TX pin is in low state during the start bit. It is in high state during the stop bit.

An Idle character is interpreted as an entire frame of “1”s followed by the start bit of the next frame which contains data (The number of “1”s includes the number of stop bits).

A Break character is interpreted on receiving “0”s for a frame period. At the end of the break frame the transmitter inserts either 1 or 2 stop bits (logic “1” bit) to acknowledge the start bit.

Transmission and reception are driven by a common baud rate generator, the clock for each is generated when the enable bit is set respectively for the transmitter and receiver.

The details of each block is given below.

Figure 168. Word length programming

Timing diagrams for 9-bit and 8-bit word length USART communication.

The diagram illustrates the timing for two word lengths: 9-bit and 8-bit, both with 1 stop bit.

9-bit word length (M bit is set), 1 Stop bit

The top diagram shows the timing for a 9-bit word length. It includes a 'Data frame' consisting of a 'Start bit', 9 data bits (Bit0 through Bit8), a 'Possible Parity bit', and a 'Stop bit'. Below the data frame is an 'Idle frame' (a continuous high state) and a 'Break frame' (a continuous low state). The 'Next data frame' begins with a 'Start bit'. A 'Clock' signal is shown as a series of pulses. A note indicates that the 'LBCL bit controls last data clock pulse'.

8-bit word length (M bit is reset), 1 Stop bit

The bottom diagram shows the timing for an 8-bit word length. It includes a 'Data frame' consisting of a 'Start bit', 8 data bits (Bit0 through Bit7), a 'Possible Parity bit', and a 'Stop bit'. Below the data frame is an 'Idle frame' (a continuous high state) and a 'Break frame' (a continuous low state). The 'Next data frame' begins with a 'Start bit'. A 'Clock' signal is shown as a series of pulses. A note indicates that the 'LBCL bit controls last data clock pulse'.

MS19822V2

Timing diagrams for 9-bit and 8-bit word length USART communication.

19.3.2 Transmitter

The transmitter can send data words of either 8 or 9 bits depending on the M bit status. When the transmit enable bit (TE) is set, the data in the transmit shift register is output on the TX pin and the corresponding clock pulses are output on the CK pin.

Character transmission

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

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 USART: 0.5, 1, 1.5 and 2 stop bits.

Note: The TE bit should not be reset during transmission of data. Resetting the TE bit during the transmission corrupts the data on the TX pin as the baud rate counters get frozen. The current data being transmitted are lost.

An idle frame is sent after the TE bit is enabled.

Configurable stop bits

The number of stop bits to be transmitted with every character can be programmed in Control register 2, bits 13,12.

An idle frame transmission includes the stop bits.

A break transmission is 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).

Figure 169. Configurable stop bits

Figure 169. Configurable stop bits. The diagram shows four examples (a, b, c, d) of data frames with different stop bit configurations. Each frame consists of a Start Bit, 8 data bits (Bit0-Bit7), a Possible parity bit, Stop bits, and a Next start bit. A CLOCK signal is shown below the frames. a) 1 Stop Bit: Standard frame with one stop bit. b) 1 1/2 stop Bits: Frame with one stop bit and a half stop bit (indicated by an arrow). c) 2 Stop Bits: Frame with two stop bits. d) 1/2 Stop Bit: Frame with a half stop bit (indicated by an arrow). A note indicates that the LBCL bit controls the last data clock pulse. The diagram is labeled MSV42088V1.

8-bit Word length (M bit is reset)

CLOCK

Data frame

Possible parity bit

Next data frame

** LBCL bit controls last data clock pulse

a) 1 Stop Bit

Data frame

Possible Parity Bit

Next data frame

1 1/2 stop bits

b) 1 1/2 stop Bits

Data frame

Possible parity bit

Next data frame

c) 2 Stop Bits

Data frame

Possible parity bit

Next data frame

d) 1/2 Stop Bit

1/2 Stop Bit

MSV42088V1

Figure 169. Configurable stop bits. The diagram shows four examples (a, b, c, d) of data frames with different stop bit configurations. Each frame consists of a Start Bit, 8 data bits (Bit0-Bit7), a Possible parity bit, Stop bits, and a Next start bit. A CLOCK signal is shown below the frames. a) 1 Stop Bit: Standard frame with one stop bit. b) 1 1/2 stop Bits: Frame with one stop bit and a half stop bit (indicated by an arrow). c) 2 Stop Bits: Frame with two stop bits. d) 1/2 Stop Bit: Frame with a half stop bit (indicated by an arrow). A note indicates that the LBCL bit controls the last data clock pulse. The diagram is labeled MSV42088V1.

Procedure:

  1. 1. Enable the USART by writing the UE bit in USART_CR1 register to 1.
  2. 2. Program the M bit in USART_CR1 to define the word length.
  3. 3. Program the number of stop bits in USART_CR2.
  4. 4. Select DMA enable (DMAT) in USART_CR3 if Multi buffer Communication is to take place. Configure the DMA register as explained in multibuffer communication.
  5. 5. Select the desired baud rate using the USART_BRR register.
  6. 6. Set the TE bit in USART_CR1 to send an idle frame as first transmission.
  7. 7. Write the data to send in the USART_DR register (this clears the TXE bit). Repeat this for each data to be transmitted in case of single buffer.
  8. 8. After writing the last data into the USART_DR register, wait until TC=1. This indicates that the transmission of the last frame is complete. This is required for instance when the USART is disabled or enters the Halt mode to avoid corrupting the last transmission.

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:

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

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

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

If a frame is transmitted (after the stop bit) and the TXE bit is set, the TC bit goes high. An interrupt is generated if the TCIE bit is set in the USART_CR1 register.

After writing the last data into the USART_DR register, it is mandatory to wait for TC=1 before disabling the USART or causing the microcontroller to enter the low-power mode (see Figure 170: TC/TXE behavior when transmitting ).

The TC bit is cleared by the following software sequence:

  1. 1. A read from the USART_SR register
  2. 2. A write to the USART_DR register

Note: The TC bit can also be cleared by writing a '0' to it. This clearing sequence is recommended only for Multibuffer communication.

Figure 170. TC/TXE behavior when transmitting

Timing diagram showing the relationship between the TX line, TXE flag, USART_DR register, and TC flag during frame transmission. The diagram illustrates the sequence of events for three frames (Frame 1, Frame 2, Frame 3) following an idle preamble. The TX line shows the physical transmission of frames. The TXE flag is set by hardware when the shift register is empty and cleared by software when a new frame is written. The USART_DR register holds the data to be transmitted. The TC flag is set by hardware when the last stop bit of a frame is transmitted and cleared by software when the shift register is empty. The diagram shows that the TC flag is not set if the TXE flag is still set (i.e., if a new frame is written before the previous one is fully transmitted). The software sequence for enabling the USART and writing the first frame is: 'Software enables the USART' followed by 'Software waits until TXE=1 and writes F1 into DR'. For subsequent frames, the sequence is: 'Software waits until TXE=1 and writes F2 into DR' (or F1 into DR). After the last frame (F3) is written, the software must wait until TC=1 before disabling the USART or entering low-power mode.
Timing diagram showing the relationship between the TX line, TXE flag, USART_DR register, and TC flag during frame transmission. The diagram illustrates the sequence of events for three frames (Frame 1, Frame 2, Frame 3) following an idle preamble. The TX line shows the physical transmission of frames. The TXE flag is set by hardware when the shift register is empty and cleared by software when a new frame is written. The USART_DR register holds the data to be transmitted. The TC flag is set by hardware when the last stop bit of a frame is transmitted and cleared by software when the shift register is empty. The diagram shows that the TC flag is not set if the TXE flag is still set (i.e., if a new frame is written before the previous one is fully transmitted). The software sequence for enabling the USART and writing the first frame is: 'Software enables the USART' followed by 'Software waits until TXE=1 and writes F1 into DR'. For subsequent frames, the sequence is: 'Software waits until TXE=1 and writes F2 into DR' (or F1 into DR). After the last frame (F3) is written, the software must wait until TC=1 before disabling the USART or entering low-power mode.

Break characters

Setting the SBK bit transmits a break character. The break frame length depends on the M bit (see Figure 168 ).

If the SBK bit is set to '1' a break character is sent on the TX line after completing the current character transmission. This bit is reset by hardware when the break character is completed (during the stop bit of the break character). The USART inserts a logic 1 bit at the end of the last break frame to guarantee the recognition of the start bit of the next frame.

Note: If the software resets the SBK bit before the commencement of break transmission, the break character is not transmitted. For two consecutive breaks, the SBK bit should be set after the stop bit of the previous break.

Idle characters

Setting the TE bit drives the USART to send an idle frame before the first data frame.

19.3.3 Receiver

The USART can receive data words of either 8 or 9 bits depending on the M bit in the USART_CR1 register.

Start bit detection

The start bit detection sequence is the same when oversampling by 16 or by 8.

In the USART, the start bit is detected when a specific sequence of samples is recognized. This sequence is: 1 1 1 0 X 0 X 0 X 0 0 0 0.

Figure 171. Start bit detection when oversampling by 16 or 8

Timing diagram for start bit detection showing RX state, RX line, Ideal sample clock, Real sample clock, and Conditions to validate the start bit. The diagram illustrates the sequence of samples (1, 1, 1, 0, X, 0, X, 0, X, 0, 0, 0, 0) required to detect a start bit. It shows the transition from an idle state to a start bit, with sampling points indicated by arrows. The 'Conditions to validate the start bit' row shows the logic levels at each sampling point, with 'X' indicating a don't care condition. The diagram also includes timing information for 'One-bit time' and '7/16' bit durations.

The diagram illustrates the start bit detection process. The RX line transitions from a high idle state to a low start bit. Sampling occurs at regular intervals. The 'Ideal sample clock' has 16 samples per bit, while the 'Real sample clock' has 8 samples per bit. The 'Conditions to validate the start bit' row shows the logic levels at each sampling point. The first three samples (1, 1, 1) must be high. The fourth sample (0) must be low. The subsequent samples (X, 0, X, 0, X, 0, 0, 0, 0) are used to validate the start bit. The 'Falling edge detection' occurs at the transition from the third high sample to the first low sample. The 'At least 2 bits out of 3 at 0' condition is met for the first sampling (samples 3, 5, 7) and the second sampling (samples 8, 9, 10).

Sample Index12345678910111213141516
Logic Level1110X0X000XXXXXX
ConditionAt least 2 bits out of 3 at 0At least 2 bits out of 3 at 0At least 2 bits out of 3 at 0
Timing diagram for start bit detection showing RX state, RX line, Ideal sample clock, Real sample clock, and Conditions to validate the start bit. The diagram illustrates the sequence of samples (1, 1, 1, 0, X, 0, X, 0, X, 0, 0, 0, 0) required to detect a start bit. It shows the transition from an idle state to a start bit, with sampling points indicated by arrows. The 'Conditions to validate the start bit' row shows the logic levels at each sampling point, with 'X' indicating a don't care condition. The diagram also includes timing information for 'One-bit time' and '7/16' bit durations.

Note: If the sequence is not complete, the start bit detection aborts and the receiver returns to the idle state (no flag is set), where it waits for a falling edge.

The start bit is confirmed (RXNE flag set, interrupt generated if RXNEIE=1) if the three sampled bits are at 0 (first sampling on the third, fifth and seventh bit finds the three bits at 0 and second sampling on the eighth, ninth and tenth bit also finds the three bits at 0).

The start bit is validated (RXNE flag set, interrupt generated if RXNEIE=1) but the NE noise flag is set if, for both samplings, at least two out of the three sampled bits are at 0 (sampling on the third, fifth and seventh bit and sampling on the eighth, ninth and tenth bit). If this

condition is not met, the start detection aborts and the receiver returns to the idle state (no flag is set).

If, for one of the samplings (on the third, fifth and seventh bit, or on the eighth, ninth and tenth bit), two out of the three bits are found at 0, the start bit is validated but the NE noise flag bit is set.

Character reception

During an USART reception, data shifts in least significant bit first through the RX pin. In this mode, the USART_DR register consists of a buffer (RDR) between the internal bus and the received shift register.

Procedure:

  1. 1. Enable the USART by writing the UE bit in USART_CR1 register to 1.
  2. 2. Program the M bit in USART_CR1 to define the word length.
  3. 3. Program the number of stop bits in USART_CR2.
  4. 4. Select DMA enable (DMAR) in USART_CR3 if multibuffer communication is to take place. Configure the DMA register as explained in multibuffer communication. STEP 3
  5. 5. Select the desired baud rate using the baud rate register USART_BRR
  6. 6. Set the RE bit USART_CR1. This enables the receiver which begins searching for a start bit.

When a character is received

Note: The RE bit should not be reset while receiving data. If the RE bit is disabled during reception, the reception of the current byte is aborted.

Break character

When a break character is received, the USART handles it as a framing error.

Idle character

When an idle frame is detected, there is the same procedure as a data received character plus an interrupt if the IDLEIE bit is set.

Overrun error

An overrun error occurs when a character is received when RXNE has not been reset. Data can not be transferred from the shift register to the RDR register until the RXNE bit is cleared.

The RXNE flag is set after every byte received. An overrun error occurs if RXNE flag is set when the next data is received or the previous DMA request has not been serviced. When an overrun error occurs:

Note: The ORE bit, when set, indicates that at least 1 data has been lost. There are two possibilities:

Selecting the proper oversampling method

The receiver implements different user-configurable oversampling techniques (except in synchronous mode) for data recovery by discriminating between valid incoming data and noise.

The oversampling method can be selected by programming the OVER8 bit in the USART_CR1 register and can be either 16 or 8 times the baud rate clock ( Figure 172 and Figure 173 ).

Depending on the application:

Programming the ONEBIT bit in the USART_CR3 register selects the method used to evaluate the logic level. There are two options:

Depending on the application:

When noise is detected in a frame:

The NF bit is reset by a USART_SR register read operation followed by a USART_DR register read operation.

Note: Oversampling by 8 is not available in the Smartcard, IrDA and LIN modes. In those modes, the OVER8 bit is forced to '0' by hardware.

Figure 172. Data sampling when oversampling by 16

Timing diagram for data sampling when oversampling by 16. The diagram shows the RX line and Sample clock signals over one bit time. The RX line is sampled 16 times by the Sample clock. The first 7 samples are used to determine the start of the bit. The next 3 samples (samples 8, 9, and 10) are the 'sampled values' used for the majority vote. The remaining 6 samples (samples 11 through 16) are used to determine the end of the bit. The bit time is divided into 16 equal parts. The first 7/16 of the bit time corresponds to the first 7 samples. The next 6/16 of the bit time corresponds to the 6 samples used for the majority vote (samples 8 through 13). The final 7/16 of the bit time corresponds to the last 7 samples (samples 14 through 16 and the start of the next bit).

The diagram illustrates the timing for data sampling when oversampling by 16. The RX line is shown at the top, and the Sample clock is shown below it. The Sample clock has 16 rising edges per bit time, labeled 1 through 16. The RX line is sampled at each rising edge. The first 7 samples (1-7) are used to determine the start of the bit. The next 3 samples (8-10) are the 'sampled values' used for the majority vote. The remaining 6 samples (11-16) are used to determine the end of the bit. The bit time is divided into 16 equal parts. The first 7/16 of the bit time corresponds to the first 7 samples. The next 6/16 of the bit time corresponds to the 6 samples used for the majority vote (samples 8 through 13). The final 7/16 of the bit time corresponds to the last 7 samples (samples 14 through 16 and the start of the next bit). The diagram also shows the start and end of the bit time, and the MSv31152V1 identifier.

Timing diagram for data sampling when oversampling by 16. The diagram shows the RX line and Sample clock signals over one bit time. The RX line is sampled 16 times by the Sample clock. The first 7 samples are used to determine the start of the bit. The next 3 samples (samples 8, 9, and 10) are the 'sampled values' used for the majority vote. The remaining 6 samples (samples 11 through 16) are used to determine the end of the bit. The bit time is divided into 16 equal parts. The first 7/16 of the bit time corresponds to the first 7 samples. The next 6/16 of the bit time corresponds to the 6 samples used for the majority vote (samples 8 through 13). The final 7/16 of the bit time corresponds to the last 7 samples (samples 14 through 16 and the start of the next bit).

Figure 173. Data sampling when oversampling by 8

Timing diagram showing data sampling on the RX line with a sample clock (x8). It illustrates one bit time divided into 8 samples, with 'sampled values' taken at samples 4, 5, and 6. Time intervals of 3/8 and 2/8 bit times are marked.

The diagram shows the RX line and Sample clock (x8) over one bit time. The RX line has a pulse. The Sample clock (x8) has 8 rising edges labeled 1 through 8. Samples are taken at edges 4, 5, and 6, labeled 'sampled values'. The time from the start of the bit to the start of the sampled values is 3/8 of a bit time. The duration of the sampled values is 2/8 of a bit time. The time from the end of the sampled values to the end of the bit time is 3/8 of a bit time. The total bit time is labeled 'One bit time'. The diagram is labeled MSv31153V1.

Timing diagram showing data sampling on the RX line with a sample clock (x8). It illustrates one bit time divided into 8 samples, with 'sampled values' taken at samples 4, 5, and 6. Time intervals of 3/8 and 2/8 bit times are marked.

Table 72. Noise detection from sampled data

Sampled valueNE statusReceived bit value
00000
00110
01010
01111
10010
10111
11011
11101

Framing error

A framing error is detected when:

The stop bit is not recognized on reception at the expected time, following either a de-synchronization or excessive noise.

When the framing error is detected:

The FE bit is reset by a USART_SR register read operation followed by a USART_DR register read operation.

Configurable stop bits during reception

The number of stop bits to be received can be configured through the control bits of Control Register 2 - it can be either 1 or 2 in normal mode and 0.5 or 1.5 in Smartcard mode.

  1. 1. 0.5 stop bit (reception in Smartcard mode) : No sampling is done for 0.5 stop bit. As a consequence, no framing error and no break frame can be detected when 0.5 stop bit is selected.
  2. 2. 1 stop bit : Sampling for 1 stop Bit is done on the 8th, 9th and 10th samples.
  3. 3. 1.5 stop bits (Smartcard mode) : When transmitting in smartcard mode, the device must check that the data is correctly sent. Thus the receiver block must be enabled (RE =1 in the USART_CR1 register) and the stop bit is checked to test if the smartcard has detected a parity error. In the event of a parity error, the smartcard forces the data signal low during the sampling - NACK signal-, which is flagged as a framing error. Then, the FE flag is set with the RXNE at the end of the 1.5 stop bit. Sampling for 1.5 stop bits is done on the 16th, 17th and 18th samples (1 baud clock period after the beginning of the stop bit). The 1.5 stop bit can be decomposed into 2 parts: one 0.5 baud clock period during which nothing happens, followed by 1 normal stop bit period during which sampling occurs halfway through. Refer to Section 19.3.11: Smartcard on page 534 for more details.
  4. 4. 2 stop bits : Sampling for 2 stop bits is done on the 8th, 9th and 10th samples of the first stop bit. If a framing error is detected during the first stop bit the framing error flag is set. The second stop bit is not checked for framing error. The RXNE flag is set at the end of the first stop bit.

19.3.4 Fractional baud rate generation

The baud rate for the receiver and transmitter (Rx and Tx) are both set to the same value as programmed in the Mantissa and Fraction values of USARTDIV.

Equation 1: Baud rate for standard USART (SPI mode included)

\[ \text{Tx/Rx baud} = \frac{f_{\text{CK}}}{8 \times (2 - \text{OVER8}) \times \text{USARTDIV}} \]

Equation 2: Baud rate in Smartcard, LIN and IrDA modes

\[ \text{Tx/Rx baud} = \frac{f_{\text{CK}}}{16 \times \text{USARTDIV}} \]

USARTDIV is an unsigned fixed point number that is coded on the USART_BRR register.

Note: The baud counters are updated to the new value in the baud registers after a write operation to USART_BRR. Hence the baud rate register value should not be changed during communication.

How to derive USARTDIV from USART_BRR register values when OVER8=0 Example 1:

If DIV_Mantissa = 0d27 and DIV_Fraction = 0d12 (USART_BRR = 0x1BC), then

Mantissa (USARTDIV) = 0d27

Fraction (USARTDIV) = 12/16 = 0d0.75

Therefore USARTDIV = 0d27.75

Example 2:

To program USARTDIV = 0d25.62

This leads to:

DIV_Fraction = 16*0d0.62 = 0d9.92

The nearest real number is 0d10 = 0xA

DIV_Mantissa = mantissa (0d25.620) = 0d25 = 0x19

Then, USART_BRR = 0x19A hence USARTDIV = 0d25.625

Example 3:

To program USARTDIV = 0d50.99

This leads to:

DIV_Fraction = 16*0d0.99 = 0d15.84

The nearest real number is 0d16 = 0x10 => overflow of DIV_frac[3:0] => carry must be added up to the mantissa

DIV_Mantissa = mantissa (0d50.990 + carry) = 0d51 = 0x33

Then, USART_BRR = 0x330 hence USARTDIV = 0d51.000

How to derive USARTDIV from USART_BRR register values when OVER8=1 Example 1:

If DIV_Mantissa = 0x27 and DIV_Fraction[2:0]= 0d6 (USART_BRR = 0x1B6), then

Mantissa (USARTDIV) = 0d27

Fraction (USARTDIV) = 6/8 = 0d0.75

Therefore USARTDIV = 0d27.75

Example 2:

To program USARTDIV = 0d25.62

This leads to:

DIV_Fraction = 8*0d0.62 = 0d4.96

The nearest real number is 0d5 = 0x5

DIV_Mantissa = mantissa (0d25.620) = 0d25 = 0x19

Then, \( USART\_BRR = 0x195 \Rightarrow USARTDIV = 0d25.625 \)

Example 3:

To program \( USARTDIV = 0d50.99 \)

This leads to:

\( DIV\_Fraction = 8 * 0d0.99 = 0d7.92 \)

The nearest real number is \( 0d8 = 0x8 \Rightarrow \) overflow of the \( DIV\_frac[2:0] \Rightarrow \) carry must be added up to the mantissa

\( DIV\_Mantissa = \text{mantissa } (0d50.990 + \text{carry}) = 0d51 = 0x33 \)

Then, \( USART\_BRR = 0x0330 \Rightarrow USARTDIV = 0d51.000 \)

Table 73. Error calculation for programmed baud rates at \( f_{PCLK} = 8 \) MHz or \( f_{PCLK} = 12 \) MHz, oversampling by 16 (1)

Oversampling by 16 (OVER8=0)
Baud rate 7\( f_{PCLK} = 8 \) MHz\( f_{PCLK} = 12 \) MHz
S.NoDesiredActualValue programmed in the baud rate register% Error = (Calculated - Desired) B.rate / Desired B.rateActualValue programmed in the baud rate register% Error
11.2 KBps1.2 KBps416.687501.2 KBps6250
22.4 KBps2.4 KBps208.31250.012.4 KBps312.50
39.6 KBps9.604 KBps52.06250.049.6 KBps78.1250
419.2 KBps19.185 KBps26.06250.0819.2 KBps39.06250
538.4 KBps38.462 KBps130.1638.339 KBps19.56250.16
657.6 KBps57.554 KBps8.68750.0857.692 KBps130.16
7115.2 KBps115.942 KBps4.31250.64115.385 KBps6.50.16
8230.4 KBps228.571 KBps2.18750.79230.769 KBps3.250.16
9460.8 KBps470.588 KBps1.06252.12461.538 KBps1.6250.16
10921.6 KBpsNANANANANANA
112 MBpsNANANANANANA
123 MBpsNANANANANANA
  1. 1. The lower the CPU clock the lower the accuracy for a particular baud rate. The upper limit of the achievable baud rate can be fixed with these data.
Table 74. Error calculation for programmed baud rates at \( f_{PCLK} = 8 \) MHz or \( f_{PCLK} = 12 \) MHz, oversampling by 8 (1)
Oversampling by 8 (OVER8 = 1)
Baud rate\( f_{PCLK} = 8 \) MHz\( f_{PCLK} = 12 \) MHz
S.NoDesiredActualValue programmed in the baud rate register% Error = (Calculated - Desired) B.rate / Desired B.rateActualValue programmed in the baud rate register% Error
11.2 KBps1.2 KBps833.37501.2 KBps12500
22.4 KBps2.4 KBps416.6250.012.4 KBps6250
39.6 KBps9.604 KBps104.1250.049.6 KBps156.250
419.2 KBps19.185 KBps52.1250.0819.2 KBps78.1250
538.4 KBps38.462 KBps260.1638.339 KBps39.1250.16
657.6 KBps57.554 KBps17.3750.0857.692 KBps260.16
7115.2 KBps115.942 KBps8.6250.64115.385 KBps130.16
8230.4 KBps228.571 KBps4.3750.79230.769 KBps6.50.16
9460.8 KBps470.588 KBps2.1252.12461.538 KBps3.250.16
10921.6 KBps888.889 KBps1.1253.55923.077 KBps1.6250.16
112 MBpsNANANANANANA
123 MBpsNANANANANANA

1. The lower the CPU clock the lower the accuracy for a particular baud rate. The upper limit of the achievable baud rate can be fixed with these data.

Table 75. Error calculation for programmed baud rates at \( f_{PCLK} = 16 \) MHz or \( f_{PCLK} = 24 \) MHz, oversampling by 16 (1)
Oversampling by 16 (OVER8 = 0)
Baud rate\( f_{PCLK} = 16 \) MHz\( f_{PCLK} = 24 \) MHz
S.NoDesiredActualValue programmed in the baud rate register% Error = (Calculated - Desired) B.rate / Desired B.rateActualValue programmed in the baud rate register% Error
11.2 KBps1.2 KBps833.312501.212500
22.4 KBps2.4 KBps416.687502.46250
39.6 KBps9.598 KBps104.18750.029.6156.250
419.2 KBps19.208 KBps52.06250.0419.278.1250
538.4 KBps38.369 KBps26.06250.0838.439.06250
657.6 KBps57.554 KBps17.3750.0857.55426.06250.08

Table 75. Error calculation for programmed baud rates at \( f_{PCLK} = 16 \) MHz or \( f_{PCLK} = 24 \) MHz, oversampling by 16 (1) (continued)

Oversampling by 16 (OVER8 = 0)
Baud rate\( f_{PCLK} = 16 \) MHz\( f_{PCLK} = 24 \) MHz
S.NoDesiredActualValue programmed in the baud rate register% Error = (Calculated - Desired) B.rate / Desired B.rateActualValue programmed in the baud rate register% Error
7115.2 KBps115.108 KBps8.68750.08115.385130.16
8230.4 KBps231.884 KBps4.31250.64230.7696.50.16
9460.8 KBps457.143 KBps2.18750.79461.5383.250.16
10921.6 KBps941.176 KBps1.06252.12923.0771.6250.16
112 MBpsNANANANANANA
123 MBpsNANANANANANA

1. The lower the CPU clock the lower the accuracy for a particular baud rate. The upper limit of the achievable baud rate can be fixed with these data.

Table 76. Error calculation for programmed baud rates at \( f_{PCLK} = 16 \) MHz or \( f_{PCLK} = 24 \) MHz, oversampling by 8 (1)

Oversampling by 8 (OVER8=1)
Baud rate\( f_{PCLK} = 16 \) MHz\( f_{PCLK} = 24 \) MHz
S.NoDesiredActualValue programmed in the baud rate register% Error = (Calculated - Desired) B.rate / Desired B.rateActualValue programmed in the baud rate register% Error
11.2 KBps1.2 KBps1666.62501.2 KBps25000
22.4 KBps2.4 KBps833.37502.4 KBps12500
39.6 KBps9.598 KBps208.3750.029.6 KBps312.50
419.2 KBps19.208 KBps104.1250.0419.2 KBps156.250
538.4 KBps38.369 KBps52.1250.0838.4 KBps78.1250
657.6 KBps57.554 KBps34.750.0857.554 KBps52.1250.08
7115.2 KBps115.108 KBps17.3750.08115.385 KBps260.16
8230.4 KBps231.884 KBps8.6250.64230.769 KBps130.16
9460.8 KBps457.143 KBps4.3750.79461.538 KBps6.50.16
10921.6 KBps941.176 KBps2.1252.12923.077 KBps3.250.16
112 MBps2000 KBps102000 KBps1.50
123 MBpsNANANA3000 KBps10

1. The lower the CPU clock the lower the accuracy for a particular baud rate. The upper limit of the achievable baud rate can be fixed with these data.

Table 77. Error calculation for programmed baud rates at \( f_{PCLK} = 8 \) MHz or \( f_{PCLK} = 16 \) MHz, oversampling by 16 (1)
Oversampling by 16 (OVER8=0)
Baud rate\( f_{PCLK} = 8 \) MHz\( f_{PCLK} = 16 \) MHz
S.NoDesiredActualValue programmed in the baud rate register% Error = (Calculated - Desired)B.Rate /Desired B.RateActualValue programmed in the baud rate register% Error
1.2.4 KBps2.400 KBps208.31250.00%2.400 KBps416.68750.00%
2.9.6 KBps9.604 KBps52.06250.04%9.598 KBps104.18750.02%
3.19.2 KBps19.185 KBps26.06250.08%19.208 KBps52.06250.04%
4.57.6 KBps57.554 KBps8.68750.08%57.554 KBps17.37500.08%
5.115.2 KBps115.942 KBps4.31250.64%115.108 KBps8.68750.08%
6.230.4 KBps228.571 KBps2.18750.79%231.884 KBps4.31250.64%
7.460.8 KBps470.588 KBps1.06252.12%457.143 KBps2.18750.79%
8.896 KBpsNANANA888.889 KBps1.12500.79%
9.921.6 KBpsNANANA941.176 KBps1.06252.12%
10.1.792 MBpsNANANANANANA
11.1.8432 MBpsNANANANANANA
12.3.584 MBpsNANANANANANA
13.3.6864 MBpsNANANANANANA
14.7.168 MBpsNANANANANANA
15.7.3728 MBpsNANANANANANA

1. The lower the CPU clock the lower the accuracy for a particular baud rate. The upper limit of the achievable baud rate can be fixed with these data.

Table 78. Error calculation for programmed baud rates at \( f_{PCLK} = 8 \) MHz or \( f_{PCLK} = 16 \) MHz, oversampling by 8 (1)
Oversampling by 8 (OVER8=1)
Baud rate\( f_{PCLK} = 8 \) MHz\( f_{PCLK} = 16 \) MHz
S.NoDesiredActualValue programmed in the baud rate register% Error = (Calculated - Desired)B.Rate /Desired B.RateActualValue programmed in the baud rate register% Error
1.2.4 KBps2.400 KBps416.6250.01%2.400 KBps833.3750.00%
2.9.6 KBps9.604 KBps104.1250.04%9.598 KBps208.3750.02%
3.19.2 KBps19.185 KBps52.1250.08%19.208 KBps104.1250.04%

Table 78. Error calculation for programmed baud rates at \( f_{PCLK} = 8 \) MHz or \( f_{PCLK} = 16 \) MHz, oversampling by 8 (1) (continued)

Oversampling by 8 (OVER8=1)
Baud rate\( f_{PCLK} = 8 \) MHz\( f_{PCLK} = 16 \) MHz
S.NoDesiredActualValue programmed in the baud rate register% Error = (Calculated - Desired)B.Rate /Desired B.RateActualValue programmed in the baud rate register% Error
4.57.6 KBps57.557 KBps17.3750.08%57.554 KBps34.7500.08%
5.115.2 KBps115.942 KBps8.6250.64%115.108 KBps17.3750.08%
6.230.4 KBps228.571 KBps4.3750.79%231.884 KBps8.6250.64%
7.460.8 KBps470.588 KBps2.1252.12%457.143 KBps4.3750.79%
8.896 KBps888.889 KBps1.1250.79%888.889 KBps2.2500.79%
9.921.6 KBps888.889 KBps1.1253.55%941.176 KBps2.1252.12%
10.1.792 MBpsNANANA1.7777 MBps1.1250.79%
11.1.8432 MBpsNANANA1.7777 MBps1.1253.55%
12.3.584 MBpsNANANANANANA
13.3.6864 MBpsNANANANANANA
14.7.168 MBpsNANANANANANA
15.7.3728 MBpsNANANANANANA

1. The lower the CPU clock the lower the accuracy for a particular baud rate. The upper limit of the achievable baud rate can be fixed with these data.

Table 79. Error calculation for programmed baud rates at \( f_{PCLK} = 30 \) MHz or \( f_{PCLK} = 60 \) MHz, oversampling by 16 (1)(2)

Oversampling by 16 (OVER8=0)
Baud rate\( f_{PCLK} = 30 \) MHz\( f_{PCLK} = 60 \) MHz
S.NoDesiredActualValue programmed in the baud rate register% Error = (Calculated - Desired)B.Rate /Desired B.RateActualValue programmed in the baud rate register% Error
1.2.4 KBps2.400 KBps781.25000.00%2.400 KBps1562.50000.00%
2.9.6 KBps9.600 KBps195.31250.00%9.600 KBps390.62500.00%
3.19.2 KBps19.194 KBps97.68750.03%19.200 KBps195.31250.00%
4.57.6 KBps57.582 KBps32.56250.03%57.582 KBps65.12500.03%
5.115.2 KBps115.385 KBps16.25000.16%115.163 KBps32.56250.03%
6.230.4 KBps230.769 KBps8.12500.16%230.769 KBps16.25000.16%
7.460.8 KBps461.538 KBps4.06250.16%461.538 KBps8.12500.16%
8.896 KBps909.091 KBps2.06251.46%895.522 KBps4.18750.05%
Table 79. Error calculation for programmed baud rates at \( f_{PCLK} = 30 \) MHz or \( f_{PCLK} = 60 \) MHz, oversampling by 16 (1)(2) (continued)
Oversampling by 16 (OVER8=0)
Baud rate\( f_{PCLK} = 30 \) MHz\( f_{PCLK} = 60 \) MHz
S.NoDesiredActualValue programmed in the baud rate register% Error = (Calculated - Desired)B.Rate /Desired B.RateActualValue programmed in the baud rate register% Error
9.921.6 KBps909.091 KBps2.06251.36%923.077 KBps4.06250.16%
10.1.792 MBps1.1764 MBps1.06251.52%1.8182 MBps2.06251.36%
11.1.8432 MBps1.8750 MBps1.00001.73%1.8182 MBps2.06251.52%
12.3.584 MBpsNANANA3.2594 MBps1.06251.52%
13.3.6864 MBpsNANANA3.7500 MBps1.00001.73%
14.7.168 MBpsNANANANANANA
15.7.3728 MBpsNANANANANANA
  1. 1. The lower the CPU clock the lower the accuracy for a particular baud rate. The upper limit of the achievable baud rate can be fixed with these data.
  2. 2. Only USART1 and USART6 are clocked with PCLK2. Other USARTs are clocked with PCLK1. Refer to the device datasheets for the maximum values for PCLK1 and PCLK2.
Table 80. Error calculation for programmed baud rates at \( f_{PCLK} = 30 \) MHz or \( f_{PCLK} = 60 \) MHz, oversampling by 8 (1) (2)
Oversampling by 8 (OVER8=1)
Baud rate\( f_{PCLK} = 30 \) MHz\( f_{PCLK} = 60 \) MHz
S.NoDesiredActualValue programmed in the baud rate register% Error = (Calculated - Desired)B.Rate /Desired B.RateActualValue programmed in the baud rate register% Error
1.2.4 KBps2.400 KBps1562.50000.00%2.400 KBps3125.00000.00%
2.9.6 KBps9.600 KBps390.62500.00%9.600 KBps781.25000.00%
3.19.2 KBps19.194 KBps195.37500.03%19.200 KBps390.62500.00%
4.57.6 KBps57.582 KBps65.12500.16%57.582 KBps130.25000.03%
5.115.2 KBps115.385 KBps32.50000.16%115.163 KBps65.12500.03%
6.230.4 KBps230.769 KBps16.25000.16%230.769 KBps32.50000.16%
7.460.8 KBps461.538 KBps8.12500.16%461.538 KBps16.25000.16%
8.896 KBps909.091 KBps4.12501.46%895.522 KBps8.37500.05%
9.921.6 KBps909.091 KBps4.12501.36%923.077 KBps8.12500.16%
10.1.792 MBps1.7647 MBps2.12501.52%1.8182 MBps4.12501.46%

Table 80. Error calculation for programmed baud rates at \( f_{PCLK} = 30 \) MHz or \( f_{PCLK} = 60 \) MHz, oversampling by 8 (1) (2) (continued)

Oversampling by 8 (OVER8=1)
Baud rate\( f_{PCLK} = 30 \) MHz\( f_{PCLK} = 60 \) MHz
S.NoDesiredActualValue programmed in the baud rate register% Error = (Calculated - Desired)B.Rate /Desired B.RateActualValue programmed in the baud rate register% Error
11.1.8432 MBps1.8750 MBps2.00001.73%1.8182 MBps4.12501.36%
12.3.584 MBps3.7500 MBps1.00004.63%3.5294 MBps2.12501.52%
13.3.6864 MBps3.7500 MBps1.00001.73%3.7500 MBps2.00001.73%
14.7.168 MBpsNANANA7.5000 MBps1.00004.63%
15.7.3728 MBpsNANANA7.5000 MBps1.00001.73%
  1. 1. The lower the CPU clock the lower the accuracy for a particular baud rate. The upper limit of the achievable baud rate can be fixed with these data.
  2. 2. Only USART1 and USART6 are clocked with PCLK2. Other USARTs are clocked with PCLK1. Refer to the device datasheets for the maximum values for PCLK1 and PCLK2.

Table 81. Error calculation for programmed baud rates at \( f_{PCLK} = 42 \) MHz or \( f_{PCLK} = 84 \) MHz, oversampling by 16 (1)(2)

Oversampling by 16 (OVER8=0)
Baud rate\( f_{PCLK} = 42 \) MHz\( f_{PCLK} = 84 \) MHz
S.NoDesiredActualValue programmed in the baud rate register% Error = (Calculated - Desired)B.Rate /Desired B.RateActualValue programmed in the baud rate register% Error
1.1.2 KBps1.2 KBps2187.501.2 KBpsNA0
2.2.4 KBps2.4 KBps1093.7502.4 KBps2187.50
3.9.6 KBps9.6 KBps273.437509.6 KBps546.8750
4.19.2 KBps19.195 KBps136.750.0219.2 KBps273.43750
5.38.4 KBps38.391 KBps68.3750.0238.391 KBps136.750.02
6.57.6 KBps57.613 KBps45.56250.0257.613 KBps91.1250.02
7.115.2 KBps115.068 KBps22.81250.11115.226 KBps45.56250.02
8.230.4 KBps230.769 KBps11.3750.16230.137 KBps22.81250.11
9.460.8 KBps461.538 KBps5.68750.16461.538 KBps11.3750.16
10.921.6 KBps913.043 KBps2.8750.93923.076 KBps5.68750.93
11.1.792 MBps1.826 MBps1.43751.91.787 MBps2.93750.27
12.1.8432 MBps1.826 MBps1.43750.931.826 MBps2.8750.93
13.3.584 MBpsN.AN.AN.A3.652 MBps1.43751.9
14.3.6864 MBpsN.AN.AN.A3.652 MBps1.43750.93
Table 81. Error calculation for programmed baud rates at \( f_{PCLK} = 42 \) MHz or \( f_{PCLK} = 84 \) Hz, oversampling by 16 (1)(2) (continued)
Oversampling by 16 (OVER8=0)
Baud rate\( f_{PCLK} = 42 \) MHz\( f_{PCLK} = 84 \) MHz
S.NoDesiredActualValue programmed in the baud rate register% Error = (Calculated - Desired)B.Rate /Desired B.RateActualValue programmed in the baud rate register% Error
15.7.168 MBpsN.AN.AN.AN.AN.AN.A
16.7.3728 MBpsN.AN.AN.AN.AN.AN.A
17.9 MBpsN.AN.AN.AN.AN.AN.A
18.10.5 MBpsN.AN.AN.AN.AN.AN.A
  1. 1. The lower the CPU clock the lower the accuracy for a particular baud rate. The upper limit of the achievable baud rate can be fixed with these data.
  2. 2. Only USART1 and USART6 are clocked with PCLK2. Other USARTs are clocked with PCLK1. Refer to the device datasheets for the maximum values for PCLK1 and PCLK2.
Table 82. Error calculation for programmed baud rates at \( f_{PCLK} = 42 \) MHz or \( f_{PCLK} = 84 \) MHz, oversampling by 8 (1)(2)
Oversampling by 8 (OVER8=1)
Baud rate\( f_{PCLK} = 42 \) MHz\( f_{PCLK} = 84 \) MHz
S.NoDesiredActualValue programmed in the baud rate registerValue programmed in the baud rate registerActualValue programmed in the baud rate register% Error
1.2.4 KBps2.4 KBps2187.502.4 KBpsNA0
2.9.6 KBps9.6 KBps546.87509.6 KBps1093.750
3.19.2 KBps19.195 KBps273.50.0219.2 KBps546.8750
4.38.4 KBps38.391 KBps136.750.0238.391 KBps273.50.02
5.57.6 KBps57.613 KBps91.1250.0257.613 KBps182.250.02
6.115.2 KBps115.068 KBps45.6250.11115.226 KBps91.1250.02
7.230.4 KBps230.769 KBps22.750.11230.137 KBps45.6250.11
8.460.8 KBps461.538 KBps11.3750.16461.538 KBps22.750.16
9.921.6 KBps913.043 KBps5.750.93923.076 KBps11.3750.93
10.1.792 MBps1.826 MBps2.8751.91.787 Mbps5.8750.27
11.1.8432 MBps1.826 MBps2.8750.931.826 MBps5.750.93
12.3.584 MBps3.5 MBps1.52.343.652 MBps2.8751.9
13.3.6864 MBps3.82 MBps1.3753.573.652 MBps2.8750.93
14.7.168 MBpsN.AN.AN.A7 MBps1.52.34
15.7.3728 MBpsN.AN.AN.A7.636 MBps1.3753.57

Table 82. Error calculation for programmed baud rates at \( f_{PCLK} = 42 \) MHz or \( f_{PCLK} = 84 \) MHz, oversampling by 8 (1)(2) (continued)

Oversampling by 8 (OVER8=1)
Baud rate\( f_{PCLK} = 42 \) MHz\( f_{PCLK} = 84 \) MHz
S.NoDesiredActualValue programmed in the baud rate registerValue programmed in the baud rate registerActualValue programmed in the baud rate register% Error
16.9 MBpsN.AN.AN.A9.333 MBps1.1253.7
17.10.5 MBpsN.AN.AN.A10.5 MBps10

1. The lower the CPU clock the lower the accuracy for a particular baud rate. The upper limit of the achievable baud rate can be fixed with these data.

2. Only USART1 and USART6 are clocked with PCLK2. Other USARTs are clocked with PCLK1. Refer to the device datasheets for the maximum values for PCLK1 and PCLK2.

19.3.5 USART receiver tolerance to clock deviation

The USART asynchronous receiver works correctly only if the total clock system deviation is smaller than the USART receiver's tolerance. The causes which contribute to the total deviation are:

\[ DTRA + DQUANT + DREC + DTCL < \text{USART receiver's tolerance} \]

The USART receiver's tolerance to properly receive data is equal to the maximum tolerated deviation and depends on the following choices:

Table 83. USART receiver's tolerance when DIV fraction is 0

M bitOVER8 bit = 0OVER8 bit = 1
ONEBIT=0ONEBIT=1ONEBIT=0ONEBIT=1
03.75%4.375%2.50%3.75%
13.41%3.97%2.27%3.41%
Table 84. USART receiver tolerance when DIV_Fraction is different from 0
M bitOVER8 bit = 0OVER8 bit = 1
ONEBIT=0ONEBIT=1ONEBIT=0ONEBIT=1
03.33%3.88%2%3%
13.03%3.53%1.82%2.73%

Note: The figures specified in Table 83 and Table 84 may slightly differ in the special case when the received frames contain some Idle frames of exactly 10-bit times when M=0 (11-bit times when M=1).

19.3.6 Multiprocessor communication

There is a possibility of performing multiprocessor communication with the USART (several USARTs connected in a network). For instance one of the USARTs can be the master, its TX output is connected to the RX input of the other USART. The others are slaves, their respective TX outputs are logically ANDed together and connected to the RX input of the master.

In multiprocessor configurations it is often desirable that only the intended message recipient should actively receive the full message contents, thus reducing redundant USART service overhead for all non addressed receivers.

The non addressed devices may be placed in mute mode by means of the muting function. In mute mode:

The USART can enter or exit from mute mode using one of two methods, depending on the WAKE bit in the USART_CR1 register:

Idle line detection (WAKE=0)

The USART enters mute mode when the RWU bit is written to 1.

It wakes up when an Idle frame is detected. Then the RWU bit is cleared by hardware but the IDLE bit is not set in the USART_SR register. RWU can also be written to 0 by software.

An example of mute mode behavior using Idle line detection is given in Figure 174.

Figure 174. Mute mode using Idle line detection

Timing diagram for Figure 174 showing RX data and RWU signal for mute mode using Idle line detection.

The diagram illustrates the RX signal and RWU signal over time. The RX signal consists of Data 1, Data 2, Data 3, Data 4, an IDLE state, Data 5, and Data 6. The RWU signal is initially low. When RWU is written to 1, the USART enters Mute mode. Upon detection of an Idle frame (after Data 4), the USART exits Mute mode and enters Normal mode. In Normal mode, the RXNE flag is set for Data 5 and Data 6.

Timing diagram for Figure 174 showing RX data and RWU signal for mute mode using Idle line detection.

Address mark detection (WAKE=1)

In this mode, bytes are recognized as addresses if their MSB is a '1' else they are considered as data. In an address byte, the address of the targeted receiver is put on the 4 LSB. This 4-bit word is compared by the receiver with its own address which is programmed in the ADD bits in the USART_CR2 register.

The USART enters mute mode when an address character is received which does not match its programmed address. In this case, the RWU bit is set by hardware. The RXNE flag is not set for this address byte and no interrupt nor DMA request is issued as the USART would have entered mute mode.

It exits from mute mode when an address character is received which matches the programmed address. Then the RWU bit is cleared and subsequent bytes are received normally. The RXNE bit is set for the address character since the RWU bit has been cleared.

The RWU bit can be written to as 0 or 1 when the receiver buffer contains no data (RXNE=0 in the USART_SR register). Otherwise the write attempt is ignored.

An example of mute mode behavior using address mark detection is given in Figure 175.

Figure 175. Mute mode using address mark detection

Timing diagram for Figure 175 showing RX data and RWU signal for mute mode using address mark detection.

The diagram shows the RX signal and RWU signal. The RX signal contains IDLE, Addr=0, Data 1, Data 2, IDLE, Addr=1, Data 3, Data 4, Addr=2, and Data 5. The RWU signal is initially low. When RWU is written to 1 (RXNE was cleared), the USART enters Mute mode. Upon receiving Addr=0 (a non-matching address), the USART stays in Mute mode. Upon receiving Addr=1 (a matching address), the USART exits Mute mode and enters Normal mode. Upon receiving Addr=2 (a non-matching address), the USART enters Mute mode again. The RXNE flag is set for Data 1, Data 2, Data 3, Data 4, and Data 5 in Normal mode.

Timing diagram for Figure 175 showing RX data and RWU signal for mute mode using address mark detection.

19.3.7 Parity control

Parity control (generation of parity bit in transmission and parity checking in reception) can be enabled by setting the PCE bit in the USART_CR1 register. Depending on the frame length defined by the M bit, the possible USART frame formats are as listed in Table 85 .

Table 85. Frame formats

M bitPCE bitUSART frame (1)
00| SB | 8 bit data | STB |
01| SB | 7-bit data | PB | STB |
10| SB | 9-bit data | STB |
11| SB | 8-bit data PB | STB |

1. Legends: SB: start bit, STB: stop bit, PB: parity bit.

Even parity

The parity bit is calculated to obtain an even number of “1s” inside the frame made of the 7 or 8 LSB bits (depending on whether M is equal to 0 or 1) and the parity bit.

E.g.: data=00110101; 4 bits set => parity bit is 0 if even parity is selected (PS bit in USART_CR1 = 0).

Odd parity

The parity bit is calculated to obtain an odd number of “1s” inside the frame made of the 7 or 8 LSB bits (depending on whether M is equal to 0 or 1) and the parity bit.

E.g.: data=00110101; 4 bits set => parity bit is 1 if odd parity is selected (PS bit in USART_CR1 = 1).

Parity checking in reception

If the parity check fails, the PE flag is set in the USART_SR register and an interrupt is generated if PEIE is set in the USART_CR1 register. The PE flag is cleared by a software sequence (a read from the status register followed by a read or write access to the USART_DR data register).

Note: In case of wake-up by an address mark: the MSB bit of the data is taken into account to identify an address but not the parity bit. And the receiver does not check the parity of the address data (PE is not set in case of a parity error).

Parity generation in transmission

If the PCE bit is set in USART_CR1, then the MSB bit of the data written in the data register is transmitted but is changed by the parity bit (even number of “1s” if even parity is selected (PS=0) or an odd number of “1s” if odd parity is selected (PS=1)).

Note: The software routine that manages the transmission can activate the software sequence which clears the PE flag (a read from the status register followed by a read or write access to the data register). When operating in half-duplex mode, depending on the software, this can cause the PE flag to be unexpectedly cleared.

19.3.8 LIN (local interconnection network) mode

The LIN mode is selected by setting the LINEN bit in the USART_CR2 register. In LIN mode, the following bits must be kept cleared:

LIN transmission

The same procedure explained in Section 19.3.2 has to be applied for LIN Master transmission than for normal USART transmission with the following differences:

LIN reception

A break detection circuit is implemented on the USART interface. The detection is totally independent from the normal USART receiver. A break can be detected whenever it occurs, during Idle state or during a frame.

When the receiver is enabled (RE=1 in USART_CR1), the circuit looks at the 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 (when the LBDL = 0 in USART_CR2) or 11 (when LBDL=1 in USART_CR2) consecutive bits are detected as '0, and are followed by a delimiter character, the LBD flag is set in USART_SR. If the LBDIE bit=1, an interrupt is generated. Before validating the break, the delimiter is checked for as it signifies that the RX line has returned to a high level.

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 the LIN mode is disabled (LINEN=0), the receiver continues working as normal USART, without taking into account the break detection.

If the LIN mode is enabled (LINEN=1), as soon as a framing error occurs (stop bit detected at '0, which is 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 on the Figure 176: Break detection in LIN mode (11-bit break length - LBDL bit is set) on page 530 .

Examples of break frames are given on Figure 177: Break detection in LIN mode vs. Framing error detection on page 531 .

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

Timing diagram for Case 1: Break signal not long enough. RX line shows a 'Break frame' pulse that goes high before the 11th bit is sampled. Capture strobe is a periodic signal. Break state machine shows Idle followed by Bit0 through Bit10, then Idle. Read samples for Bit0 through Bit10 are 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 respectively. LBD is not set. Timing diagram for Case 2: Break signal just long enough. RX line shows a 'Break frame' pulse that goes high exactly after the 11th bit is sampled. Capture strobe is a periodic signal. Break state machine shows Idle followed by Bit0 through Bit10, then Idle. Read samples for Bit0 through Bit10 are all 0. LBD is set at the end of Bit10. A note 'Delimiter is immediate' is present above the transition to Idle. Timing diagram for Case 3: Break signal long enough. RX line shows a 'Break frame' pulse that stays low beyond the 11th bit. Capture strobe is a periodic signal. Break state machine shows Idle followed by Bit0 through Bit10, then 'wait delimiter', then Idle when RX goes high. Read samples for Bit0 through Bit10 are all 0. LBD is set at the end of Bit10.

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

RX line: Break frame

Capture strobe

Break state machineIdleBit0Bit1Bit2Bit3Bit4Bit5Bit6Bit7Bit8Bit9Bit10Idle
Read samples00000000001

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

RX line: Break frame

Capture strobe

Delimiter is immediate

Break state machineIdleBit0Bit1Bit2Bit3Bit4Bit5Bit6Bit7Bit8Bit9Bit10Idle
Read samples00000000000

LBD


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

RX line: Break frame

Capture strobe

Break state machineIdleBit0Bit1Bit2Bit3Bit4Bit5Bit6Bit7Bit8Bit9Bit10wait delimiterIdle
Read samples00000000000

LBD

MSv40883V1

Timing diagram for Case 1: Break signal not long enough. RX line shows a 'Break frame' pulse that goes high before the 11th bit is sampled. Capture strobe is a periodic signal. Break state machine shows Idle followed by Bit0 through Bit10, then Idle. Read samples for Bit0 through Bit10 are 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 respectively. LBD is not set. Timing diagram for Case 2: Break signal just long enough. RX line shows a 'Break frame' pulse that goes high exactly after the 11th bit is sampled. Capture strobe is a periodic signal. Break state machine shows Idle followed by Bit0 through Bit10, then Idle. Read samples for Bit0 through Bit10 are all 0. LBD is set at the end of Bit10. A note 'Delimiter is immediate' is present above the transition to Idle. Timing diagram for Case 3: Break signal long enough. RX line shows a 'Break frame' pulse that stays low beyond the 11th bit. Capture strobe is a periodic signal. Break state machine shows Idle followed by Bit0 through Bit10, then 'wait delimiter', then Idle when RX goes high. Read samples for Bit0 through Bit10 are all 0. LBD is set at the end of Bit10.

Figure 177. Break detection in LIN mode vs. Framing error detection

Timing diagram showing break detection in LIN mode vs. framing error detection. Case 1: break occurring after an Idle. Case 2: break occurring while data is being received. Both cases show RX line, RXNE/FE, and LBDF signals over time.

Case 1: break occurring after an Idle

The diagram shows the RX line transitioning from IDLE to BREAK, then to data 2 (0x55) and data 3 (header). The RXNE/FE signal is shown as a step function that goes high when the line is in BREAK and returns low when it is in IDLE. The LBDF signal is shown as a step function that goes high when the line is in BREAK and returns low when it is in IDLE. The time between the start of the BREAK and the start of data 2 is labeled as 1 data time. The time between the start of data 2 and the start of data 3 is also labeled as 1 data time.

Case 2: break occurring while data is being received

The diagram shows the RX line transitioning from data 1 to data 2, then to BREAK, then to data 2 (0x55) and data 3 (header). The RXNE/FE signal is shown as a step function that goes high when the line is in BREAK and returns low when it is in IDLE. The LBDF signal is shown as a step function that goes high when the line is in BREAK and returns low when it is in IDLE. The time between the start of data 2 and the start of the BREAK is labeled as 1 data time. The time between the start of the BREAK and the start of data 2 (0x55) is also labeled as 1 data time.

MSv31157V1

Timing diagram showing break detection in LIN mode vs. framing error detection. Case 1: break occurring after an Idle. Case 2: break occurring while data is being received. Both cases show RX line, RXNE/FE, and LBDF signals over time.

19.3.9 USART synchronous mode

The synchronous mode is selected by writing the CLKEN bit in the USART_CR2 register to 1. In synchronous mode, the following bits must be kept cleared:

The USART allows the user to control a bidirectional synchronous serial communications in master mode. The CK pin is the output of the USART transmitter clock. No clock pulses are sent to the CK pin during start bit and stop bit. Depending on the state of the LBCL bit in the USART_CR2 register clock pulses are generated or not during the last valid data bit (address mark). The CPOL bit in the USART_CR2 register allows the user to select the clock polarity, and the CPHA bit in the USART_CR2 register allows the user to select the phase of the external clock (see Figure 178 , Figure 179 & Figure 180 ).

During the Idle state, preamble and send break, the external CK clock is not activated.

In synchronous mode the USART transmitter works exactly like in asynchronous mode. But as CK is synchronized with TX (according to CPOL and CPHA), the data on TX is synchronous.

In this mode the USART receiver works in a different manner compared to the asynchronous mode. If RE=1, the data is sampled on CK (rising or falling edge, depending on CPOL and CPHA), without any oversampling. A setup and a hold time must be respected (which depends on the baud rate: 1/16 bit time).

Note: The CK pin works in conjunction with the TX pin. Thus, the clock is provided only if the transmitter is enabled (TE=1) and a data is being transmitted (the data register USART_DR

has been written). This means that it is not possible to receive a synchronous data without transmitting data.

The LBCL, CPOL and CPHA bits have to be selected when both the transmitter and the receiver are disabled (TE=RE=0) to ensure that the clock pulses function correctly. These bits should not be changed while the transmitter or the receiver is enabled.

It is advised that TE and RE are set in the same instruction in order to minimize the setup and the hold time of the receiver.

The USART supports master mode only: it cannot receive or send data related to an input clock (CK is always an output).

Figure 178. USART example of synchronous transmission

Figure 178: USART example of synchronous transmission. A block diagram showing a USART block connected to a Synchronous device (slave SPI). The USART has pins RX, TX, and CK. The RX pin is connected to the Data out pin of the slave. The TX pin is connected to the Data in pin of the slave. The CK pin is connected to the Clock pin of the slave. The slave is labeled 'Synchronous device (slave SPI)'.

MSv31158V2

Figure 178: USART example of synchronous transmission. A block diagram showing a USART block connected to a Synchronous device (slave SPI). The USART has pins RX, TX, and CK. The RX pin is connected to the Data out pin of the slave. The TX pin is connected to the Data in pin of the slave. The CK pin is connected to the Clock pin of the slave. The slave is labeled 'Synchronous device (slave SPI)'.

Figure 179. USART data clock timing diagram (M=0)

Figure 179: USART data clock timing diagram (M=0). A timing diagram showing the relationship between the clock and data lines during a synchronous transmission. The diagram is divided into three main sections: 'Idle or preceding transmission', 'M=0 (8 data bits)', and 'Idle or next Stop transmission'. The 'M=0 (8 data bits)' section shows 8 data bits being transmitted, labeled 0 through 7. The first bit (0) is the LSB and the last bit (7) is the MSB. The clock signal is shown for four different configurations: CPOL=0, CPHA=0; CPOL=0, CPHA=1; CPOL=1, CPHA=0; and CPOL=1, CPHA=1. The data on the TX line (from master) is shown as a series of pulses. The data on the RX line (from slave) is shown as a series of pulses. The capture strobe is shown as a series of pulses. The diagram also includes labels for 'Start', 'Stop', 'LSB', and 'MSB'. A note at the bottom right indicates that the *LBCL bit controls the last data pulse.

MSv31159V2

*LBCL bit controls last data pulse

Figure 179: USART data clock timing diagram (M=0). A timing diagram showing the relationship between the clock and data lines during a synchronous transmission. The diagram is divided into three main sections: 'Idle or preceding transmission', 'M=0 (8 data bits)', and 'Idle or next Stop transmission'. The 'M=0 (8 data bits)' section shows 8 data bits being transmitted, labeled 0 through 7. The first bit (0) is the LSB and the last bit (7) is the MSB. The clock signal is shown for four different configurations: CPOL=0, CPHA=0; CPOL=0, CPHA=1; CPOL=1, CPHA=0; and CPOL=1, CPHA=1. The data on the TX line (from master) is shown as a series of pulses. The data on the RX line (from slave) is shown as a series of pulses. The capture strobe is shown as a series of pulses. The diagram also includes labels for 'Start', 'Stop', 'LSB', and 'MSB'. A note at the bottom right indicates that the *LBCL bit controls the last data pulse.

Figure 180. USART data clock timing diagram (M=1)

Figure 180. USART data clock timing diagram (M=1). This timing diagram illustrates the relationship between the clock (CK), transmit data (TX), and receive data (RX) lines for a 9-bit data frame (M=1). It shows four clock configurations: CPOL=0/CPHA=0, CPOL=0/CPHA=1, CPOL=1/CPHA=0, and CPOL=1/CPHA=1. The data lines (TX and RX) show a Start bit, followed by 9 data bits (0 to 8, LSB to MSB), and a Stop bit. A capture strobe line indicates sampling points. An asterisk (*) on the last clock pulse refers to the note that the LBCL bit controls the last data pulse.

Idle or preceding transmission     Start     M=1 (9 data bits)     Stop     Idle or next transmission

Clock (CPOL=0, CPHA=0)

Clock (CPOL=0, CPHA=1)

Clock (CPOL=1, CPHA=0)

Clock (CPOL=1, CPHA=1)

Data on TX (from master)     Start LSB 0 1 2 3 4 5 6 7 8 MSB Stop

Data on RX (from slave)     Start LSB 0 1 2 3 4 5 6 7 8 MSB Stop

Capture strobe

*LBCL bit controls last data pulse

MSV31160V1

Figure 180. USART data clock timing diagram (M=1). This timing diagram illustrates the relationship between the clock (CK), transmit data (TX), and receive data (RX) lines for a 9-bit data frame (M=1). It shows four clock configurations: CPOL=0/CPHA=0, CPOL=0/CPHA=1, CPOL=1/CPHA=0, and CPOL=1/CPHA=1. The data lines (TX and RX) show a Start bit, followed by 9 data bits (0 to 8, LSB to MSB), and a Stop bit. A capture strobe line indicates sampling points. An asterisk (*) on the last clock pulse refers to the note that the LBCL bit controls the last data pulse.

Figure 181. RX data setup/hold time

Figure 181. RX data setup/hold time diagram. It shows a clock signal CK (capture strobe on CK rising edge) and a data signal on RX. The diagram defines the setup time (tSETUP) as the interval before the clock edge where data must be valid, and the hold time (tHOLD) as the interval after the clock edge where data must remain valid. A note states that tSETUP = tHOLD = 1/16 bit time.

CK (capture strobe on CK rising edge in this example)

Data on RX (from slave)

Valid DATA bit

\( t_{SETUP} \) \( t_{HOLD} \)

\( t_{SETUP} = t_{HOLD} = 1/16 \) bit time

MSV31161V2

Figure 181. RX data setup/hold time diagram. It shows a clock signal CK (capture strobe on CK rising edge) and a data signal on RX. The diagram defines the setup time (tSETUP) as the interval before the clock edge where data must be valid, and the hold time (tHOLD) as the interval after the clock edge where data must remain valid. A note states that tSETUP = tHOLD = 1/16 bit time.

Note: The function of CK is different in Smartcard mode. Refer to the Smartcard mode chapter for more details.

19.3.10 Single-wire half-duplex communication

The single-wire half-duplex mode is selected by setting the HDSEL bit in the USART_CR3 register. In this mode, the following bits must be kept cleared:

The USART can be configured to follow a single-wire half-duplex protocol where the TX and RX lines are internally connected. The selection between half- and full-duplex communication is made with a control bit ‘HALF DUPLEX SEL’ (HDSEL in USART_CR3).

As soon as HDSEL is written to 1:

Apart from this, the communications are similar to what is done in normal USART mode. The conflicts on the line must be managed by the software (by the use of a centralized arbiter, for instance). In particular, the transmission is never blocked by hardware and continue to occur as soon as a data is written in the data register while the TE bit is set.

19.3.11 Smartcard

The Smartcard mode is selected by setting the SCEN bit in the USART_CR3 register. In smartcard mode, the following bits must be kept cleared:

Moreover, the CLKEN bit may be set in order to provide a clock to the smartcard.

The Smartcard interface is designed to support asynchronous protocol Smartcards as defined in the ISO 7816-3 standard. The USART should be configured as:

Note: It is also possible to choose 0.5 stop bit for receiving but it is recommended to use 1.5 stop bits for both transmitting and receiving to avoid switching between the two configurations.

Figure 182 shows examples of what can be seen on the data line with and without parity error.

Figure 182. ISO 7816-3 asynchronous protocol

Figure 182: ISO 7816-3 asynchronous protocol timing diagrams. The top diagram, 'Without Parity error', shows a sequence of bits: S (Start bit), 0, 1, 2, 3, 4, 5, 6, 7, p (parity bit), followed by a Guard time. The bottom diagram, 'With Parity error', shows the same sequence of bits, but after the parity bit 'p', the line is pulled low by the receiver during stop in case of parity error, before the Guard time begins. The diagram is labeled MSv31162V1.
Figure 182: ISO 7816-3 asynchronous protocol timing diagrams. The top diagram, 'Without Parity error', shows a sequence of bits: S (Start bit), 0, 1, 2, 3, 4, 5, 6, 7, p (parity bit), followed by a Guard time. The bottom diagram, 'With Parity error', shows the same sequence of bits, but after the parity bit 'p', the line is pulled low by the receiver during stop in case of parity error, before the Guard time begins. The diagram is labeled MSv31162V1.

When connected to a Smartcard, the TX output of the USART drives a bidirectional line that is also driven by the Smartcard. The TX pin must be configured as open-drain.

Smartcard is a single wire half duplex communication protocol.

shifting on the next baud clock edge. In Smartcard mode this transmission is further delayed by a guaranteed 1/2 baud clock.

Note: A break character is not significant in Smartcard mode. A 0x00 data with a framing error is treated as data and not as a break.

No Idle frame is transmitted when toggling the TE bit. The Idle frame (as defined for the other configurations) is not defined by the ISO protocol.

Figure 183 details how the NACK signal is sampled by the USART. In this example the USART is transmitting a data and is configured with 1.5 stop bits. The receiver part of the USART is enabled in order to check the integrity of the data and the NACK signal.

Figure 183. Parity error detection using the 1.5 stop bits

Timing diagram for parity error detection using 1.5 stop bits. The diagram shows two rows of signal levels over time. The top row represents the transmitted signal, and the bottom row represents the received signal. The transmitted signal consists of Bit 7, a Parity bit, and a 1.5 Stop bit. The Parity bit and Stop bit are each 1 bit time long. The Stop bit is split into two 0.5 bit time segments. The received signal shows sampling points at the 8th, 9th, and 10th bit times for both the Parity bit and the Stop bit. The diagram illustrates that the receiver samples the Parity bit and the first 0.5 bit time of the Stop bit, while the second 0.5 bit time of the Stop bit is ignored.

The diagram illustrates the timing for parity error detection with 1.5 stop bits. It shows two horizontal lines representing signal levels. The top line represents the transmitted signal, and the bottom line represents the received signal. The transmitted signal is divided into three segments: Bit 7 (1 bit time), Parity bit (1 bit time), and 1.5 Stop bit (1.5 bit times). The Stop bit is further divided into two 0.5 bit time segments. The received signal shows sampling points at the 8th, 9th, and 10th bit times for both the Parity bit and the Stop bit. The diagram indicates that the receiver samples the Parity bit and the first 0.5 bit time of the Stop bit, while the second 0.5 bit time of the Stop bit is ignored. The label 'MSv31163V1' is present in the bottom right corner of the diagram.

Timing diagram for parity error detection using 1.5 stop bits. The diagram shows two rows of signal levels over time. The top row represents the transmitted signal, and the bottom row represents the received signal. The transmitted signal consists of Bit 7, a Parity bit, and a 1.5 Stop bit. The Parity bit and Stop bit are each 1 bit time long. The Stop bit is split into two 0.5 bit time segments. The received signal shows sampling points at the 8th, 9th, and 10th bit times for both the Parity bit and the Stop bit. The diagram illustrates that the receiver samples the Parity bit and the first 0.5 bit time of the Stop bit, while the second 0.5 bit time of the Stop bit is ignored.

The USART can provide a clock to the smartcard through the CK output. In smartcard mode, CK is not associated to the communication but is simply derived from the internal peripheral input clock through a 5-bit prescaler. The division ratio is configured in the

prescaler register USART_GTPR. CK frequency can be programmed from \( f_{CK}/2 \) to \( f_{CK}/62 \) , where \( f_{CK} \) is the peripheral input clock.

19.3.12 IrDA SIR ENDEC block

The IrDA mode is selected by setting the IREN bit in the USART_CR3 register. In IrDA mode, the following bits must be kept cleared:

The IrDA SIR physical layer specifies use of a Return to Zero, Inverted (RZI) modulation scheme that represents logic 0 as an infrared light pulse (see Figure 184 ).

The SIR Transmit encoder modulates the Non Return to Zero (NRZ) transmit bit stream output from USART. The output pulse stream is transmitted to an external output driver and infrared LED. USART supports only bit rates up to 115.2Kbps for the SIR ENDEC. In normal mode the transmitted pulse width is specified as 3/16 of a bit period.

The SIR receive decoder demodulates the return-to-zero bit stream from the infrared detector and outputs the received NRZ serial bit stream to USART. The decoder input is normally HIGH (marking state) in the Idle state. The transmit encoder output has the opposite polarity to the decoder input. A start bit is detected when the decoder input is low.

IrDA low-power mode

Transmitter:

In low-power mode the pulse width is not maintained at 3/16 of the bit period. Instead, the width of the pulse is 3 times the low-power baud rate which can be a minimum of 1.42 MHz. Generally this value is 1.8432 MHz ( \( 1.42\text{ MHz} < \text{PSC} < 2.12\text{ MHz} \) ). A low-power mode programmable divisor divides the system clock to achieve this value.

Receiver:

Receiving in low-power mode is similar to receiving in normal mode. For glitch detection the USART should discard pulses of duration shorter than \( 1/\text{PSC} \) . A valid low is accepted only if its duration is greater than 2 periods of the IrDA low-power Baud clock (PSC value in USART_GTPR).

Note:

A pulse of width less than two and greater than one PSC period(s) may or may not be rejected.

The receiver set up time should be managed by software. The IrDA physical layer specification specifies a minimum of 10 ms delay between transmission and reception (IrDA is a half duplex protocol).

Figure 184. IrDA SIR ENDEC- block diagram

Figure 184. IrDA SIR ENDEC- block diagram. A block diagram showing the USART block on the left connected to an IrDA block. The IrDA block contains a SIR Transmit Encoder receiving TX from USART, and a SIR Receive DEcoder sending RX to USART. A SIREN signal also comes from USART. The SIR Transmit Encoder output goes through a multiplexer to USART_TX. USART_RX comes from an external source, passes through a multiplexer, and enters the SIR Receive DEcoder. Reference MSv31164V.
Figure 184. IrDA SIR ENDEC- block diagram. A block diagram showing the USART block on the left connected to an IrDA block. The IrDA block contains a SIR Transmit Encoder receiving TX from USART, and a SIR Receive DEcoder sending RX to USART. A SIREN signal also comes from USART. The SIR Transmit Encoder output goes through a multiplexer to USART_TX. USART_RX comes from an external source, passes through a multiplexer, and enters the SIR Receive DEcoder. Reference MSv31164V.

Figure 185. IrDA data modulation (3/16) -Normal mode

Figure 185. IrDA data modulation (3/16) -Normal mode. Timing diagram showing four signals: TX, IrDA_OUT, IrDA_IN, and RX. TX shows a bit sequence: Start bit 0, then 1, 0, 1, 0, 0, 1, 1, 0, and Stop bit 1. IrDA_OUT shows narrow pulses corresponding to the '0' bits in TX. The pulse width is labeled as 3/16 of the bit period. IrDA_IN shows the received pulses. RX shows the reconstructed bit sequence matching TX. Reference MSv31165V1.
Figure 185. IrDA data modulation (3/16) -Normal mode. Timing diagram showing four signals: TX, IrDA_OUT, IrDA_IN, and RX. TX shows a bit sequence: Start bit 0, then 1, 0, 1, 0, 0, 1, 1, 0, and Stop bit 1. IrDA_OUT shows narrow pulses corresponding to the '0' bits in TX. The pulse width is labeled as 3/16 of the bit period. IrDA_IN shows the received pulses. RX shows the reconstructed bit sequence matching TX. Reference MSv31165V1.

19.3.13 Continuous communication using DMA

The USART is capable of continuous communication using the DMA. The DMA requests for Rx buffer and Tx buffer are generated independently.

Transmission using DMA

DMA mode can be enabled for transmission by setting DMAT bit in the USART_CR3 register. Data is loaded from a SRAM area configured using the DMA peripheral (refer to the DMA specification) to the USART_DR register whenever the TXE bit is set. To map a DMA channel for USART transmission, use the following procedure (x denotes the channel number):

  1. 1. Write the USART_DR register address in the DMA control register to configure it as the destination of the transfer. The data are moved to this address from memory after each TXE event.
  2. 2. Write the memory address in the DMA control register to configure it as the source of the transfer. The data are loaded into the USART_DR register from this memory area after each TXE event.
  3. 3. Configure the total number of bytes to be transferred to the DMA control register.
  4. 4. Configure the channel priority in the DMA register
  5. 5. Configure DMA interrupt generation after half/ full transfer as required by the application.
  6. 6. Clear the TC bit in the SR register by writing 0 to it.
  7. 7. Activate the channel in the DMA register.

When the number of data transfers programmed in the DMA Controller is reached, the DMA controller generates an interrupt on the DMA channel interrupt vector.

In transmission mode, once the DMA has written all the data to be transmitted (the TCIF flag is set in the DMA_ISR register), the TC flag can be monitored to make sure that the USART communication is complete. This is required to avoid corrupting the last transmission before disabling the USART or entering the Stop mode. The software must wait until TC=1. The TC flag remains cleared during all data transfers and it is set by hardware at the last frame's end of transmission.

Figure 186. Transmission using DMA

Timing diagram for USART transmission using DMA. The diagram shows the relationship between the TX line, TXE flag, DMA request, USART_DR register, TC flag, and DMA writes. It illustrates the sequence of events for sending three frames (F1, F2, F3) via DMA. The TX line starts with an idle preamble, then Frame 1, Frame 2, and Frame 3. The TXE flag is set by hardware and cleared by DMA read. The DMA request is set by hardware and ignored by the DMA because the DMA transfer is complete. The USART_DR register contains F1, F2, and F3. The TC flag is set by hardware and clear by software. The DMA writes are shown as F1, F2, and F3 into the USART_DR register. The DMA TCIF (Transfer complete) flag is set by hardware and clear by software. The software configures the DMA to send 3 data and enables the USART. The DMA writes F1 into USART_DR, F2 into USART_DR, and F3 into USART_DR. The DMA transfer is complete (TCIF=1 in DMA_ISR). The software waits until TC=1.

The diagram illustrates the timing and sequence of events for USART transmission using DMA. The TX line shows an idle preamble followed by three frames (F1, F2, F3). The TXE flag is set by hardware and cleared by DMA read. The DMA request is set by hardware and ignored by the DMA because the DMA transfer is complete. The USART_DR register contains F1, F2, and F3. The TC flag is set by hardware and clear by software. The DMA writes are shown as F1, F2, and F3 into the USART_DR register. The DMA TCIF (Transfer complete) flag is set by hardware and clear by software. The software configures the DMA to send 3 data and enables the USART. The DMA writes F1 into USART_DR, F2 into USART_DR, and F3 into USART_DR. The DMA transfer is complete (TCIF=1 in DMA_ISR). The software waits until TC=1.

Timing diagram for USART transmission using DMA. The diagram shows the relationship between the TX line, TXE flag, DMA request, USART_DR register, TC flag, and DMA writes. It illustrates the sequence of events for sending three frames (F1, F2, F3) via DMA. The TX line starts with an idle preamble, then Frame 1, Frame 2, and Frame 3. The TXE flag is set by hardware and cleared by DMA read. The DMA request is set by hardware and ignored by the DMA because the DMA transfer is complete. The USART_DR register contains F1, F2, and F3. The TC flag is set by hardware and clear by software. The DMA writes are shown as F1, F2, and F3 into the USART_DR register. The DMA TCIF (Transfer complete) flag is set by hardware and clear by software. The software configures the DMA to send 3 data and enables the USART. The DMA writes F1 into USART_DR, F2 into USART_DR, and F3 into USART_DR. The DMA transfer is complete (TCIF=1 in DMA_ISR). The software waits until TC=1.

Reception using DMA

DMA mode can be enabled for reception by setting the DMAR bit in USART_CR3 register. Data is loaded from the USART_DR register to a SRAM area configured using the DMA peripheral (refer to the DMA specification) whenever a data byte is received. To map a DMA channel for USART reception, use the following procedure:

  1. 1. Write the USART_DR register address in the DMA control register to configure it as the source of the transfer. The data are moved from this address to the memory after each RXNE event.
  2. 2. Write the memory address in the DMA control register to configure it as the destination of the transfer. The data are loaded from USART_DR to this memory area after each RXNE event.
  3. 3. Configure the total number of bytes to be transferred in the DMA control register.
  4. 4. Configure the channel priority in the DMA control register
  5. 5. Configure interrupt generation after half/ full transfer as required by the application.
  6. 6. Activate the channel in the DMA control register.

When the number of data transfers programmed in the DMA Controller is reached, the DMA controller generates an interrupt on the DMA channel interrupt vector. The DMAR bit should be cleared by software in the USART_CR3 register during the interrupt subroutine.

Figure 187. Reception using DMA

Timing diagram for Figure 187: Reception using DMA. The diagram shows the sequence of events for receiving three frames (Frame 1, Frame 2, Frame 3) via DMA. The TX line is shown as a series of pulses for each frame. The RXNE flag is set by hardware when the first byte of a frame is received and cleared by the DMA read. The DMA request is generated when the RXNE flag is set. The USART_DR register contains the received bytes (F1, F2, F3). The DMA reads the USART_DR register when the DMA request is active. The DMA TCIF flag (Transfer complete) is set by hardware when the last byte of a frame is received and cleared by software. Callouts indicate: 'software configures the DMA to receive 3 data blocks and enables the USART', 'DMA reads F1 from USART_DR', 'DMA reads F2 from USART_DR', 'DMA reads F3 from USART_DR', and 'The DMA transfer is complete (TCIF=1 in DMA_ISR)'.
Timing diagram for Figure 187: Reception using DMA. The diagram shows the sequence of events for receiving three frames (Frame 1, Frame 2, Frame 3) via DMA. The TX line is shown as a series of pulses for each frame. The RXNE flag is set by hardware when the first byte of a frame is received and cleared by the DMA read. The DMA request is generated when the RXNE flag is set. The USART_DR register contains the received bytes (F1, F2, F3). The DMA reads the USART_DR register when the DMA request is active. The DMA TCIF flag (Transfer complete) is set by hardware when the last byte of a frame is received and cleared by software. Callouts indicate: 'software configures the DMA to receive 3 data blocks and enables the USART', 'DMA reads F1 from USART_DR', 'DMA reads F2 from USART_DR', 'DMA reads F3 from USART_DR', and 'The DMA transfer is complete (TCIF=1 in DMA_ISR)'.

Error flagging and interrupt generation in multibuffer communication

In case of multibuffer communication if any error occurs during the transaction the error flag is asserted after the current byte. An interrupt is generated if the interrupt enable flag is set. For framing error, overrun error and noise flag which are asserted with RXNE in case of single byte reception, there is a separate error flag interrupt enable bit (EIE bit in the USART_CR3 register), which if set, issues an interrupt after the current byte with either of these errors.

19.3.14 Hardware flow control

It is possible to control the serial data flow between 2 devices by using the CTS input and the RTS output. The Figure 188 shows how to connect 2 devices in this mode:

Figure 188. Hardware flow control between 2 USARTs

Block diagram for Figure 188: Hardware flow control between 2 USARTs. The diagram shows two USARTs, USART 1 and USART 2, connected via their TX and RX lines. USART 1's TX circuit is connected to USART 2's RX circuit. USART 1's RX circuit is connected to USART 2's TX circuit. Flow control lines are also connected: USART 1's CTS input is connected to USART 2's RTS output, and USART 1's RTS output is connected to USART 2's CTS input.
Block diagram for Figure 188: Hardware flow control between 2 USARTs. The diagram shows two USARTs, USART 1 and USART 2, connected via their TX and RX lines. USART 1's TX circuit is connected to USART 2's RX circuit. USART 1's RX circuit is connected to USART 2's TX circuit. Flow control lines are also connected: USART 1's CTS input is connected to USART 2's RTS output, and USART 1's RTS output is connected to USART 2's CTS input.

RTS and CTS flow control can be enabled independently by writing respectively RTSE and CTSE bits to 1 (in the USART_CR3 register).

RTS flow control

If the RTS flow control is enabled (RTSE=1), then RTS is asserted (tied low) as long as the USART receiver is ready to receive a new data. When the receive register is full, RTS is deasserted, indicating that the transmission is expected to stop at the end of the current frame. Figure 189 shows an example of communication with RTS flow control enabled.

Figure 189. RTS flow control

Timing diagram for RTS flow control showing RX and RTS signals over time.

The diagram illustrates the relationship between the RX (receive) signal and the RTS (Request To Send) signal during two data transmissions. The RX signal shows two frames: the first contains 'Start bit', 'Data 1', and 'Stop bit'; the second contains 'Start bit', 'Data 2', and 'Stop bit'. Vertical dashed lines mark the start and end of each frame, with an 'Idle' period between them. The RTS signal is initially high. It drops to low at the start of the first frame (marked by RXNE↑). It returns to high at the end of the first frame (marked by RXNE↓). It drops to low again at the start of the second frame (marked by RXNE↑). It returns to high at the end of the second frame (marked by RXNE↓). Between the two frames, a label indicates 'Data 1 read' and 'Data 2 can now be transmitted'.

Timing diagram for RTS flow control showing RX and RTS signals over time.

CTS flow control

If the CTS flow control is enabled (CTSE=1), then the transmitter checks the CTS input before transmitting the next frame. If CTS is asserted (tied low), then the next data is transmitted (assuming that a data is to be transmitted, in other words, if TXE=0), else the transmission does not occur. When CTS is deasserted during a transmission, the current transmission is completed before the transmitter stops.

When CTSE=1, the CTSIF status bit is automatically set by hardware as soon as the CTS input toggles. It indicates when the receiver becomes ready or not ready for communication. An interrupt is generated if the CTSIE bit in the USART_CR3 register is set. The figure below shows an example of communication with CTS flow control enabled.

Figure 190. CTS flow control

Timing diagram for CTS flow control showing CTS signal, Transmit data register (TDR), and TX line states over time. It illustrates how the transmission of Data 3 is delayed until the CTS signal goes low.

The diagram illustrates the CTS flow control mechanism across three horizontal timelines:

Key events and annotations:

Timing diagram for CTS flow control showing CTS signal, Transmit data register (TDR), and TX line states over time. It illustrates how the transmission of Data 3 is delayed until the CTS signal goes low.

Note: Special behavior of break frames: when the CTS flow is enabled, the transmitter does not check the CTS input state to send a break.

19.4 USART interrupts

Table 86. USART interrupt requests

Interrupt eventEvent flagEnable control bit
Transmit Data Register EmptyTXETXEIE
CTS flagCTSCTSIE
Transmission CompleteTCTCIE
Received Data Ready to be ReadRXNERXNEIE
Overrun Error DetectedORE
Idle Line DetectedIDLEIDLEIE
Parity ErrorPEPEIE
Break FlagLBDLBDIE
Noise Flag, Overrun error and Framing Error in multibuffer communicationNF or ORE or FEEIE

The USART interrupt events are connected to the same interrupt vector (see Figure 191 ).

These events generate an interrupt if the corresponding Enable Control Bit is set.

Figure 191. USART interrupt mapping diagram

Figure 191. USART interrupt mapping diagram. This logic diagram shows how various USART flags and enable bits are combined using AND and OR gates to generate a single USART interrupt signal. The diagram is organized into three main horizontal sections. The top section takes TC, TXE, and CTS flags and their corresponding enable bits (TCIE, TXEIE, CTSIE) through AND gates, then combines their outputs with an OR gate. The middle section takes IDLE, RXNE, ORE, PE, and LBD flags and their enable bits (IDLEIE, RXNEIE, ORE, PEIE, LBDIE) through AND gates, then combines these with an OR gate. The bottom section takes NF, NE, and FE flags through an OR gate, then combines this result with the EIE and DMAR enable bits through an AND gate. Finally, the outputs of the three main OR gates are combined with a large OR gate to produce the final 'USART interrupt' signal. The diagram is labeled MSV42089V1 in the bottom right corner.
Figure 191. USART interrupt mapping diagram. This logic diagram shows how various USART flags and enable bits are combined using AND and OR gates to generate a single USART interrupt signal. The diagram is organized into three main horizontal sections. The top section takes TC, TXE, and CTS flags and their corresponding enable bits (TCIE, TXEIE, CTSIE) through AND gates, then combines their outputs with an OR gate. The middle section takes IDLE, RXNE, ORE, PE, and LBD flags and their enable bits (IDLEIE, RXNEIE, ORE, PEIE, LBDIE) through AND gates, then combines these with an OR gate. The bottom section takes NF, NE, and FE flags through an OR gate, then combines this result with the EIE and DMAR enable bits through an AND gate. Finally, the outputs of the three main OR gates are combined with a large OR gate to produce the final 'USART interrupt' signal. The diagram is labeled MSV42089V1 in the bottom right corner.

19.5 USART mode configuration

Table 87. USART mode configuration (1)

USART modesUSART1USART2USART6
Asynchronous modeXXX
Hardware flow controlXXX
Multibuffer communication (DMA)XXX
Multiprocessor communicationXXX
SynchronousXXX
SmartcardXXX
Half-duplex (single-wire mode)XXX
IrDAXXX
LINXXX

1. X = supported; NA = not applicable.

19.6 USART registers

Refer to Section 1.1: List of abbreviations for registers for registers for a list of abbreviations used in register descriptions.

The peripheral registers have to be accessed by half-words (16 bits) or words (32 bits).

19.6.1 Status register (USART_SR)

Address offset: 0x00

Reset value: 0x00C0 0000

31302928272625242322212019181716
Reserved
1514131211109876543210
ReservedCTSLBDTXETCRXNEIDLEORENFFE
rc_w0rc_w0rrc_w0rc_w0rrrr

Bits 31:10 Reserved, must be kept at reset value

Bit 9 CTS : CTS flag

This bit is set by hardware when the CTS input toggles, if the CTSE bit is set. It is cleared by software (by writing it to 0). An interrupt is generated if CTSIE=1 in the USART_CR3 register.

Note: 0: No change occurred on the CTS status line
1: A change occurred on the CTS status line

Bit 8 LBD : LIN break detection flag

This bit is set by hardware when the LIN break is detected. It is cleared by software (by writing it to 0). An interrupt is generated if LBDIE = 1 in the USART_CR2 register.

0: LIN Break not detected
1: LIN break detected

Note: An interrupt is generated when LBD=1 if LBDIE=1

Bit 7 TXE: Transmit data register empty

This bit is set by hardware when the content of the TDR register has been transferred into the shift register. An interrupt is generated if the TXEIE bit =1 in the USART_CR1 register. It is cleared by a write to the USART_DR register.

0: Data is not transferred to the shift register

1: Data is transferred to the shift register)

Note: This bit is used during single buffer transmission.

Bit 6 TC: Transmission complete

This bit is set by hardware if the transmission of a frame containing data is complete and if TXE is set. An interrupt is generated if TCIE=1 in the USART_CR1 register. It is cleared by a software sequence (a read from the USART_SR register followed by a write to the USART_DR register). The TC bit can also be cleared by writing a '0' to it. This clearing sequence is recommended only for multibuffer communication.

0: Transmission is not complete

1: Transmission is complete

Bit 5 RXNE: Read data register not empty

This bit is set by hardware when the content of the RDR shift register has been transferred to the USART_DR register. An interrupt is generated if RXNEIE=1 in the USART_CR1 register. It is cleared by a read to the USART_DR register. The RXNE flag can also be cleared by writing a zero to it. This clearing sequence is recommended only for multibuffer communication.

0: Data is not received

1: Received data is ready to be read.

Bit 4 IDLE: IDLE line detected

This bit is set by hardware when an Idle Line is detected. An interrupt is generated if the IDLEIE=1 in the USART_CR1 register. It is cleared by a software sequence (an read to the USART_SR register followed by a read to the USART_DR register).

0: No Idle Line is detected

1: Idle Line is detected

Note: The IDLE bit is not set again until the RXNE bit has been set itself (a new idle line occurs).

Bit 3 ORE: Overrun error

This bit is set by hardware when the word currently being received in the shift register is ready to be transferred into the RDR register while RXNE=1. An interrupt is generated if RXNEIE=1 in the USART_CR1 register. It is cleared by a software sequence (an read to the USART_SR register followed by a read to the USART_DR register).

0: No Overrun error

1: Overrun error is detected

Note: When this bit is set, the RDR register content is not lost but the shift register is overwritten. An interrupt is generated on ORE flag in case of Multi Buffer communication if the EIE bit is set.

Bit 2 NF: Noise detected flag

This bit is set by hardware when noise is detected on a received frame. It is cleared by a software sequence (an read to the USART_SR register followed by a read to the USART_DR register).

0: No noise is detected

1: Noise is detected

Note: This bit does not generate interrupt as it appears at the same time as the RXNE bit which itself generates an interrupting interrupt is generated on NF flag in case of Multi Buffer communication if the EIE bit is set.

Note: When the line is noise-free, the NF flag can be disabled by programming the ONEBIT bit to 1 to increase the USART tolerance to deviations (Refer to Section 19.3.5: USART receiver tolerance to clock deviation on page 525 ).

Bit 1 FE: Framing error

This bit is set by hardware when a de-synchronization, excessive noise or a break character is detected. It is cleared by a software sequence (an read to the USART_SR register followed by a read to the USART_DR register).

0: No Framing error is detected

1: Framing error or break character is detected

Note: This bit does not generate interrupt as it appears at the same time as the RXNE bit which itself generates an interrupt. If the word currently being transferred causes both frame error and overrun error, it is transferred and only the ORE bit is set.

An interrupt is generated on FE flag in case of Multi Buffer communication if the EIE bit is set.

Bit 0 PE: Parity error

This bit is set by hardware when a parity error occurs in receiver mode. It is cleared by a software sequence (a read from the status register followed by a read or write access to the USART_DR data register). The software must wait for the RXNE flag to be set before clearing the PE bit.

An interrupt is generated if PEIE = 1 in the USART_CR1 register.

0: No parity error

1: Parity error

19.6.2 Data register (USART_DR)

Address offset: 0x04

Reset value: 0xXXXX XXXX

Bits 31:9 Reserved, must be kept at reset value

Bits 8:0 DR[8:0] : Data value

Contains the Received or Transmitted data character, depending on whether it is read from or written to.

The Data register performs a double function (read and write) since it is composed of two registers, one for transmission (TDR) and one for reception (RDR)

The TDR register provides the parallel interface between the internal bus and the output shift register (see Figure 167: USART block diagram ).

The RDR register provides the parallel interface between the input shift register and the internal bus.

When transmitting with the parity enabled (PCE bit set to 1 in the USART_CR1 register), the value written in the MSB (bit 7 or bit 8 depending on the data length) has no effect because it is replaced by the parity.

When receiving with the parity enabled, the value read in the MSB bit is the received parity bit.

19.6.3 Baud rate register (USART_BRR)

Note: The baud counters stop counting if the TE or RE bits are disabled respectively.

Address offset: 0x08

Reset value: 0x0000 0000

31302928272625242322212019181716
Reserved
1514131211109876543210
DIV_Mantissa[11:0]DIV_Fraction[3:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:16 Reserved, must be kept at reset value

Bits 15:4 DIV_Mantissa[11:0] : mantissa of USARTDIV

These 12 bits define the mantissa of the USART Divider (USARTDIV)

Bits 3:0 DIV_Fraction[3:0] : fraction of USARTDIV

These 4 bits define the fraction of the USART Divider (USARTDIV). When OVER8=1, the DIV_Fraction3 bit is not considered and must be kept cleared.

19.6.4 Control register 1 (USART_CR1)

Address offset: 0x0C

Reset value: 0x0000 0000

31302928272625242322212019181716
Reserved
1514131211109876543210
OVER8ReservedUEMWAKEPCEPSPEIETXEIETCIERXNEIEIDLEIETERERWUSBK
rwRes.rwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:16 Reserved, must be kept at reset value

Bit 15 OVER8 : Oversampling mode

0: oversampling by 16

1: oversampling by 8

Note: Oversampling by 8 is not available in the Smartcard, IrDA and LIN modes: when SCEN=1, IREN=1 or LINEN=1 then OVER8 is forced to '0' by hardware.

Bit 14 Reserved, must be kept at reset value

Bit 13 UE : USART enable

When this bit is cleared, the USART prescalers and outputs are stopped and the end of the current byte transfer in order to reduce power consumption. This bit is set and cleared by software.

0: USART prescaler and outputs disabled

1: USART enabled

Bit 12 M : Word length

This bit determines the word length. It is set or cleared by software.

0: 1 Start bit, 8 Data bits, n Stop bit

1: 1 Start bit, 9 Data bits, n Stop bit

Note: The M bit must not be modified during a data transfer (both transmission and reception)

Bit 11 WAKE : Wake-up method

This bit determines the USART wake-up method, it is set or cleared by software.

0: Idle Line

1: Address Mark

Bit 10 PCE : Parity control enable

This bit selects the hardware parity control (generation and detection). When the parity control is enabled, the computed parity is inserted at the MSB position (9th bit if M=1; 8th bit if M=0) and parity is checked on the received data. This bit is set and cleared by software. Once it is set, PCE is active after the current byte (in reception and in transmission).

0: Parity control disabled

1: Parity control enabled

Bit 9 PS : Parity selection

This bit selects the odd or even parity when the parity generation/detection is enabled (PCE bit set). It is set and cleared by software. The parity is selected after the current byte.

0: Even parity

1: Odd parity

Bit 8 PEIE : PE interrupt enable

This bit is set and cleared by software.

0: Interrupt is inhibited

1: An USART interrupt is generated whenever PE=1 in the USART_SR register

Bit 7 TXEIE : TXE interrupt enable

This bit is set and cleared by software.

0: Interrupt is inhibited

1: An USART interrupt is generated whenever TXE=1 in the USART_SR register

Bit 6 TCIE : Transmission complete interrupt enable

This bit is set and cleared by software.

0: Interrupt is inhibited

1: An USART interrupt is generated whenever TC=1 in the USART_SR register

Bit 5 RXNEIE: RXNE interrupt enable

This bit is set and cleared by software.

0: Interrupt is inhibited

1: An USART interrupt is generated whenever ORE=1 or RXNE=1 in the USART_SR register

Bit 4 IDLEIE: IDLE interrupt enable

This bit is set and cleared by software.

0: Interrupt is inhibited

1: An USART interrupt is generated whenever IDLE=1 in the USART_SR register

Bit 3 TE: Transmitter enable

This bit enables the transmitter. It is set and cleared by software.

0: Transmitter is disabled

1: Transmitter is enabled

Note: During transmission, a “0” pulse on the TE bit (“0” followed by “1”) sends a preamble (idle line) after the current word, except in smartcard mode.

When TE is set, there is a 1 bit-time delay before the transmission starts.

Bit 2 RE: Receiver enable

This bit enables the receiver. It is set and cleared by software.

0: Receiver is disabled

1: Receiver is enabled and begins searching for a start bit

Bit 1 RWU: Receiver wake-up

This bit determines if the USART is in mute mode or not. It is set and cleared by software and can be cleared by hardware when a wake-up sequence is recognized.

0: Receiver in active mode

1: Receiver in mute mode

Note: Before selecting Mute mode (by setting the RWU bit) the USART must first receive a data byte, otherwise it cannot function in Mute mode with wake-up by Idle line detection.

In Address Mark Detection wake-up configuration (WAKE bit=1) the RWU bit cannot be modified by software while the RXNE bit is set.

Bit 0 SBK: Send break

This bit set is used to send break characters. It can be set and cleared by software. It should be set by software, and is reset by hardware during the stop bit of break.

0: No break character is transmitted.

1: Break character is transmitted.

19.6.5 Control register 2 (USART_CR2)

Address offset: 0x10

Reset value: 0x0000 0000

31302928272625242322212019181716
Reserved
1514131211109876543210
Res.LINENSTOP[1:0]CLKENCPOLCPHALBCLRes.LBDIELBDLRes.ADD[3:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:15 Reserved, must be kept at reset value

Bit 14 LINEN : LIN mode enable

This bit is set and cleared by software.

0: LIN mode disabled

1: LIN mode enabled

The LIN mode enables the capability to send LIN Sync Breaks (13 low bits) using the SBK bit in the USART_CR1 register, and to detect LIN Sync breaks.

Bits 13:12 STOP : STOP bits

These bits are used for programming the stop bits.

00: 1 Stop bit

01: 0.5 Stop bit

10: 2 Stop bits

Note: 11: 1.5 Stop bit

Bit 11 CLKEN : Clock enable

This bit allows the user to enable the CK pin.

0: CK pin disabled

1: CK pin enabled

Bit 10 CPOL : Clock polarity

This bit allows the user to select the polarity of the clock output on the CK pin in synchronous mode.

It works in conjunction with the CPHA bit to produce the desired clock/data relationship

0: Steady low value on CK pin outside transmission window.

1: Steady high value on CK pin outside transmission window.

Bit 9 CPHA : Clock phase

This bit allows the user to select the phase of the clock output on the CK pin in synchronous mode.

It works in conjunction with the CPOL bit to produce the desired clock/data relationship (see figures 179 to 180 )

Note: 0: The first clock transition is the first data capture edge

1: The second clock transition is the first data capture edge

Bit 8 LBCL : Last bit clock pulse

This bit allows the user to select whether the clock pulse associated with the last data bit transmitted (MSB) has to be output on the CK pin in synchronous mode.

0: The clock pulse of the last data bit is not output to the CK pin

1: The clock pulse of the last data bit is output to the CK pin

1: The last bit is the 8th or 9th data bit transmitted depending on the 8 or 9 bit format selected by the M bit in the USART_CR1 register.

Bit 7 Reserved, must be kept at reset value

Bit 6 LBDIE : LIN break detection interrupt enable

Break interrupt mask (break detection using break delimiter).

0: Interrupt is inhibited

1: An interrupt is generated whenever LBD=1 in the USART_SR register

Bit 5 LBDL : lin break detection length

This bit is for selection between 11 bit or 10 bit break detection.

0: 10-bit break detection

1: 11-bit break detection

Bit 4 Reserved, must be kept at reset value

Bits 3:0 ADD[3:0] : Address of the USART node

This bit-field gives the address of the USART node.

This is used in multiprocessor communication during mute mode, for wake up with address mark detection.

Note: These 3 bits (CPOL, CPHA, LBCL) should not be written while the transmitter is enabled.

19.6.6 Control register 3 (USART_CR3)

Address offset: 0x14

Reset value: 0x0000 0000

31302928272625242322212019181716
Reserved
1514131211109876543210
ReservedONEBITCTSIECTSERTSEDMATDMARSCENNACKHDSELIRLPIRENEIE
rwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:12 Reserved, must be kept at reset value

Bit 11 ONEBIT : One sample bit method enable

This bit allows the user to select the sample method. When the one sample bit method is selected the noise detection flag (NF) is disabled.

0: Three sample bit method

1: One sample bit method

Note: The ONEBIT feature applies only to data bits. It does not apply to START bit.

Bit 10 CTSIE : CTS interrupt enable

Note: 0: Interrupt is inhibited

1: An interrupt is generated whenever CTS=1 in the USART_SR register

Bit 9 CTSE : CTS enable

0: CTS hardware flow control disabled

Note: 1: CTS mode enabled, data is only transmitted when the CTS input is asserted (tied to 0). If the CTS input is deasserted while a data is being transmitted, then the transmission is completed before stopping. If a data is written into the data register while CTS is deasserted, the transmission is postponed until CTS is asserted.

Bit 8 RTSE : RTS enable

0: RTS hardware flow control disabled

Note: 1: RTS interrupt enabled, data is only requested when there is space in the receive buffer. The transmission of data is expected to cease after the current character has been transmitted. The RTS output is asserted (tied to 0) when a data can be received.

Bit 7 DMAT : DMA enable transmitter

This bit is set/reset by software

1: DMA mode is enabled for transmission.

0: DMA mode is disabled for transmission.

Bit 6 DMAR : DMA enable receiver

This bit is set/reset by software

1: DMA mode is enabled for reception

0: DMA mode is disabled for reception

Bit 5 SCEN : Smartcard mode enable

This bit is used for enabling Smartcard mode.

Note: 0: Smartcard Mode disabled

1: Smartcard Mode enabled

Bit 4 NACK : Smartcard NACK enable

Note: 0: NACK transmission in case of parity error is disabled

1: NACK transmission during parity error is enabled

Bit 3 HDSEL : Half-duplex selection

Selection of Single-wire Half-duplex mode

0: Half duplex mode is not selected

1: Half duplex mode is selected

Bit 2 IRLP : IrDA low-power

This bit is used for selecting between normal and low-power IrDA modes

0: Normal mode

1: Low-power mode

Bit 1 IREN : IrDA mode enable

This bit is set and cleared by software.

0: IrDA disabled

1: IrDA enabled

Bit 0 EIE : Error interrupt enable

Error Interrupt Enable Bit is required to enable interrupt generation in case of a framing error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the USART_SR register) in case of Multi Buffer Communication (DMAR=1 in the USART_CR3 register).

0: Interrupt is inhibited

1: An interrupt is generated whenever DMAR=1 in the USART_CR3 register and FE=1 or ORE=1 or NF=1 in the USART_SR register.

19.6.7 Guard time and prescaler register (USART_GTPR)

Address offset: 0x18

Reset value: 0x0000 0000

31302928272625242322212019181716
Reserved
1514131211109876543210
GT[7:0]PSC[7:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:16 Reserved, must be kept at reset value

Bits 15:8 GT[7:0] : Guard time value

This bit-field gives the Guard time value in terms of number of baud clocks.

Note: This is used in Smartcard mode. The Transmission Complete flag is set after this guard time value.

Bits 7:0 PSC[7:0] : Prescaler value

– In IrDA Low-power mode :

PSC[7:0] = IrDA Low-Power Baud Rate

Used for programming the prescaler for dividing the system clock to achieve the low-power frequency:

The source clock is divided by the value given in the register (8 significant bits):

00000000: Reserved - do not program this value

00000001: divides the source clock by 1

00000010: divides the source clock by 2

...

– In normal IrDA mode : PSC must be set to 00000001.

– In smartcard mode:

PSC[4:0] : Prescaler value

Used for programming the prescaler for dividing the system clock to provide the smartcard clock.

The value given in the register (5 significant bits) is multiplied by 2 to give the division factor of the source clock frequency:

00000: Reserved - do not program this value

00001: divides the source clock by 2

00010: divides the source clock by 4

00011: divides the source clock by 6

...

Note: 1: Bits [7:5] have no effect if Smartcard mode is used.

19.6.8 USART register map

The table below gives the USART register map and reset values.

Table 88. USART register map and reset values

OffsetRegister313029282726252423222120191817161514131211109876543210
0x00USART_SRReservedCTSLBDTXETCRXNEIDLEORENFFEPE
Reset value0011000000
0x04USART_DRReservedDR[8:0]
Reset value0
0x08USART_BRRReservedDIV_Fraction [3:0]
Reset value0
0x0CUSART_CR1Reserved
Reset value
0x10USART_CR2Reserved
Reset value
0x14USART_CR3Reserved
Reset value
0x18USART_GTPRReserved
Reset value

Refer to Section 2.3: Memory map for the register boundary addresses.