21. Universal synchronous/asynchronous receiver transmitter (USART/UART)
21.1 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 programmable baud rate generator.
It supports synchronous one-way communication and Half-duplex Single-wire communication, as well as multiprocessor communications. It also supports the LIN (Local Interconnect Network), Smartcard protocol and IrDA (Infrared Data Association) SIR ENDEC specifications and Modem operations (CTS/RTS).
High speed data communication is possible by using the DMA (direct memory access) for multibuffer configuration.
21.2 USART main features
- • Full-duplex asynchronous communications
- • NRZ standard format (mark/space)
- • Configurable oversampling method by 16 or 8 to give flexibility between speed and clock tolerance
- • A common programmable transmit and receive baud rate of up to 4 Mbit/s when the clock frequency is 32 MHz and oversampling is by 8
- • Dual clock domain allowing:
- – USART functionality and wakeup from Stop mode
- – Convenient baud rate programming independent from the PCLK reprogramming
- • Auto baud rate detection
- • Programmable data word length (7, 8 or 9 bits)
- • Programmable data order with MSB-first or LSB-first shifting
- • Configurable stop bits (1 or 2 stop bits)
- • Synchronous mode and clock output for synchronous communications
- • Single-wire Half-duplex communications
- • Continuous communications using DMA
- • Received/transmitted bytes are buffered in reserved SRAM using centralized DMA
- • Separate enable bits for transmitter and receiver
- • Separate signal polarity control for transmission and reception
- • Swappable Tx/Rx pin configuration
- • Hardware flow control for modem and RS-485 transceiver
- • Communication control/error detection flags
- • Parity control:
- – Transmits parity bit
- – Checks parity of received data byte
- • Fourteen interrupt sources with flags
- • Multiprocessor communications
The USART enters Mute mode if the address does not match. - • Wakeup from Mute mode (by idle line detection or address mark detection)
21.3 USART extended features
- • LIN master synchronous break send capability and LIN slave break detection capability
- – 13-bit break generation and 10/11-bit break detection when USART is hardware configured for LIN
- • IrDA SIR encoder decoder supporting 3/16 bit duration for normal mode
- • Smartcard mode
- – Supports the T=0 and T=1 asynchronous protocols for smartcards as defined in the ISO/IEC 7816-3 standard
- – 0.5 and 1.5 stop bits for smartcard operation
- • Support for ModBus communication
- – Timeout feature
- – CR/LF character recognition
21.4 USART implementation
Table 102. STM32L010x USART/LPUART features
| USART modes/features (1) | USART2 (category 1 and 2 devices) | USART2 (category 3 and 5) | LPUART1 |
|---|---|---|---|
| Hardware flow control for modem | X | X | X |
| Continuous communication using DMA | X | X | X |
| Multiprocessor communication | X | X | X |
| Synchronous mode | - | X | - |
| Smartcard mode | - | X | - |
| Single-wire Half-duplex communication | X | X | X |
| Ir SIR ENDEC block | - | X | - |
| LIN mode | - | X | - |
| Dual clock domain and wakeup from Stop mode | - | X | X |
| Receiver timeout interrupt | - | X | - |
| Modbus communication | - | X | - |
| Auto baud rate detection | - | X | - |
| Driver Enable | X | X | X |
| USART/LPUART data length | 7 (2) , 8 and 9 bits | ||
1. X = supported.
2. In 7-bit data length mode, Smartcard mode, LIN master mode and Auto baud rate (0x7F and 0x55 frame detection) are not supported.
21.5 USART functional description
Any USART bidirectional communication requires a minimum of two pins: Receive data In (RX) and Transmit data Out (TX):
- • RX: Receive data Input.
This 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.
Serial data are transmitted and received through these pins in normal USART mode. The frames are comprised of:
- • An Idle Line prior to transmission or reception
- • A start bit
- • A data word (7, 8 or 9 bits) least significant bit first
- • 0.5, 1, 1.5, 2 stop bits indicating that the frame is complete
- • The USART interface uses a baud rate generator
- • A status register (USART_ISR)
- • Receive and transmit data registers (USART_RDR, USART_TDR)
- • A baud rate register (USART_BRR)
- • A guard-time register (USART_GTPR) in case of Smartcard mode.
Refer to Section 21.8: USART registers on page 617 for the definitions of each bit.
The following pin is required to interface in synchronous mode and Smartcard mode:
- • CK: Clock output. This pin outputs the transmitter data clock for synchronous transmission corresponding to SPI master mode (no clock pulses on start bit and stop bit, and a software option to send a clock pulse on the last data bit). In parallel, data can be received synchronously on RX. This can be used to control peripherals that have shift registers. The clock phase and polarity are software programmable. In Smartcard mode, CK output can provide the clock to the smartcard.
The following pins are required in RS232 Hardware flow control mode:
- • CTS: Clear To Send blocks the data transmission at the end of the current transfer (when high)
- • RTS: Request to send indicates that the USART is ready to receive data (when low).
The following pin is required in RS485 Hardware control mode:
- • DE: Driver Enable activates the transmission mode of the external transceiver.
Note: DE and RTS share the same pin.
Figure 180. USART block diagram
![Figure 180. USART block diagram. This is a detailed block diagram of the USART (Universal Synchronous/Asynchronous Receiver Transmitter) block. At the top, a 'PRDATA' bus is connected to a 'Write' block (CPU or DMA) which feeds into a 'Transmit shift register'. A 'Read' block (CPU or DMA) feeds into a 'Receive shift register', which is connected to a 'DR (data register)'. Below the shift registers are the 'Transmit data register (TDR)' and 'Receive data register (RDR)'. The 'IrDA SIR ENDEC block' is connected to the 'TX' and 'RX' pins and to the 'Transmit data register (TDR)'. The 'Hardware flow controller' is connected to the 'RTS/DE' and 'CTS' pins and to the 'Transmit control' and 'Receiver control' blocks. The 'USART_CR3 register' and 'USART_CR2 register' are connected to the 'IrDA SIR ENDEC block' and the 'Hardware flow controller'. The 'USART_CR1 register' is connected to the 'Transmit control', 'Wake-up unit', and 'Receiver control' blocks. The 'USART_GTPR register' contains 'GT' and 'PSC' fields, which are connected to the 'CK control' block. The 'CK control' block is connected to the 'CK' pin. The 'Transmit control' block is connected to the 'Transmit shift register', 'Transmit data register (TDR)', 'Wake-up unit', and 'USART_CR1 register'. The 'Wake-up unit' is connected to the 'Transmit control', 'Receiver control', and 'USART_CR1 register'. The 'Receiver control' block is connected to the 'Receive shift register', 'Receive data register (RDR)', 'Wake-up unit', 'USART_CR1 register', and 'USART_ISR register'. The 'USART_ISR register' is connected to the 'Receiver control' and 'USART interrupt control' blocks. The 'USART interrupt control' block is connected to the 'Transmit control', 'Wake-up unit', and 'Receiver control' blocks. The 'Transmitter clock' is connected to the '/USARTDIV or 2/USARTDIV (depending on the oversampling mode) (Note 1)' block. The 'fck (Note 2)' input is also connected to this block. The 'USART_BRR register' contains 'TE', 'BRR[15:0]', and 'RE' fields. The 'TE' field is connected to the 'Transmitter rate controller', which is connected to the '/USARTDIV or 2/USARTDIV' block. The 'BRR[15:0]' field is connected to the 'Transmitter rate controller' and the 'Receiver rate controller'. The 'RE' field is connected to the 'Receiver rate controller', which is connected to the '/USARTDIV or 2/USARTDIV' block. The 'Conventional baud rate generator' is connected to the 'Receiver rate controller'. The diagram is labeled 'MS19821V8' in the bottom right corner.](/RM0451-STM32L0x0/fa676d145fed4fc3621ea24c653c0299_img.jpg)
- 1. For details on coding USARTDIV in the USART_BRR register, refer to Section 21.5.4: USART baud rate generation .
- 2. \( f_{CK} \) can be \( f_{LSE} \) , \( f_{HSI} \) , \( f_{PCLK} \) , \( f_{SYS} \) .
21.5.1 USART character description
The word length can be selected as being either 7 or 8 or 9 bits by programming the M[1:0] bits in the USART_CR1 register (see Figure 181 ).
- • 7-bit character length: M[1:0] = 10
- • 8-bit character length: M[1:0] = 00
- • 9-bit character length: M[1:0] = 01
Note: The 7-bit mode is supported only on some USARTs. In addition, not all modes are supported in 7-bit data length mode. Refer to Section 21.4: USART implementation for additional information.
By default, the signal (TX or RX) is in low state during the start bit. It is in high state during the stop bit.
These values can be inverted, separately for each signal, through polarity configuration control.
An Idle character is interpreted as an entire frame of “1”s (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 2 stop bits.
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 181. Word length programming

The diagram illustrates the timing for three different word lengths in a USART/UART. Each section shows a 'Data frame', an 'Idle frame', and a 'Break frame' relative to a 'Clock' signal.
- 9-bit word length (M = 01), 1 Stop bit:
- Data frame: Start bit, Bit0, Bit1, Bit2, Bit3, Bit4, Bit5, Bit6, Bit7, Bit8, Possible Parity bit, Stop bit. The clock signal has 10 pulses, with the last one (LBCL) marked with '**'.
- Idle frame: A high level followed by a Start bit.
- Break frame: A low level followed by two Stop bits and a Start bit.
- 8-bit word length (M = 00), 1 Stop bit:
- Data frame: Start bit, Bit0, Bit1, Bit2, Bit3, Bit4, Bit5, Bit6, Bit7, Possible Parity bit, Stop bit. The clock signal has 9 pulses, with the last one (LBCL) marked with '**'.
- Idle frame: A high level followed by a Start bit.
- Break frame: A low level followed by two Stop bits and a Start bit.
- 7-bit word length (M = 10), 1 Stop bit:
- Data frame: Start bit, Bit0, Bit1, Bit2, Bit3, Bit4, Bit5, Bit6, Possible Parity bit, Stop bit. The clock signal has 8 pulses, with the last one (LBCL) marked with '**'.
- Idle frame: A high level followed by a Start bit.
- Break frame: A low level followed by two Stop bits and a Start bit.
** LBCL bit controls last data clock pulse
MS33194V2
21.5.2 USART transmitter
The transmitter can send data words of either 7, 8 or 9 bits depending on the M bits status. The Transmit Enable bit (TE) must be set in order to activate the transmitter function. 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 (default configuration) on the TX pin. In this mode, the USART_TDR register consists of a buffer (TDR) between the internal bus and the transmit shift register (see Figure 180 ).
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 must be set before writing the data to be transmitted to the USART_TDR. The TE bit should not be reset during transmission of data. Resetting the TE bit during the transmission will corrupt the data on the TX pin as the baud rate counters will get frozen. The current data being transmitted will be lost. An idle frame will be 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.
- • 1 stop bit: This is the default value of number of stop bits.
- • 2 stop bits: This will be supported by normal USART, Single-wire and Modem modes.
- • 1.5 stop bits: To be used in Smartcard mode.
- • 0.5 stop bit: To be used when receiving data in Smartcard mode.
An idle frame transmission will include the stop bits.
A break transmission will be 10 low bits (when M[1:0] = 00) or 11 low bits (when M[1:0] = 01) or 9 low bits (when M[1:0] = 10) followed by 2 stop bits (see Figure 182 ). It is not possible to transmit long breaks (break of length greater than 9/10/11 low bits).
Figure 182. Configurable stop bits

The diagram illustrates three data frame structures for 8-bit data transmission, showing the sequence of bits: Start bit, 8 data bits (Bit0 to Bit7), an optional parity bit, and stop bits. A CLOCK signal is shown above the frames, with a note that the LBCL bit controls the last data clock pulse.
- 8-bit data, 1 Stop bit: The frame consists of a Start bit, 8 data bits (Bit0 to Bit7), an optional parity bit, and 1 stop bit. The next data frame begins after the stop bit.
- 8-bit data, 1 1/2 Stop bits: The frame consists of a Start bit, 8 data bits (Bit0 to Bit7), an optional parity bit, and 1.5 stop bits. The next data frame begins after the stop bits.
- 8-bit data, 2 Stop bits: The frame consists of a Start bit, 8 data bits (Bit0 to Bit7), an optional parity bit, and 2 stop bits. The next data frame begins after the stop bits.
** LBCL bit controls last data clock pulse
MSv31887V1
Character transmission procedure
- 1. Program the M bits in USART_CR1 to define the word length.
- 2. Select the desired baud rate using the USART_BRR register.
- 3. Program the number of stop bits in USART_CR2.
- 4. Enable the USART by writing the UE bit in USART_CR1 register to 1.
- 5. Select DMA enable (DMAT) in USART_CR3 if multibuffer communication is to take place. Configure the DMA register as explained in multibuffer communication.
- 6. Set the TE bit in USART_CR1 to send an idle frame as first transmission.
- 7. Write the data to send in the USART_TDR register (this clears the TXE bit). Repeat this for each data to be transmitted in case of single buffer.
- 8. After writing the last data into the USART_TDR 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.
For code example, refer to A.15.1: USART transmitter configuration code example .
Single byte communication
Clearing the TXE bit is always performed by a write to the transmit data register.
The TXE bit is set by hardware and it indicates:
- • The data has been moved from the USART_TDR register to the shift register and the data transmission has started.
- • The USART_TDR register is empty.
- • The next data can be written in the USART_TDR register without overwriting the previous data.
For code example, refer to A.15.2: USART transmit byte code example .
This flag generates an interrupt if the TXEIE bit is set.
When a transmission is taking place, a write instruction to the USART_TDR register stores the data in the TDR register; next, the data is copied in the shift register at the end of the currently ongoing transmission.
When no transmission is taking place, a write instruction to the USART_TDR register places the data in the shift register, the data transmission starts, and the TXE bit is 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 in the USART_TDR 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 183: TC/TXE behavior when transmitting ).
Figure 183. TC/TXE behavior when transmitting

The diagram illustrates the timing and state of flags during the transmission of three frames (Frame 1, Frame 2, Frame 3) over a TX line. The sequence starts with an Idle preamble. The TX line shows the transmission of each frame. The TXE flag is set by hardware when the shift register is empty and cleared by software when a new character is written. The USART_DR register contains the data to be transmitted. The TC flag is set by hardware when the shift register is empty and the TXE flag is set. The diagram shows that the TC flag is not set while the TXE flag is set, and only becomes set after the TXE flag is cleared and the shift register is empty.
Key events and states shown in the diagram:
- Idle preamble: The initial state of the TX line.
- Frame 1: The first frame to be transmitted. The TXE flag is set by hardware. Software enables the USART and waits until TXE=1 to write F1 into DR. The TC flag is not set because TXE=0.
- Frame 2: The second frame to be transmitted. The TXE flag is set by hardware. Software waits until TXE=1 and writes F2 into DR. The TC flag is not set because TXE=0.
- Frame 3: The third frame to be transmitted. The TXE flag is set by hardware. Software waits until TXE=1 and writes F3 into DR. The TC flag is not set because TXE=0.
- End of transmission: After the last character (F3) is written, the TXE flag is cleared by software. The TC flag is set by hardware because TXE=1. Software waits until TC=1.
For code example, refer to A.15.3: USART transfer complete code example .
Break characters
Setting the SBKRQ bit transmits a break character. The break frame length depends on the M bits (see Figure 181 ).
If a '1' is written to the SBKRQ bit, a break character is sent on the TX line after completing the current character transmission. The SBKF bit is set by the write operation and it is reset by hardware when the break character is completed (during the stop bits after the break character). The USART inserts a logic 1 signal (STOP) for the duration of 2 bits at the end of the break frame to guarantee the recognition of the start bit of the next frame.
In the case the application needs to send the break character following all previously inserted data, including the ones not yet transmitted, the software should wait for the TXE flag assertion before setting the SBKRQ bit.
Idle characters
Setting the TE bit drives the USART to send an idle frame before the first data frame.
21.5.3 USART receiver
The USART can receive data words of either 7, 8 or 9 bits depending on the M bits 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 X 0 X 0.
Figure 184. Start bit detection when oversampling by 16 or 8

The diagram illustrates the start bit detection process. The RX state transitions from Idle to Start bit. The RX line shows a falling edge for the start bit. Ideal sample clock has 16 samples per bit, while Real sample clock has 8 samples per bit. Sampling occurs at the 3rd, 5th, 7th, 8th, 9th, and 10th clock cycles. The sampled values are 1 1 1 0 X 0 X 0 X 0 X 0 X 0. Conditions to validate the start bit include falling edge detection and at least 2 bits out of 3 at 0 for two consecutive samplings. Timing markers show 7/16 and 6/16 bit times.
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 3 sampled bits are at 0 (first sampling on the 3rd, 5th and 7th bits finds the 3 bits at 0 and second sampling on the 8th, 9th and 10th bits also finds the 3 bits at 0).
The start bit is validated (RXNE flag set, interrupt generated if RXNEIE=1) but the NF noise flag is set if,
- for both samplings, 2 out of the 3 sampled bits are at 0 (sampling on the 3rd, 5th and 7th bits and sampling on the 8th, 9th and 10th bits)
- or
- for one of the samplings (sampling on the 3rd, 5th and 7th bits or sampling on the 8th, 9th and 10th bits), 2 out of the 3 bits are found at 0.
If neither conditions a. or b. are met, the start detection aborts and the receiver returns to the idle state (no flag is set).
Character reception
During an USART reception, data shifts in least significant bit first (default configuration) through the RX pin. In this mode, the USART_RDR register consists of a buffer (RDR) between the internal bus and the receive shift register.
Character reception procedure
- 1. Program the M bits in USART_CR1 to define the word length.
- 2. Select the desired baud rate using the baud rate register USART_BRR
- 3. Program the number of stop bits in USART_CR2.
- 4. Enable the USART by writing the UE bit in USART_CR1 register to 1.
- 5. Select DMA enable (DMAR) in USART_CR3 if multibuffer communication is to take place. Configure the DMA register as explained in multibuffer communication.
- 6. Set the RE bit USART_CR1. This enables the receiver which begins searching for a start bit.
For code example, refer to A.15.4: USART receiver configuration code example .
When a character is received:
- • The RXNE bit is set to indicate that the content of the shift register is transferred to the RDR. In other words, data has been received and can be read (as well as its associated error flags).
- • An interrupt is generated if the RXNEIE bit is set.
- • The error flags can be set if a frame error, noise or an overrun error has been detected during reception. PE flag can also be set with RXNE.
- • In multibuffer, RXNE is set after every byte received and is cleared by the DMA read of the Receive data Register.
- • In single buffer mode, clearing the RXNE bit is performed by a software read to the USART_RDR register. The RXNE flag can also be cleared by writing 1 to the RXFRQ in the USART_RQR register. The RXNE bit must be cleared before the end of the reception of the next character to avoid an overrun error.
For code example, refer to A.15.5: USART receive byte code example .
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 for a received data 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:
- • The ORE bit is set.
- • The RDR content will not be lost. The previous data is available when a read to USART_RDR is performed.
- • The shift register will be overwritten. After that point, any data received during overrun is lost.
- • An interrupt is generated if either the RXNEIE bit is set or EIE bit is set.
- • The ORE bit is reset by setting the ORECF bit in the ICR register.
Note: The ORE bit, when set, indicates that at least 1 data has been lost. There are two possibilities:
- - if RXNE=1, then the last valid data is stored in the receive register RDR and can be read,
- - if RXNE=0, then it means that the last valid data has already been read and thus there is nothing to be read in the RDR. This case can occur when the last valid data is read in the RDR at the same time as the new (and lost) data is received.
Selecting the proper oversampling method
When the dual clock domain with the wakeup from Stop mode is supported, the clock source can be one of the following sources: PCLK (default), LSE, HSI16 or SYSCLK. Otherwise, the USART clock source is PCLK.
Choosing LSE or HSI16 as clock source may allow the USART to receive data while the MCU is in low-power mode. Depending on the received data and wakeup mode selection, the USART wakes up the MCU, when needed, in order to transfer the received data by software reading the USART_RDR register or by DMA.
For the other clock sources, the system must be active in order to allow USART communication.
The receiver implements different user-configurable oversampling techniques for data recovery by discriminating between valid incoming data and noise. This allows a trade-off between the maximum communication speed and noise/clock inaccuracy immunity.
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 185 and Figure 186 ).
Depending on the application:
- • Select oversampling by 8 (OVER8=1) to achieve higher speed (up to \( f_{CK}/8 \) ). In this case the maximum receiver tolerance to clock deviation is reduced (refer to Section 21.5.5: Tolerance of the USART receiver to clock deviation on page 590 )
- • Select oversampling by 16 (OVER8=0) to increase the tolerance of the receiver to clock deviations. In this case, the maximum speed is limited to maximum \( f_{CK}/16 \) where \( f_{CK} \) is the clock source frequency.
Programming the ONEBIT bit in the USART_CR3 register selects the method used to evaluate the logic level. There are two options:
- • The majority vote of the three samples in the center of the received bit. In this case, when the 3 samples used for the majority vote are not equal, the NF bit is set
- • A single sample in the center of the received bit
Depending on the application:
- – select the three samples' majority vote method (ONEBIT=0) when operating in a noisy environment and reject the data when a noise is detected (refer to Figure 103 ) because this indicates that a glitch occurred during the sampling.
- – select the single sample method (ONEBIT=1) when the line is noise-free to increase the receiver's tolerance to clock deviations (see Section 21.5.5: Tolerance of the USART receiver to clock deviation on page 590 ). In this case the NF bit will never be set.
When noise is detected in a frame:
- • The NF bit is set at the rising edge of the RXNE bit.
- • The invalid data is transferred from the Shift register to the USART_RDR register.
- • No interrupt is generated in case of single byte communication. However this bit rises at the same time as the RXNE bit which itself generates an interrupt. In case of multibuffer communication an interrupt will be issued if the EIE bit is set in the USART_CR3 register.
The NF bit is reset by setting NFCF bit in ICR register.
Note: Oversampling by 8 is not available in LIN, Smartcard and IrDA modes. In those modes, the OVER8 bit is forced to '0' by hardware.
Figure 185. Data sampling when oversampling by 16

The diagram illustrates the timing for data sampling with 16x oversampling. A horizontal line represents the RX line, and a series of vertical arrows represents the Sample clock. The clock frequency is 16 times the bit rate. The first bit is sampled by the first 7 clock edges (labeled 1 to 7). The second bit is sampled by the next 7 clock edges (labeled 8 to 14). The third bit is sampled by the remaining 6 clock edges (labeled 15 to 16). A bracket labeled 'sampled values' covers the 8th, 9th, and 10th samples. Horizontal double-headed arrows indicate durations: '7/16' for the first bit, '6/16' for the third bit, and '7/16' for the second bit. A longer double-headed arrow at the bottom is labeled 'One bit time'. The diagram is identified by the code MSv31152V1 in the bottom right corner.
Figure 186. Data sampling when oversampling by 8

Table 103. Noise detection from sampled data
| Sampled value | NE status | Received bit value |
|---|---|---|
| 000 | 0 | 0 |
| 001 | 1 | 0 |
| 010 | 1 | 0 |
| 011 | 1 | 1 |
| 100 | 1 | 0 |
| 101 | 1 | 1 |
| 110 | 1 | 1 |
| 111 | 0 | 1 |
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 set by hardware
- • The invalid data is transferred from the Shift register to the USART_RDR register.
- • No interrupt is generated in case of single byte communication. However this bit rises at the same time as the RXNE bit which itself generates an interrupt. In case of multibuffer communication an interrupt will be issued if the EIE bit is set in the USART_CR3 register.
The FE bit is reset by writing 1 to the FECF in the USART_ICR register.
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.
- • 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.
- • 1 stop bit: Sampling for 1 stop Bit is done on the 8th, 9th and 10th samples.
- • 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 bits. 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 bits 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 21.5.13: USART Smartcard mode on page 602 for more details.
- • 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 will be set. The second stop bit is not checked for framing error. The RXNE flag will be set at the end of the first stop bit.
21.5.4 USART 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 USART_BRR register.
Equation 1: Baud rate for standard USART (SPI mode included) (OVER8 = 0 or 1)
In case of oversampling by 16, the equation is:
In case of oversampling by 8, the equation is:
Equation 2: Baud rate in Smartcard, LIN and IrDA modes (OVER8 = 0)
In Smartcard, LIN and IrDA modes, only Oversampling by 16 is supported:
USARTDIV is an unsigned fixed point number that is coded on the USART_BRR register.
- • When OVER8 = 0, BRR = USARTDIV.
- • When OVER8 = 1
- – BRR[2:0] = USARTDIV[3:0] shifted 1 bit to the right.
- – BRR[3] must be kept cleared.
- – BRR[15:4] = USARTDIV[15:4]
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.
In case of oversampling by 16 or 8, USARTDIV must be greater than or equal to 16d.
How to derive USARTDIV from USART_BRR register values
Example 1
To obtain 9600 baud with \( f_{CK} = 8 \) MHz.
- • In case of oversampling by 16:
USARTDIV = 8 000 000/9600
BRR = USARTDIV = 833d = 0341h - • In case of oversampling by 8:
USARTDIV = 2 * 8 000 000/9600
USARTDIV = 1666,66 (1667d = 683h)
BRR[3:0] = 3h >> 1 = 1h
BRR = 0x681
Example 2
To obtain 921.6 kbaud with \( f_{CK} = 32 \) MHz.
- • In case of oversampling by 16:
USARTDIV = 32 000 000/921 600
BRR = USARTDIV = 35d = 23h - • In case of oversampling by 8:
USARTDIV = 2 * 32 000 000/921 600
USARTDIV = 70d = 46h
BRR[3:0] = USARTDIV[3:0] >> 1 = 6h >> 1 = 3h
BRR = 0x43
| Baud rate | Oversampling by 16 (OVER8 = 0) | Oversampling by 8 (OVER8 = 1) | |||||
|---|---|---|---|---|---|---|---|
| S.No | Desired | Actual | BRR | % Error = (Calculated - Desired)B.Rate / Desired B.Rate | Actual | BRR | % Error |
| 1 | 2.4 kbaud | 2.4 kbaud | 0x3415 | 0 | 2.4 kbaud | 0x6825 | 0 |
| 2 | 9.6 kbaud | 9.6 kbaud | 0xD05 | 0 | 9.6 kbaud | 0x1A05 | 0 |
| 3 | 19.2 kbaud | 19.19 kbaud | 0x683 | 0.02 | 19.2 kbaud | 0xD02 | 0 |
| 4 | 38.4 kbaud | 38.41 kbaud | 0x341 | 0.04 | 38.39 kbaud | 0x681 | 0.02 |
| 5 | 57.6 kbaud | 57.55 kbaud | 0x22C | 0.08 | 57.6 kbaud | 0x453 | 0 |
| 6 | 115.2 kbaud | 115.1 kbaud | 0x116 | 0.08 | 115.11 kbaud | 0x226 | 0.08 |
| 7 | 230.4 kbaud | 230.21 kbaud | 0x8B | 0.08 | 230.21 kbaud | 0x113 | 0.08 |
| 8 | 460.8 kbaud | 463.76 kbaud | 0x045 | 0.64 | 460.06 kbaud | 0x85 | 0.08 |
| 9 | 921.6 kbaud | 914.28 kbaud | 0x23 | 0.79 | 927.5 kbaud | 0x42 | 0.79 |
| 10 | 2 Mbaud | 2 Mbaud | 0x10 | 0 | 2 Mbaud | 0x20 | 0 |
| 12 | 4Mbaud | 4Mbaud | NA | NA | 4Mbaud | 0x10 | 0 |
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.
21.5.5 Tolerance of the USART receiver to clock deviation
The asynchronous receiver of the USART works correctly only if the total clock system deviation is less than the tolerance of the USART receiver. The causes which contribute to the total deviation are:
- • DTRA: Deviation due to the transmitter error (which also includes the deviation of the transmitter's local oscillator)
- • DQUANT: Error due to the baud rate quantization of the receiver
- • DREC: Deviation of the receiver's local oscillator
- • DTCL: Deviation due to the transmission line (generally due to the transceivers which can introduce an asymmetry between the low-to-high transition timing and the high-to-low transition timing)
where
DWU is the error due to sampling point deviation when the wakeup from Stop mode is used.
when M[1:0] = 01:
when M[1:0] = 00:
when M[1:0] = 10:
\( t_{\text{WUUSART}} \) is the time between:
- – The detection of start bit falling edge
- – The instant when clock (requested by the peripheral) is ready and reaching the peripheral and regulator is ready.
\( t_{\text{WUUSART}} \) corresponds to \( t_{\text{WUSTOP}} \) value provided in the datasheet.
The USART receiver can receive data correctly at up to the maximum tolerated deviation specified in Table 105 and Table 106 depending on the following choices:
- • 9-, 10- or 11-bit character length defined by the M bits in the USART_CR1 register
- • Oversampling by 8 or 16 defined by the OVER8 bit in the USART_CR1 register
- • Bits BRR[3:0] of USART_BRR register are equal to or different from 0000.
- • Use of 1 bit or 3 bits to sample the data, depending on the value of the ONEBIT bit in the USART_CR3 register.
Table 105. Tolerance of the USART receiver when BRR [3:0] = 0000
| M bits | OVER8 bit = 0 | OVER8 bit = 1 | ||
|---|---|---|---|---|
| ONEBIT=0 | ONEBIT=1 | ONEBIT=0 | ONEBIT=1 | |
| 00 | 3.75% | 4.375% | 2.50% | 3.75% |
| 01 | 3.41% | 3.97% | 2.27% | 3.41% |
| 10 | 4.16% | 4.86% | 2.77% | 4.16% |
Table 106. Tolerance of the USART receiver when BRR [3:0] is different from 0000
| M bits | OVER8 bit = 0 | OVER8 bit = 1 | ||
|---|---|---|---|---|
| ONEBIT=0 | ONEBIT=1 | ONEBIT=0 | ONEBIT=1 | |
| 00 | 3.33% | 3.88% | 2% | 3% |
| 01 | 3.03% | 3.53% | 1.82% | 2.73% |
| 10 | 3.7% | 4.31% | 2.22% | 3.33% |
Note: The data specified in Table 105 and Table 106 may slightly differ in the special case when the received frames contain some Idle frames of exactly 10-bit durations when M bits = 00 (11-bit durations when M bits = 01 or 9- bit durations when M bits = 10).
21.5.6 USART auto baud rate detection
The USART is able to detect and automatically set the USART_BRR register value based on the reception of one character. Automatic baud rate detection is useful under two circumstances:
- • The communication speed of the system is not known in advance
- • The system is using a relatively low accuracy clock source and this mechanism allows the correct baud rate to be obtained without measuring the clock deviation.
The clock source frequency must be compatible with the expected communication speed (when oversampling by 16, the baud rate is between \( f_{CK}/65535 \) and \( f_{CK}/16 \) . when oversampling by 8, the baud rate is between \( f_{CK}/65535 \) and \( f_{CK}/8 \) ).
Before activating the auto baud rate detection, the auto baud rate detection mode must be chosen. There are various modes based on different character patterns.
They can be chosen through the ABRMOD[1:0] field in the USART_CR2 register. In these auto baud rate modes, the baud rate is measured several times during the synchronization data reception and each measurement is compared to the previous one.
These modes are:
- • Mode 0: Any character starting with a bit at 1. In this case the USART measures the duration of the Start bit (falling edge to rising edge).
- • Mode 1: Any character starting with a 10xx bit pattern. In this case, the USART measures the duration of the Start and of the 1st data bit. The measurement is done falling edge to falling edge, ensuring better accuracy in the case of slow signal slopes.
- • Mode 2: A 0x7F character frame (it may be a 0x7F character in LSB first mode or a 0xFE in MSB first mode). In this case, the baud rate is updated first at the end of the start bit (BRs), then at the end of bit 6 (based on the measurement done from falling edge to falling edge: BR6). Bit 0 to bit 6 are sampled at BRs while further bits of the character are sampled at BR6.
- • Mode 3: A 0x55 character frame. In this case, the baud rate is updated first at the end of the start bit (BRs), then at the end of bit 0 (based on the measurement done from falling edge to falling edge: BR0), and finally at the end of bit 6 (BR6). Bit 0 is sampled at BRs, bit 1 to bit 6 are sampled at BR0, and further bits of the character are sampled at BR6.
In parallel, another check is performed for each intermediate transition of RX line. An error is generated if the transitions on RX are not sufficiently synchronized with the receiver (the receiver being based on the baud rate calculated on bit 0).
Prior to activating auto baud rate detection, the USART_BRR register must be initialized by writing a non-zero baud rate value.
The automatic baud rate detection is activated by setting the ABREN bit in the USART_CR2 register. The USART will then wait for the first character on the RX line. The auto baud rate operation completion is indicated by the setting of the ABRF flag in the USART_ISR register. If the line is noisy, the correct baud rate detection cannot be guaranteed. In this case the BRR value may be corrupted and the ABRE error flag will be set. This also happens if the communication speed is not compatible with the automatic baud rate
detection range (bit duration not between 16 and 65536 clock periods (oversampling by 16) and not between 8 and 65536 clock periods (oversampling by 8)).
The RXNE interrupt will signal the end of the operation.
At any later time, the auto baud rate detection may be relaunched by resetting the ABRF flag (by writing a 0).
Note: If the USART is disabled (UE=0) during an auto baud rate operation, the BRR value may be corrupted.
21.5.7 Multiprocessor communication using USART
In multiprocessor communication, the following bits are to be kept cleared:
- • LINEN bit in the USART_CR2 register,
- • HDSEL, IREN and SCEN bits in the USART_CR3 register.
It is possible to perform multiprocessor communication with the USART (with several USARTs connected in a network). For instance one of the USARTs can be the master, its TX output connected to the RX inputs of the other USARTs. 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 order to use the mute mode feature, the MME bit must be set in the USART_CR1 register.
In mute mode:
- • None of the reception status bits can be set.
- • All the receive interrupts are inhibited.
- • The RWU bit in USART_ISR register is set to 1. RWU can be controlled automatically by hardware or by software, through the MMRQ bit in the USART_RQR register, under certain conditions.
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 if the WAKE bit is reset,
- • Address Mark detection if the WAKE bit is set.
Idle line detection (WAKE=0)
The USART enters mute mode when the MMRQ bit is written to 1 and the RWU is automatically set.
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_ISR register. An example of mute mode behavior using Idle line detection is given in Figure 187 .
Figure 187. Mute mode using Idle line detection

The diagram illustrates the relationship between the RX (Receive) signal and the RWU (Receive Wakeup) signal during Idle line detection. The RX signal shows a sequence of data frames: Data 1, Data 2, Data 3, Data 4, followed by an IDLE state, then Data 5, and Data 6. The RWU signal is initially low. When the MMRQ bit is written to 1, the RWU signal goes high, entering 'Mute mode'. The RWU signal returns to low ('Normal mode') when an Idle frame is detected. RXNE (Receive Not Empty) flags are indicated by arrows pointing to the start of Data 5 and Data 6.
Note: If the MMRQ is set while the IDLE character has already elapsed, mute mode will not be entered (RWU is not set).
If the USART is activated while the line is IDLE, the idle state is detected after the duration of one IDLE frame (not only after the reception of one character frame).
4-bit/7-bit address mark detection (WAKE=1)
In this mode, bytes are recognized as addresses if their MSB is a '1' otherwise they are considered as data. In an address byte, the address of the targeted receiver is put in the 4 or 7 LSBs. The choice of 7 or 4-bit address detection is done using the ADDM7 bit. This 4-bit/7-bit word is compared by the receiver with its own address which is programmed in the ADD bits in the USART_CR2 register.
Note: In 7-bit and 9-bit data modes, address detection is done on 6-bit and 8-bit addresses (ADD[5:0] and ADD[7:0]) respectively.
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 or DMA request is issued when the USART enters mute mode.
The USART also enters mute mode when the MMRQ bit is written to 1. The RWU bit is also automatically set in this case.
The USART 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.
An example of mute mode behavior using address mark detection is given in Figure 188 .
Figure 188. Mute mode using address mark detection

In this example, the current address of the receiver is 1 (programmed in the USART_CR2 register)
The diagram illustrates the RX and RWU signals during mute mode using address mark detection. The RX signal shows a sequence of IDLE, Addr=0, Data 1, Data 2, IDLE, Addr=1, Data 3, Data 4, Addr=2, Data 5. The RWU signal shows transitions between Mute mode and Normal mode based on address matching. Address 0 is a non-matching address, Addr=1 is a matching address, and Addr=2 is a non-matching address. RXNE flags are shown for the matching address.
MSV31155V1
21.5.8 Modbus communication using USART
The USART offers basic support for the implementation of Modbus/RTU and Modbus/ASCII protocols. Modbus/RTU is a half duplex, block transfer protocol. The control part of the protocol (address recognition, block integrity control and command interpretation) must be implemented in software.
The USART offers basic support for the end of the block detection, without software overhead or other resources.
Modbus/RTU
In this mode, the end of one block is recognized by a “silence” (idle line) for more than 2 character times. This function is implemented through the programmable timeout function.
The timeout function and interrupt must be activated, through the RTOEN bit in the USART_CR2 register and the RTOIE in the USART_CR1 register. The value corresponding to a timeout of 2 character times (for example 22 x bit duration) must be programmed in the RTO register. When the receive line is idle for this duration, after the last stop bit is received, an interrupt is generated, informing the software that the current block reception is completed.
Modbus/ASCII
In this mode, the end of a block is recognized by a specific (CR/LF) character sequence. The USART manages this mechanism using the character match function.
By programming the LF ASCII code in the ADD[7:0] field and by activating the character match interrupt (CMIE=1), the software is informed when a LF has been received and can check the CR/LF in the DMA buffer.
21.5.9 USART 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 bits, the possible USART frame formats are as listed in Table 107 .
Table 107. Frame formats
| M bits | PCE bit | USART frame (1) |
|---|---|---|
| 00 | 0 | | SB | 8-bit data | STB | |
| 00 | 1 | | SB | 7-bit data | PB | STB | |
| 01 | 0 | | SB | 9-bit data | STB | |
| 01 | 1 | | SB | 8-bit data | PB | STB | |
| 10 | 0 | | SB | 7-bit data | STB | |
| 10 | 1 | | SB | 6-bit data | PB | STB | |
1. Legends: SB: start bit, STB: stop bit, PB: parity bit. In the data register, the PB is always taking the MSB position (9th, 8th or 7th, depending on the M bits value).
Even parity
The parity bit is calculated to obtain an even number of “1s” inside the frame of the 6, 7 or 8 LSB bits (depending on M bits values) and the parity bit.
As an example, if data=00110101, and 4 bits are set, then the parity bit will be 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 6, 7 or 8 LSB bits (depending on M bits values) and the parity bit.
As an example, if data=00110101 and 4 bits set, then the parity bit will be 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_ISR register and an interrupt is generated if PEIE is set in the USART_CR1 register. The PE flag is cleared by software writing 1 to the PECF in the USART_ICR register.
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)).
21.5.10 USART LIN (local interconnection network) mode
This section is relevant only when LIN mode is supported. Please refer to Section 21.4: USART implementation on page 575 .
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:
- • STOP[1:0] and CLKEN in the USART_CR2 register,
- • SCEN, HDSEL and IREN in the USART_CR3 register.
For code example, refer to A.15.6: USART LIN mode code example .
LIN transmission
The procedure explained in Section 21.5.2: USART transmitter has to be applied for LIN Master transmission. It must be the same as for normal USART transmission with the following differences:
- • Clear the M bits to configure 8-bit word length.
- • Set the LINEN bit to enter LIN mode. In this case, setting the SBKRQ bit sends 13 '0' bits as a break character. Then 2 bits of value '1' are sent to allow the next start detection.
LIN reception
When LIN mode is enabled, the break detection circuit is activated. 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 LBDF flag is set in USART_ISR. 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 (i.e. stop bit detected at '0', which will be the case for any break frame), the receiver stops until the break detection circuit receives either a '1', if the break word was not complete, or a delimiter character if a break has been detected.
The behavior of the break detector state machine and the break flag is shown on the Figure 189: Break detection in LIN mode (11-bit break length - LBDL bit is set) on page 598 .
Examples of break frames are given on Figure 190: Break detection in LIN mode vs. Framing error detection on page 599 .
Figure 189. Break detection in LIN mode (11-bit break length - LBDL bit is set)

Case 1: break signal not long enough => break discarded, LBDF is not set
| RX line | Break frame | ||||||||||||
| Capture strobe | |||||||||||||
| Break state machine | Idle | Bit0 | Bit1 | Bit2 | Bit3 | Bit4 | Bit5 | Bit6 | Bit7 | Bit8 | Bit9 | Bit10 | Idle |
| Read samples | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | ||
Case 2: break signal just long enough => break detected, LBDF is set
| RX line | Break frame | ||||||||||||
| Capture strobe | |||||||||||||
| Break state machine | Idle | Bit0 | Bit1 | Bit2 | Bit3 | Bit4 | Bit5 | Bit6 | Bit7 | Bit8 | Bit9 | Bit10 | Idle |
| Read samples | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||
| LBDF | Delimiter is immediate | ||||||||||||
Case 3: break signal long enough => break detected, LBDF is set
| RX line | Break frame | |||||||||||||
| Capture strobe | ||||||||||||||
| Break state machine | Idle | Bit0 | Bit1 | Bit2 | Bit3 | Bit4 | Bit5 | Bit6 | Bit7 | Bit8 | Bit9 | Bit10 | wait delimiter | Idle |
| Read samples | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||
| LBDF | ||||||||||||||
MSv31156V1
Figure 190. Break detection in LIN mode vs. Framing error detection

Case 1: break occurring after an Idle
The diagram shows the RX line transitioning from 'data 1' to 'IDLE', then to 'BREAK', then to 'data 2 (0x55)', and finally to 'data 3 (header)'. The 'BREAK' duration is marked as '1 data time'. The RXNE/FE signal goes high at the start of the 'BREAK' and stays high until the start of 'data 2 (0x55)'. The LBDF signal goes high at the start of the 'BREAK' and stays high until the start of 'data 2 (0x55)'.
Case 2: break occurring while data is being received
The diagram shows the RX line transitioning from 'data 1' to 'data2', then to 'BREAK', then to 'data 2 (0x55)', and finally to 'data 3 (header)'. The 'BREAK' duration is marked as '1 data time'. The RXNE/FE signal goes high at the start of the 'BREAK' and stays high until the start of 'data 2 (0x55)'. The LBDF signal goes high at the start of the 'BREAK' and stays high until the start of 'data 2 (0x55)'.
MSv31157V1
21.5.11 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:
- • LINEN bit in the USART_CR2 register,
- • SCEN, HDSEL and IREN bits in the USART_CR3 register.
In this mode, the USART can be used to control 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, or are not, generated during the last valid data bit (address mark). The CPOL bit in the USART_CR2 register is used to select the clock polarity, and the CPHA bit in the USART_CR2 register is used to select the phase of the external clock (see Figure 191 , Figure 192 and Figure 193 ).
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 duration).
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 data is being transmitted (the data register USART_TDR written). This means that it is not possible to receive synchronous data without transmitting data.
The LBCL, CPOL and CPHA bits have to be selected when the USART is disabled (UE=0) to ensure that the clock pulses function correctly.
For code example, refer to A.15.7: USART synchronous mode code example .
Figure 191. USART example of synchronous transmission

Figure 192. USART data clock timing diagram (M bits = 00)

Figure 193. USART data clock timing diagram (M bits = 01)

This timing diagram shows the relationship between the clock (CK) and data lines (TX and RX) for a 9-bit transmission. It illustrates four clock configurations based on CPOL (Clock Polarity) and CPHA (Clock Phase):
- Clock (CPOL=0, CPHA=0)
- Clock (CPOL=0, CPHA=1)
- Clock (CPOL=1, CPHA=0)
- Clock (CPOL=1, CPHA=1)
The sequence starts with an 'Idle or preceding transmission', followed by a 'Start' bit, then 9 data bits (0 to 8), and ends with a 'Stop' bit before returning to 'Idle or next transmission'. Bit 0 is labeled LSB and bit 8 is labeled MSB. A 'Capture strobe' line indicates sampling points. An asterisk (*) indicates that the LBCL bit controls the last data pulse. MSv34710V1
Figure 194. RX data setup/hold time

This diagram defines the timing requirements for receiving data. It shows the CK (capture strobe on CK rising edge in this example) and the 'Data on RX (from slave)'. The 'Valid DATA bit' must be stable for a duration of t
SETUP
before the clock edge and t
HOLD
after the clock edge.
\(
t_{SETUP} = t_{HOLD} = 1/16 \text{ bit time}
\)
MSv31161V2
Note: The function of CK is different in Smartcard mode. Refer to Section 21.5.13: USART Smartcard mode for more details.
21.5.12 USART Single-wire Half-duplex communication
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:
- • LINEN and CLKEN bits in the USART_CR2 register,
- • SCEN and IREN bits in the USART_CR3 register.
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 HDSEL in USART_CR3.
As soon as HDSEL is written to 1:
- • The TX and RX lines are internally connected
- • The RX pin is no longer used
- • The TX pin is always released when no data is transmitted. Thus, it acts as a standard I/O in idle or in reception. It means that the I/O must be configured so that TX is configured as alternate function open-drain with an external pull-up.
Apart from this, the communication protocol is similar to normal USART mode. Any conflicts on the line must be managed by software (by the use of a centralized arbiter, for instance). In particular, the transmission is never blocked by hardware and continues as soon as data is written in the data register while the TE bit is set.
For code example, refer to A.15.8: USART single-wire half-duplex code example .
21.5.13 USART Smartcard mode
This section is relevant only when Smartcard mode is supported. Please refer to Section 21.4: USART implementation on page 575 .
Smartcard mode is selected by setting the SCEN bit in the USART_CR3 register. In Smartcard mode, the following bits must be kept cleared:
- • LINEN bit in the USART_CR2 register,
- • HDSEL and IREN bits in the USART_CR3 register.
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 for smartcards as defined in the ISO 7816-3 standard. Both T=0 (character mode) and T=1 (block mode) are supported.
The USART should be configured as:
- • 8 bits plus parity: where word length is set to 8 bits and PCE=1 in the USART_CR1 register
- • 1.5 stop bits when transmitting and receiving data: where STOP=11 in the USART_CR2 register. It is also possible to choose 0.5 stop bit for receiving.
For code example, refer to A.15.9: USART smartcard mode code example .
In T=0 (character) mode, the parity error is indicated at the end of each character during the guard time period.
Figure 195 shows examples of what can be seen on the data line with and without parity error.
Figure 195. ISO 7816-3 asynchronous protocol

The diagram illustrates two scenarios for character transmission according to the ISO 7816-3 asynchronous protocol. Both scenarios show a sequence of bits: a start bit 'S', data bits '0' through '7', and a parity bit 'p'. In the 'Without Parity error' scenario, the transmission ends with a 'Guard time'. In the 'With Parity error' scenario, the parity bit 'p' is followed by a 'Line pulled low by receiver during stop in case of parity error', which is then followed by a 'Guard time'. 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 mode implements a single wire half duplex communication protocol.
- • Transmission of data from the transmit shift register is guaranteed to be delayed by a minimum of 1/2 baud clock. In normal operation a full transmit shift register starts shifting on the next baud clock edge. In Smartcard mode this transmission is further delayed by a guaranteed 1/2 baud clock.
- • In transmission, if the smartcard detects a parity error, it signals this condition to the USART by driving the line low (NACK). This NACK signal (pulling transmit line low for 1 baud clock) causes a framing error on the transmitter side (configured with 1.5 stop bits). The USART can handle automatic re-sending of data according to the protocol. The number of retries is programmed in the SCARCNT bit field. If the USART continues receiving the NACK after the programmed number of retries, it stops transmitting and signals the error as a framing error. The TXE bit can be set using the TXFRQ bit in the USART_RQR register.
- • Smartcard auto-retry in transmission: a delay of 2.5 baud periods is inserted between the NACK detection by the USART and the start bit of the repeated character. The TC bit is set immediately at the end of reception of the last repeated character (no guard-time). If the software wants to repeat it again, it must insure the minimum 2 baud periods required by the standard.
- • If a parity error is detected during reception of a frame programmed with a 1.5 stop bits period, the transmit line is pulled low for a baud clock period after the completion of the receive frame. This is to indicate to the smartcard that the data transmitted to the USART has not been correctly received. A parity error is NACKed by the receiver if the NACK control bit is set, otherwise a NACK is not transmitted (to be used in T=1 mode). If the received character is erroneous, the RXNE/receive DMA request is not activated. According to the protocol specification, the smartcard must resend the same character. If the received character is still erroneous after the maximum number of retries specified in the SCARCNT bit field, the USART stops transmitting the NACK and signals the error as a parity error.
- • Smartcard auto-retry in reception: the BUSY flag remains set if the USART NACKs the card but the card doesn't repeat the character.
- • In transmission, the USART inserts the Guard Time (as programmed in the Guard Time register) between two successive characters. As the Guard Time is measured after the stop bit of the previous character, the GT[7:0] register must be programmed to the desired CGT (Character Guard Time, as defined by the 7816-3 specification) minus 12 (the duration of one character).
- • The assertion of the TC flag can be delayed by programming the Guard Time register. In normal operation, TC is asserted when the transmit shift register is empty and no further transmit requests are outstanding. In Smartcard mode an empty transmit shift register triggers the Guard Time counter to count up to the programmed value in the Guard Time register. TC is forced low during this time. When the Guard Time counter reaches the programmed value TC is asserted high.
- • The TCBGT flag can be used to detect the end of data transfer without waiting for guard time completion. This flag is set just after the end of frame transmission and if no NACK has been received from the card.
- • The de-assertion of TC flag is unaffected by Smartcard mode.
- • If a framing error is detected on the transmitter end (due to a NACK from the receiver), the NACK is not detected as a start bit by the receive block of the transmitter. According to the ISO protocol, the duration of the received NACK can be 1 or 2 baud clock periods.
- • On the receiver side, if a parity error is detected and a NACK is transmitted the receiver does not detect the NACK as a start bit.
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 196 details how the NACK signal is sampled by the USART. In this example the USART is transmitting 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 196. Parity error detection using the 1.5 stop bits

The diagram illustrates the timing for parity error detection with 1.5 stop bits. It shows two rows of bit transmission. The top row shows Bit 7, Parity bit, and 1.5 Stop bit. The bottom row shows the same bits. Sampling points are indicated by arrows at the 8th, 9th, and 10th bit times. The 1.5 stop bit duration is shown as 1.5 bit time. The diagram is labeled MSv31163V1.
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.
Block mode (T=1)
In T=1 (block) mode, the parity error transmission is deactivated, by clearing the NACK bit in the USART_CR3 register.
When requesting a read from the smartcard, in block mode, the software must enable the receiver Timeout feature by setting the RTOEN bit in the USART_CR2 register and program the RTO bits field in the RTOR register to the BWT (block wait time) - 11 value. If no answer is received from the card before the expiration of this period, the RTOF flag will be set and a timeout interrupt will be generated (if RTOIE bit in the USART_CR1 register is set). If the first character is received before the expiration of the period, it is signaled by the RXNE interrupt.
Note: The RXNE interrupt must be enabled even when using the USART in DMA mode to read from the smartcard in block mode. In parallel, the DMA must be enabled only after the first received byte.
After the reception of the first character (RXNE interrupt), the RTO bit fields in the RTOR register must be programmed to the CWT (character wait time) - 11 value, in order to allow the automatic check of the maximum wait time between two consecutive characters. This time is expressed in baudtime units. If the smartcard does not send a new character in less than the CWT period after the end of the previous character, the USART signals this to the software through the RTOF flag and interrupt (when RTOIE bit is set).
Note: The RTO counter starts counting:
- - From the end of the stop bit in case STOP = 00.
- - From the end of the second stop bit in case of STOP = 10.
- - 1 bit duration after the beginning of the STOP bit in case STOP = 11.
- - From the beginning of the STOP bit in case STOP = 01.
As in the Smartcard protocol definition, the BWT/CWT values are defined from the beginning (start bit) of the last character. The RTO register must be programmed to BWT - 11 or CWT - 11, respectively, taking into account the length of the last character itself.
A block length counter is used to count all the characters received by the USART. This counter is reset when the USART is transmitting (TXE=0). The length of the block is communicated by the smartcard in the third byte of the block (prologue field). This value must be programmed to the BLEN field in the USART_RTOR register. When using DMA mode, before the start of the block, this register field must be programmed to the minimum value (0x0). With this value, an interrupt is generated after the 4th received character. The software must read the LEN field (third byte), its value must be read from the receive buffer.
In interrupt driven receive mode, the length of the block may be checked by software or by programming the BLEN value. However, before the start of the block, the maximum value of BLEN (0xFF) may be programmed. The real value will be programmed after the reception of the third character.
If the block is using the LRC longitudinal redundancy check (1 epilogue byte), the BLEN=LEN. If the block is using the CRC mechanism (2 epilogue bytes), BLEN=LEN+1 must be programmed. The total block length (including prologue, epilogue and information fields) equals BLEN+4. The end of the block is signaled to the software through the EOBF flag and interrupt (when EOBIE bit is set).
In case of an error in the block length, the end of the block is signaled by the RTO interrupt (Character wait Time overflow).
Note: The error checking code (LRC/CRC) must be computed/verified by software.
Direct and inverse convention
The Smartcard protocol defines two conventions: direct and inverse.
The direct convention is defined as: LSB first, logical bit value of 1 corresponds to a H state of the line and parity is even. In order to use this convention, the following control bits must be programmed: MSBFIRST=0, DATAINV=0 (default values).
The inverse convention is defined as: MSB first, logical bit value 1 corresponds to an L state on the signal line and parity is even. In order to use this convention, the following control bits must be programmed: MSBFIRST=1, DATAINV=1.
Note: When logical data values are inverted (0=H, 1=L), the parity bit is also inverted in the same way.
In order to recognize the card convention, the card sends the initial character, TS, as the first character of the ATR (Answer To Reset) frame. The two possible patterns for the TS are: LHHL LLL LLH and LHHL HHH LLH.
- • (H) LHHL LLL LLH sets up the inverse convention: state L encodes value 1 and moment 2 conveys the most significant bit (MSB first). when decoded by inverse convention, the conveyed byte is equal to '3F'.
- • (H) LHHL HHH LLH sets up the direct convention: state H encodes value 1 and moment 2 conveys the least significant bit (LSB first). when decoded by direct convention, the conveyed byte is equal to '3B'.
Character parity is correct when there is an even number of bits set to 1 in the nine moments 2 to 10.
As the USART does not know which convention is used by the card, it needs to be able to recognize either pattern and act accordingly. The pattern recognition is not done in hardware, but through a software sequence. Moreover, supposing that the USART is configured in direct convention (default) and the card answers with the inverse convention, TS = LHHL LLL LLH => the USART received character will be '03' and the parity will be odd.
Therefore, two methods are available for TS pattern recognition:
Method 1
The USART is programmed in standard Smartcard mode/direct convention. In this case, the TS pattern reception generates a parity error interrupt and error signal to the card.
- • The parity error interrupt informs the software that the card didn't answer correctly in direct convention. Software then reprograms the USART for inverse convention
- • In response to the error signal, the card retries the same TS character, and it will be correctly received this time, by the reprogrammed USART
Alternatively, in answer to the parity error interrupt, the software may decide to reprogram the USART and to also generate a new reset command to the card, then wait again for the TS.
Method 2
The USART is programmed in 9-bit/no-parity mode, no bit inversion. In this mode it receives any of the two TS patterns as:
(H) LHHL LLL LLH = 0x103 -> inverse convention to be chosen
(H) LHHL HHH LLH = 0x13B -> direct convention to be chosen
The software checks the received character against these two patterns and, if any of them match, then programs the USART accordingly for the next character reception.
If none of the two is recognized, a card reset may be generated in order to restart the negotiation.
21.5.14 USART IrDA SIR ENDEC block
This section is relevant only when IrDA mode is supported. Please refer to Section 21.4: USART implementation on page 575 .
IrDA mode is selected by setting the IREN bit in the USART_CR3 register. In IrDA mode, the following bits must be kept cleared:
- • LINEN, STOP and CLKEN bits in the USART_CR2 register,
- • SCEN and HDSEL bits in the USART_CR3 register.
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 197 ).
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.2 Kbps 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 the 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 is a half duplex communication protocol. If the Transmitter is busy (when the USART is sending data to the IrDA encoder), any data on the IrDA receive line is ignored by the IrDA decoder and if the Receiver is busy (when the USART is receiving decoded data from the IrDA decoder), data on the TX from the USART to IrDA is not encoded. while receiving data, transmission should be avoided as the data to be transmitted could be corrupted.
- • A 0 is transmitted as a high pulse and a 1 is transmitted as a 0. The width of the pulse is specified as 3/16th of the selected bit period in normal mode (see Figure 198 ).
- • The SIR decoder converts the IrDA compliant receive signal into a bit stream for USART.
- • The SIR receive logic interprets a high state as a logic one and low pulses as logic zeros.
- • The transmit encoder output has the opposite polarity to the decoder input. The SIR output is in low state when Idle.
- • The IrDA specification requires the acceptance of pulses greater than 1.41 \( \mu\text{s} \) . The acceptable pulse width is programmable. Glitch detection logic on the receiver end filters out pulses of width less than 2 PSC periods (PSC is the prescaler value programmed in the USART_GTPR). Pulses of width less than 1 PSC period are always rejected, but those of width greater than one and less than two periods may be accepted or rejected, those greater than 2 periods will be accepted as a pulse. The IrDA encoder/decoder doesn't work when PSC=0.
- • The receiver can communicate with a low-power transmitter.
- • In IrDA mode, the STOP bits in the USART_CR2 register must be configured to "1 stop bit".
For code example, refer to A.15.11: USART IrDA mode code example .
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 PSC period. A valid low is accepted only if its duration is greater than 2 periods of the IrDA low-power Baud clock (PSC value in the 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 197. IrDA SIR ENDEC- block diagram

graph LR
subgraph USART
TX
RX
end
subgraph SIREN
OR_GATE[OR]
MUX[Multiplexer]
SIR_TX[SIR Transmit Encoder]
SIR_RX[SIR Receive Decoder]
end
TX --> OR_GATE
TX --> SIR_TX
OR_GATE --> USART_TX
SIR_TX --> IrDA_OUT
IrDA_IN --> SIR_RX
SIR_RX --> MUX
RX --> MUX
MUX --> USART_RX
Figure 198. IrDA data modulation (3/16) -Normal Mode

The diagram illustrates the IrDA data modulation process. The TX line shows a start bit (0), followed by data bits (1, 0, 1, 0, 0, 1, 1, 0), and a stop bit (1). The IrDA_OUT line shows the modulated signal, which consists of short pulses corresponding to the '0' bits in the TX stream. The IrDA_IN line shows the received signal pulses. The RX line shows the demodulated signal, which reconstructs the original bit sequence. The bit period is indicated, and the IrDA_OUT signal is shown as a 3/16 duty cycle signal relative to the bit period. The diagram is labeled MSv31165V1.
21.5.15 USART continuous communication in DMA mode
The USART is capable of performing continuous communication using the DMA. The DMA requests for Rx buffer and Tx buffer are generated independently.
Note: Please refer to Section 21.4: USART implementation on page 575 to determine if the DMA mode is supported. If DMA is not supported, use the USART as explained in Section 21.5.2: USART transmitter or Section 21.5.3: USART receiver . To perform continuous communication, the user can clear the TXE/ RXNE flags in the USART_ISR register.
For code example, refer to A.15.10: USART DMA code example .
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 Section 10: Direct memory access controller (DMA) on page 216 ) to the USART_TDR 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. Write the USART_TDR register address in the DMA control register to configure it as the destination of the transfer. The data is moved to this address from memory after each TXE event.
- 2. Write the memory address in the DMA control register to configure it as the source of the transfer. The data is loaded into the USART_TDR register from this memory area after each TXE event.
- 3. Configure the total number of bytes to be transferred to the DMA control register.
- 4. Configure the channel priority in the DMA register
- 5. Configure DMA interrupt generation after half/ full transfer as required by the application.
- 6. Clear the TC flag in the USART_ISR register by setting the TCCF bit in the USART_ICR register.
- 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 Stop mode. Software must wait until TC=1. The TC flag remains cleared during all data transfers and it is set by hardware at the end of transmission of the last frame.
Figure 199. Transmission using DMA

The diagram illustrates the sequence of events for USART transmission using DMA across three frames (Frame 1, Frame 2, Frame 3) following an idle preamble.
- TX line: Shows the physical transmission of data for Frame 1, Frame 2, and Frame 3.
- TXE flag: Set by hardware when the USART_TDR is empty. It is cleared by a DMA read (when data is written to the register).
- DMA request: Generated when the TXE flag is set. For Frame 3, it is ignored by the DMA because the transfer is complete.
- USART_TDR: The data register. Data blocks F1, F2, and F3 are written into it by the DMA.
- TC flag: Set by hardware at the end of the transmission of the last frame (Frame 3).
- DMA writes USART_TDR: Shows the DMA writing data blocks F1, F2, and F3 into the USART_TDR register.
- DMA TCIF flag (transfer complete): Set by hardware when the DMA transfer is complete (after Frame 3). It is cleared by software.
Sequence of events:
- Software configures DMA to send 3 data blocks and enables USART.
- DMA writes F1 into USART_TDR.
- DMA writes F2 into USART_TDR.
- DMA writes F3 into USART_TDR.
- The DMA transfer is complete (TCIF=1 in DMA_ISR).
- Software waits until TC=1.
ai17192b
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_RDR register to a SRAM area configured using the DMA peripheral (refer to Section 10: Direct memory access controller (DMA) on page 216 ) whenever a data byte is received. To map a DMA channel for USART reception, use the following procedure:
- 1. Write the USART_RDR register address in the DMA control register to configure it as the source of the transfer. The data is moved from this address to the memory after each RXNE event.
- 2. Write the memory address in the DMA control register to configure it as the destination of the transfer. The data is loaded from USART_RDR to this memory area after each RXNE event.
- 3. Configure the total number of bytes to be transferred to the DMA control register.
- 4. Configure the channel priority in the DMA control register
- 5. Configure interrupt generation after half/ full transfer as required by the application.
- 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.
Figure 200. Reception using DMA

Figure 200 illustrates the reception of three frames (Frame 1, Frame 2, Frame 3) using DMA. The diagram shows the following signals and events:
- TX line: Shows the transmission of data bytes for Frame 1, Frame 2, and Frame 3.
- RXNE flag: Set by hardware when a byte is received and cleared by DMA read. It pulses high when a byte is received and low when it is read.
- DMA request: Generated when the RXNE flag is set.
- USART_RDR: The receive data register, which contains the received bytes F1, F2, and F3.
- DMA reads USART_RDR: The DMA reads the bytes from the USART_RDR register.
- DMA TCIF flag (transfer complete): Set by hardware when the last byte is received and cleared by software. It indicates the completion of the DMA transfer.
Sequence of events:
- Software configures the DMA to receive 3 data blocks and enables the USART.
- DMA reads F1 from USART_RDR.
- DMA reads F2 from USART_RDR.
- DMA reads F3 from USART_RDR.
- The DMA transfer is complete (TCIF=1 in DMA_ISR).
ai17193c
Error flagging and interrupt generation in multibuffer communication
In 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 single byte reception, there is a separate error flag interrupt enable bit (EIE bit in the USART_CR3 register), which, if set, enables an interrupt after the current byte if any of these errors occur.
21.5.16 RS232 hardware flow control and RS485 driver enable using USART
It is possible to control the serial data flow between 2 devices by using the CTS input and the RTS output. The Figure 201 shows how to connect 2 devices in this mode:
Figure 201. Hardware flow control between 2 USARTs

Figure 201 illustrates the hardware flow control connection between two USARTs (USART 1 and USART 2). The connections are as follows:
- USART 1 TX circuit is connected to USART 2 RX circuit (TX line).
- USART 1 RX circuit is connected to USART 2 TX circuit (RX line).
- USART 1 RTS (Request to Send) output is connected to USART 2 CTS (Clear to Send) input.
- USART 2 RTS (Request to Send) output is connected to USART 1 CTS (Clear to Send) input.
MSv31169V2
RS232 RTS and CTS flow control can be enabled independently by writing the RTSE and CTSE bits respectively to 1 (in the USART_CR3 register).
RS232 RTS flow control
If the RTS flow control is enabled (RTSE=1), then RTS is deasserted (tied low) as long as the USART receiver is ready to receive a new data. When the receive register is full, RTS is asserted, indicating that the transmission is expected to stop at the end of the current frame. Figure 202 shows an example of communication with RTS flow control enabled.
Figure 202. RS232 RTS flow control

The diagram illustrates the relationship between the receive (RX) signal and the Request to Send (RTS) flow control signal. The RX signal shows two data frames: 'Data 1' and 'Data 2', each preceded by a 'Start bit' and followed by a 'Stop bit' and an 'Idle' period. The RTS signal is initially low. It transitions to high at the end of the first frame (after the stop bit) and remains high until the start of the second frame. At the start of the second frame, the RTS signal transitions back to low. Labels indicate 'RXNE' (Receive Not Empty) flags at the start of each frame. A label 'Data 1 read' is placed between the two frames, with the text 'Data 2 can now be transmitted' below it. The diagram is labeled 'MSV68794V1' in the bottom right corner.
RS232 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 deasserted (tied low), then the next data is transmitted (assuming that data is to be transmitted, in other words, if TXE=0), else the transmission does not occur. When CTS is asserted 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. Figure 203 shows an example of communication with CTS flow control enabled.
Figure 203. RS232 CTS flow control

The diagram shows three horizontal timelines: CTS, TDR, and TX. - The CTS line starts high, then drops to low when Data 2 is being transmitted. It returns to high after Data 2 is finished. When Data 3 is ready to be transmitted, it drops to low again and returns to high after Data 3 is finished. - The TDR line shows Data 2 being written, then the register becoming empty. Data 3 is then written into the register. - The TX line shows the transmission of Data 1, followed by a stop bit, start bit, Data 2, stop bit, idle, start bit, and Data 3. - Vertical dashed lines mark key events: 'Writing data 3 in TDR' occurs just before the second drop of the CTS line; 'Transmission of Data 3 is delayed until CTS = 0' occurs when the CTS line drops for the second time.
Note: For correct behavior, CTS must be deasserted at least 3 USART clock source periods before the end of the current character. In addition it should be noted that the CTSCF flag may not be set for pulses shorter than 2 x PCLK periods.
For code example, refer to A.15.12: USART hardware flow control code example .
RS485 Driver Enable
The driver enable feature is enabled by setting bit DEM in the USART_CR3 control register. This allows the user to activate the external transceiver control, through the DE (Driver Enable) signal. The assertion time is the time between the activation of the DE signal and the beginning of the START bit. It is programmed using the DEAT [4:0] bit fields in the USART_CR1 control register. The de-assertion time is the time between the end of the last stop bit, in a transmitted message, and the de-activation of the DE signal. It is programmed using the DEDT [4:0] bit fields in the USART_CR1 control register. The polarity of the DE signal can be configured using the DEP bit in the USART_CR3 control register.
In USART, the DEAT and DEDT are expressed in sample time units (1/8 or 1/16 bit duration, depending on the oversampling rate).
21.5.17 Wakeup from Stop mode using USART
The USART is able to wake up the MCU from Stopmode when the UESM bit is set and the USART clock is set to HSI or LSE (refer to Section Reset and clock control (RCC)).
- • USART source clock is HSI
If during Stop mode the HSI clock is switched OFF, when a falling edge on the USART receive line is detected, the USART interface requests the HSI clock to be switched ON. The HSI clock is then used for the frame reception.
- – If the wakeup event is verified, the MCU wakes up from low-power mode and data reception goes on normally.
- – If the wakeup event is not verified, the HSI clock is switched OFF again, the MCU is not waken up and stays in low-power mode and the clock request is released.
Note: If the USART kernel clock is kept ON during Stop mode, there is no constraint on the maximum baud rate that allows waking up from Stop mode. It is the same as in Run mode.
- • USART source clock is LSE
Same principle as described in case of USART source clock is HSI with the difference that the LSE is ON in Stop mode, but the LSE clock is not propagated to USART if the USART is not requesting it. The LSE clock is not OFF but there is a clock gating to avoid useless consumption.
When the USART clock source is configured to be \( f_{LSE} \) or \( f_{HSI} \) , it is possible to keep enabled this clock during STOP mode by setting the UCESM bit in USART_CR3 control register.
The MCU wakeup from Stop mode can be done using the standard RXNE interrupt. In this case, the RXNEIE bit must be set before entering Stop mode.
Alternatively, a specific interrupt may be selected through the WUS bit fields.
In order to be able to wake up the MCU from Stop mode, the UESM bit in the USART_CR1 control register must be set prior to entering Stop mode.
When the wakeup event is detected, the WUF flag is set by hardware and a wakeup interrupt is generated if the WUFIE bit is set.
Note: Before entering Stop mode, the user must ensure that the USART is not performing a transfer. BUSY flag cannot ensure that Stop mode is never entered during a running reception.
The WUF flag is set when a wakeup event is detected, independently of whether the MCU is in Stop or in an active mode.
When entering Stop mode just after having initialized and enabled the receiver, the REACK bit must be checked to ensure the USART is actually enabled.
When DMA is used for reception, it must be disabled before entering Stop mode and re-enabled upon exit from Stop mode.
The wakeup from Stop mode feature is not available for all modes. For example it doesn't work in SPI mode because the SPI operates in master mode only.
Using Mute mode with Stop mode
If the USART is put into Mute mode before entering Stop mode:
- • Wakeup from Mute mode on idle detection must not be used, because idle detection cannot work in Stop mode.
- • If the wakeup from Mute mode on address match is used, then the source of wake-up from Stop mode must also be the address match. If the RXNE flag is set when entering the Stop mode, the interface will remain in mute mode upon address match and wake up from Stop.
- • If the USART is configured to wake up the MCU from Stop mode on START bit detection, the WUF flag is set, but the RXNE flag is not set.
Determining the maximum USART baud rate allowing to wakeup correctly from Stop mode when the USART clock source is the HSI clock
The maximum baud rate allowing to wakeup correctly from Stop mode depends on:
- • the parameter \( t_{WUUSART} \) provided in the device datasheet
- • the USART receiver tolerance provided in the Section 21.5.5: Tolerance of the USART receiver to clock deviation .
Let us take this example: OVER8 = 0, M bits = 10, ONEBIT = 1, BRR [3:0] = 0000.
In these conditions, according to Table 105: Tolerance of the USART receiver when BRR [3:0] = 0000 , the USART receiver tolerance is 4.86 %.
\( DTRA + DQUANT + DREC + DTCL + DWU < \text{USART receiver's tolerance} \)
\( DWU \max = t_{WUUSART} / (9 \times Tbit \text{ Min}) \)
\( Tbit \text{ Min} = t_{WUUSART} / (9 \times DWU \max) \)
If we consider an ideal case where the parameters DTRA, DQUANT, DREC and DTCL are at 0%, the DWU max is 4.86 %. In reality, we need to consider at least the HSI inaccuracy.
Let us consider HSI inaccuracy = 1 %, \( t_{WUUSART} = 8.1 \mu s \) (in case of Stop mode with main regulator in Run mode, Range 1 ):
\( DWU \max = 4.86 \% - 1 \% = 3.86 \% \)
\( Tbit \text{ min} = 8.1 \mu s / (9 \times 3.86 \%) = 23.31 \mu s \) .
In these conditions, the maximum baud rate allowing to wakeup correctly from Stop mode is \( 1/23.31 \mu s = 42 \text{ kbaud} \) .
21.6 USART in low-power modes
Table 108. Effect of low-power modes on the USART
| Mode | Description |
|---|---|
| Sleep | No effect. USART interrupt causes the device to exit Sleep mode. |
| Low-power run | No effect. |
| Low-power sleep | No effect. USART interrupt causes the device to exit Low-power sleep mode. |
| Stop | The USART is able to wake up the MCU from Stop mode when the UESM bit is set and the USART clock is set to HSI16 or LSE. The MCU wakeup from Stop mode can be done using the standard RXNE interrupt. |
| Standby | The USART is powered down and must be reinitialized when the device has exited from Standby mode. |
21.7 USART interrupts
Table 109. USART interrupt requests
| Interrupt event | Event flag | Enable Control bit |
|---|---|---|
| Transmit data register empty | TXE | TXEIE |
| CTS interrupt | CTSIF | CTSIE |
| Transmission Complete | TC | TCIE |
| Receive data register not empty (data ready to be read) | RXNE | RXNEIE |
| Overrun error detected | ORE |
Table 109. USART interrupt requests (continued)
| Interrupt event | Event flag | Enable Control bit |
|---|---|---|
| Idle line detected | IDLE | IDLEIE |
| Parity error | PE | PEIE |
| LIN break | LBDF | LBDIE |
| Noise Flag, Overrun error and Framing Error in multibuffer communication. | NF or ORE or FE | EIE |
| Character match | CMF | CMIE |
| Receiver timeout | RTOF | RTOIE |
| End of Block | EOBF | EOBIE |
| Wakeup from Stop mode | WUF (1) | WUFIE |
| Transmission complete before guard time | TCBGT | TCBGTIE |
1. The WUF interrupt is active only in Stop mode.
The USART interrupt events are connected to the same interrupt vector (see Figure 204 ).
- • During transmission: Transmission Complete, Transmission complete before guard time, Clear to Send, Transmit data Register empty or Framing error (in Smartcard mode) interrupt.
- • During reception: Idle Line detection, Overrun error, Receive data register not empty, Parity error, LIN break detection, Noise Flag, Framing Error, Character match, etc.
These events generate an interrupt if the corresponding Enable Control Bit is set.
Figure 204. USART interrupt mapping diagram

MSv19820V1
21.8 USART registers
Refer to Section 1.2 on page 33 for a list of abbreviations used in register descriptions.
The peripheral registers have to be accessed by words (32 bits).
21.8.1 USART control register 1 (USART_CR1)
Address offset: 0x00
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | M1 | EOBIE | RTOIE | DEAT[4:0] | DEDT[4:0] | ||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | |||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| OVER8 | CMIE | MME | M0 | WAKE | PCE | PS | PEIE | TXEIE | TCIE | RXNEIE | IDLEIE | TE | RE | UESM | UE |
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:29 Reserved, must be kept at reset value.
Bit 28 M1 : Word length
This bit, with bit 12 (M0), determines the word length. It is set or cleared by software.
M[1:0] = 00: 1 Start bit, 8 data bits, n stop bits
M[1:0] = 01: 1 Start bit, 9 data bits, n stop bits
M[1:0] = 10: 1 Start bit, 7 data bits, n stop bits
This bit can only be written when the USART is disabled (UE=0).
Note: Not all modes are supported In 7-bit data length mode. Refer to Section 21.4: USART implementation for details.
Bit 27 EOBIE : End of Block interrupt enable
This bit is set and cleared by software.
0: Interrupt is inhibited
1: A USART interrupt is generated when the EOBF flag is set in the USART_ISR register.
Note: If the USART does not support Smartcard mode, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 26 RTOIE : Receiver timeout interrupt enable
This bit is set and cleared by software.
0: Interrupt is inhibited
1: An USART interrupt is generated when the RTOF bit is set in the USART_ISR register.
Note: If the USART does not support the Receiver timeout feature, this bit is reserved and must be kept at reset value. Section 21.4: USART implementation on page 575 .
Bits 25:21 DEAT[4:0] : Driver Enable assertion time
This 5-bit value defines the time between the activation of the DE (Driver Enable) signal and the beginning of the start bit. It is expressed in sample time units (1/8 or 1/16 bit duration, depending on the oversampling rate).
This bit field can only be written when the USART is disabled (UE=0).
Note: If the Driver Enable feature is not supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bits 20:16 DEDT[4:0] : Driver Enable de-assertion timeThis 5-bit value defines the time between the end of the last stop bit, in a transmitted message, and the de-activation of the DE (Driver Enable) signal. It is expressed in sample time units (1/8 or 1/16 bit duration, depending on the oversampling rate).
If the USART_TDR register is written during the DEDT time, the new data is transmitted only when the DEDT and DEAT times have both elapsed.
This bit field can only be written when the USART is disabled (UE=0).
Note: If the Driver Enable feature is not supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 15 OVER8 : Oversampling mode0: Oversampling by 16
1: Oversampling by 8
This bit can only be written when the USART is disabled (UE=0).
Note: In LIN, IrDA and modes, this bit must be kept at reset value.
Bit 14 CMIE : Character match interrupt enableThis bit is set and cleared by software.
0: Interrupt is inhibited
1: A USART interrupt is generated when the CMF bit is set in the USART_ISR register.
Bit 13 MME : Mute mode enableThis bit activates the mute mode function of the USART. When set, the USART can switch between the active and mute modes, as defined by the WAKE bit. It is set and cleared by software.
0: Receiver in active mode permanently
1: Receiver can switch between mute mode and active mode.
Bit 12 MO : Word lengthThis bit, with bit 28 (M1), determines the word length. It is set or cleared by software. See Bit 28 (M1) description.
This bit can only be written when the USART is disabled (UE=0).
Bit 11 WAKE : Receiver wakeup methodThis bit determines the USART wakeup method from Mute mode. It is set or cleared by software.
0: Idle line
1: Address mark
This bit field can only be written when the USART is disabled (UE=0).
Bit 10 PCE : Parity control enableThis 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
This bit field can only be written when the USART is disabled (UE=0).
Bit 9 PS : Parity selectionThis 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 will be selected after the current byte.
0: Even parity
1: Odd parity
This bit field can only be written when the USART is disabled (UE=0).
Bit 8 PEIE : PE interrupt enableThis bit is set and cleared by software.
0: Interrupt is inhibited
1: A USART interrupt is generated whenever PE=1 in the USART_ISR register
Bit 7 TXEIE : interrupt enableThis bit is set and cleared by software.
0: Interrupt is inhibited
1: A USART interrupt is generated whenever TXE=1 in the USART_ISR register
Bit 6 TCIE : Transmission complete interrupt enableThis bit is set and cleared by software.
0: Interrupt is inhibited
1: A USART interrupt is generated whenever TC=1 in the USART_ISR register
Bit 5 RXNEIE : RXNE interrupt enableThis bit is set and cleared by software.
0: Interrupt is inhibited
1: A USART interrupt is generated whenever ORE=1 or RXNE=1 in the USART_ISR register
Bit 4 IDLEIE : IDLE interrupt enableThis bit is set and cleared by software.
0: Interrupt is inhibited
1: A USART interrupt is generated whenever IDLE=1 in the USART_ISR register
Bit 3 TE : Transmitter enableThis 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. In order to generate an idle character, the TE must not be immediately written to 1. In order to ensure the required duration, the software can poll the TEACK bit in the USART_ISR register.
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 UESM: USART enable in Stop mode
When this bit is cleared, the USART is not able to wake up the MCU from Stop mode.
When this bit is set, the USART is able to wake up the MCU from Stop mode, provided that the USART clock selection is HSI16 or LSE in the RCC.
This bit is set and cleared by software.
0: USART not able to wake up the MCU from Stop mode.
1: USART able to wake up the MCU from Stop mode. When this function is active, the clock source for the USART must be HSI16 or LSE (see Section Reset and clock control (RCC)).
Note: It is recommended to set the UESM bit just before entering Stop mode and clear it on exit from Stop mode.
If the USART does not support the wakeup from Stop feature, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 0 UE: USART enable
When this bit is cleared, the USART prescalers and outputs are stopped immediately, and current operations are discarded. The configuration of the USART is kept, but all the status flags, in the USART_ISR are set to their default values. This bit is set and cleared by software.
0: USART prescaler and outputs disabled, low-power mode
1: USART enabled
Note: In order to go into low-power mode without generating errors on the line, the TE bit must be reset before and the software must wait for the TC bit in the USART_ISR to be set before resetting the UE bit.
The DMA requests are also reset when UE = 0 so the DMA channel must be disabled before resetting the UE bit.
21.8.2 USART control register 2 (USART_CR2)
Address offset: 0x04
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ADD[7:4] | ADD[3:0] | RTOEN | ABRMOD[1:0] | ABREN | MSBFI RST | DATAINV | TXINV | RXINV | |||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| SWAP | LINEN | STOP[1:0] | CLKEN | CPOL | CPHA | LBCL | Res. | LBDIE | LBDL | ADD7 | Res. | Res. | Res. | Res. | |
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | |||||
This bit-field gives the address of the USART node or a character code to be recognized.
This is used in multiprocessor communication during Mute mode or Stop mode, for wakeup with 7-bit address mark detection. The MSB of the character sent by the transmitter should be equal to 1. It may also be used for character detection during normal reception, Mute mode inactive (for example, end of block detection in ModBus protocol). In this case, the whole received character (8-bit) is compared to the ADD[7:0] value and CMF flag is set on match.
This bit field can only be written when reception is disabled (RE = 0) or the USART is disabled (UE=0)
Bits 27:24 ADD[3:0] : Address of the USART nodeThis bit-field gives the address of the USART node or a character code to be recognized.
This is used in multiprocessor communication during Mute mode or Stop mode, for wakeup with address mark detection.
This bit field can only be written when reception is disabled (RE = 0) or the USART is disabled (UE=0)
Bit 23 RTOEN : Receiver timeout enableThis bit is set and cleared by software.
0: Receiver timeout feature disabled.
1: Receiver timeout feature enabled.
When this feature is enabled, the RTOF flag in the USART_ISR register is set if the RX line is idle (no reception) for the duration programmed in the RTOR (receiver timeout register).
Note: If the USART does not support the Receiver timeout feature, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bits 22:21 ABRMOD[1:0] : Auto baud rate modeThese bits are set and cleared by software.
00: Measurement of the start bit is used to detect the baud rate.
01: Falling edge to falling edge measurement. (the received frame must start with a single bit = 1 ->
Frame = Start10xxxxx)
10: 0x7F frame detection.
11: 0x55 frame detection
This bit field can only be written when ABREN = 0 or the USART is disabled (UE=0).
Note: If DATAINV=1 and/or MSBFIRST=1 the patterns must be the same on the line, for example 0xAA for MSBFIRST)
If the USART does not support the auto baud rate feature, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 20 ABREN : Auto baud rate enableThis bit is set and cleared by software.
0: Auto baud rate detection is disabled.
1: Auto baud rate detection is enabled.
Note: If the USART does not support the auto baud rate feature, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 19 MSBFIRST : Most significant bit firstThis bit is set and cleared by software.
0: data is transmitted/received with data bit 0 first, following the start bit.
1: data is transmitted/received with the MSB (bit 7/8/9) first, following the start bit.
This bit field can only be written when the USART is disabled (UE=0).
Bit 18 DATAINV : Binary data inversionThis bit is set and cleared by software.
0: Logical data from the data register are send/received in positive/direct logic. (1=H, 0=L)
1: Logical data from the data register are send/received in negative/inverse logic. (1=L, 0=H). The parity bit is also inverted.
This bit field can only be written when the USART is disabled (UE=0).
Bit 17 TXINV : TX pin active level inversionThis bit is set and cleared by software.
0: TX pin signal works using the standard logic levels ( \( V_{DD} \) =1/idle, Gnd=0/mark)
1: TX pin signal values are inverted. ( \( V_{DD} \) =0/mark, Gnd=1/idle).
This allows the use of an external inverter on the TX line.
This bit field can only be written when the USART is disabled (UE=0).
Bit 16 RXINV : RX pin active level inversionThis bit is set and cleared by software.
0: RX pin signal works using the standard logic levels ( \( V_{DD} \) =1/idle, Gnd=0/mark)
1: RX pin signal values are inverted. ( \( V_{DD} \) =0/mark, Gnd=1/idle).
This allows the use of an external inverter on the RX line.
This bit field can only be written when the USART is disabled (UE=0).
Bit 15 SWAP : Swap TX/RX pinsThis bit is set and cleared by software.
0: TX/RX pins are used as defined in standard pinout
1: The TX and RX pins functions are swapped. This allows to work in the case of a cross-wired connection to another USART.
This bit field can only be written when the USART is disabled (UE=0).
Bit 14 LINEN : LIN mode enableThis bit is set and cleared by software.
0: LIN mode disabled
1: LIN mode enabled
The LIN mode enables the capability to send LIN synchronous breaks (13 low bits) using the SBKRQ bit in the USART_RQR register, and to detect LIN Sync breaks.
This bit field can only be written when the USART is disabled (UE=0).
Note: If the USART does not support LIN mode, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bits 13:12 STOP[1:0] : STOP bitsThese bits are used for programming the stop bits.
00: 1 stop bit
01: 0.5 stop bit
10: 2 stop bits
11: 1.5 stop bits
This bit field can only be written when the USART is disabled (UE=0).
Bit 11 CLKEN: Clock enableThis bit allows the user to enable the CK pin.
0: CK pin disabled
1: CK pin enabled
This bit can only be written when the USART is disabled (UE=0).
Note: If neither synchronous mode nor Smartcard mode is supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
In order to provide correctly the CK clock to the Smartcard when CK is always available When CLKEN = 1, regardless of the UE bit value, the steps below must be respected:
- - UE = 0
- - SCEN = 1
- - GTPR configuration (If PSC needs to be configured, it is recommended to configure PSC and GT in a single access to USART_ GTPR register).
- - CLKEN= 1
- - UE = 1
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
This bit can only be written when the USART is disabled (UE=0).
Note: If synchronous mode is not supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 9 CPHA: Clock phaseThis bit is used 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 Figure 192 and Figure 193 )
0: The first clock transition is the first data capture edge
1: The second clock transition is the first data capture edge
This bit can only be written when the USART is disabled (UE=0).
Note: If synchronous mode is not supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 8 LBCL: Last bit clock pulseThis bit is used 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
Caution: The last bit is the 7th or 8th or 9th data bit transmitted depending on the 7 or 8 or 9 bit format selected by the M bits in the USART_CR1 register.
This bit can only be written when the USART is disabled (UE=0).
Note: If synchronous mode is not supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 7 Reserved, must be kept at reset value.
Bit 6 LBDIE: LIN break detection interrupt enableBreak interrupt mask (break detection using break delimiter).
0: Interrupt is inhibited
1: An interrupt is generated whenever LBDF=1 in the USART_ISR register
Note: If LIN mode is not supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
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
This bit can only be written when the USART is disabled (UE=0).
Note: If LIN mode is not supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575.
Bit 4 ADD7 : 7-bit Address Detection/4-bit Address Detection
This bit is for selection between 4-bit address detection or 7-bit address detection.
0: 4-bit address detection
1: 7-bit address detection (in 8-bit data mode)
This bit can only be written when the USART is disabled (UE=0)
Note: In 7-bit and 9-bit data modes, the address detection is done on 6-bit and 8-bit address (ADD[5:0] and ADD[7:0]) respectively.
Bits 3:0 Reserved, must be kept at reset value.
Note: The 3 bits (CPOL, CPHA, LBCL) should not be written while the transmitter is enabled.
21.8.3 USART control register 3 (USART_CR3)
Address offset: 0x08
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | TCBGTI E | UCESM | WUFIE | WUS1 | WUS0 | SCARC NT2 | SCARC NT1 | SCARC NT0 | Res. |
| rw | rw | rw | rw | rw | rw | rw | rw | ||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| DEP | DEM | DDRE | OVRDI S | ONEBI T | CTSIE | CTSE | RTSE | DMAT | DMAR | SCEN | NACK | HDSEL | IRLP | IREN | EIE |
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:25 Reserved, must be kept at reset value.
Bit 24 TCBGTI : Transmission complete before guard time interrupt enable
This bit is set and cleared by software.
0: Interrupt is inhibited
1: An USART interrupt is generated whenever TCBGT=1 in the USART_ISR register.
Note: If Smartcard mode is not supported, this bit is reserved and must be kept at reset value (see Section 21.4: USART implementation).
Bit 23 UCESM : USART Clock Enable in Stop mode.
This bit is set and cleared by software.
0: USART Clock is disabled in STOP mode.
1: USART Clock is enabled in STOP mode.
Bit 22 WUFIE : Wakeup from Stop mode interrupt enable
This bit is set and cleared by software.
0: Interrupt is inhibited
1: An USART interrupt is generated whenever WUF=1 in the USART_ISR register
Note: WUFIE must be set before entering in Stop mode.
The WUF interrupt is active only in Stop mode.
If the USART does not support the wakeup from Stop feature, this bit is reserved and must be kept at reset value.
Bits 21:20 WUS[1:0] : Wakeup from Stop mode interrupt flag selection
This bit-field specify the event which activates the WUF (wakeup from Stop mode flag).
00: WUF active on address match (as defined by ADD[7:0] and ADDM7)
01: Reserved.
10: WuF active on Start bit detection
11: WUF active on RXNE.
This bit field can only be written when the USART is disabled (UE=0).
Note: If the USART does not support the wakeup from Stop feature, this bit is reserved and must be kept at reset value.
Bits 19:17 SCARCNT[2:0] : Smartcard auto-retry count
This bit-field specifies the number of retries in transmit and receive, in Smartcard mode.
In transmission mode, it specifies the number of automatic retransmission retries, before generating a transmission error (FE bit set).
In reception mode, it specifies the number of erroneous reception trials, before generating a reception error (RXNE and PE bits set).
This bit field must be programmed only when the USART is disabled (UE=0).
When the USART is enabled (UE=1), this bit field may only be written to 0x0, in order to stop retransmission.
0x0: retransmission disabled - No automatic retransmission in transmit mode.
0x1 to 0x7: number of automatic retransmission attempts (before signaling error)
Note: If Smartcard mode is not supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 16 Reserved, must be kept at reset value.
Bit 15 DEP : Driver enable polarity selection
0: DE signal is active high.
1: DE signal is active low.
This bit can only be written when the USART is disabled (UE=0).
Note: If the Driver Enable feature is not supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 14 DEM : Driver enable mode
This bit allows the user to activate the external transceiver control, through the DE signal.
0: DE function is disabled.
1: DE function is enabled. The DE signal is output on the RTS pin.
This bit can only be written when the USART is disabled (UE=0).
Note: If the Driver Enable feature is not supported, this bit is reserved and must be kept at reset value. Section 21.4: USART implementation on page 575 .
Bit 13 DDRE : DMA Disable on Reception Error0: DMA is not disabled in case of reception error. The corresponding error flag is set but RXNE is kept 0 preventing from overrun. As a consequence, the DMA request is not asserted, so the erroneous data is not transferred (no DMA request), but next correct received data will be transferred (used for Smartcard mode).
1: DMA is disabled following a reception error. The corresponding error flag is set, as well as RXNE. The DMA request is masked until the error flag is cleared. This means that the software must first disable the DMA request (DMAR = 0) or clear RXNE before clearing the error flag.
This bit can only be written when the USART is disabled (UE=0).
Note: The reception errors are: parity error, framing error or noise error.
Bit 12 OVRDIS : Overrun DisableThis bit is used to disable the receive overrun detection.
0: Overrun Error Flag, ORE, is set when received data is not read before receiving new data.
1: Overrun functionality is disabled. If new data is received while the RXNE flag is still set the ORE flag is not set and the new received data overwrites the previous content of the USART_RDR register.
This bit can only be written when the USART is disabled (UE=0).
Note: This control bit allows checking the communication flow without reading the data.
Bit 11 ONEBIT : One sample bit method enableThis 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
This bit can only be written when the USART is disabled (UE=0).
Note: ONEBIT feature applies only to data bits, It does not apply to Start bit.
Bit 10 CTSIE : CTS interrupt enable0: Interrupt is inhibited
1: An interrupt is generated whenever CTSIF=1 in the USART_ISR register
Note: If the hardware flow control feature is not supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 9 CTSE : CTS enable0: CTS hardware flow control disabled
1: CTS mode enabled, data is only transmitted when the CTS input is deasserted (tied to 0). If the CTS input is asserted while data is being transmitted, then the transmission is completed before stopping. If data is written into the data register while CTS is asserted, the transmission is postponed until CTS is deasserted.
This bit can only be written when the USART is disabled (UE=0).
Note: If the hardware flow control feature is not supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 8 RTSE : RTS enable0: RTS hardware flow control disabled
1: RTS output 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 deasserted (pulled to 0) when data can be received.
This bit can only be written when the USART is disabled (UE=0).
Note: If the hardware flow control feature is not supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 7 DMAT : DMA enable transmitterThis 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 receiverThis 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 enableThis bit is used for enabling Smartcard mode.
0: Smartcard Mode disabled
1: Smartcard Mode enabled
This bit field can only be written when the USART is disabled (UE=0).
Note: If the USART does not support Smartcard mode, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 4 NACK : Smartcard NACK enable0: NACK transmission in case of parity error is disabled
1: NACK transmission during parity error is enabled
This bit field can only be written when the USART is disabled (UE=0).
Note: If the USART does not support Smartcard mode, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 3 HDSEL : Half-duplex selectionSelection of Single-wire Half-duplex mode
0: Half duplex mode is not selected
1: Half duplex mode is selected
This bit can only be written when the USART is disabled (UE=0).
Bit 2 IRLP : IrDA low-powerThis bit is used for selecting between normal and low-power IrDA modes
0: Normal mode
1: Low-power mode
This bit can only be written when the USART is disabled (UE=0).
Note: If IrDA mode is not supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 1 IREN : IrDA mode enableThis bit is set and cleared by software.
0: IrDA disabled
1: IrDA enabled
This bit can only be written when the USART is disabled (UE=0).
Note: If IrDA mode is not supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 0 EIE : Error interrupt enableError 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_ISR register).
0: Interrupt is inhibited
1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the USART_ISR register.
21.8.4 USART baud rate register (USART_BRR)
This register can only be written when the USART is disabled (UE=0). It may be automatically updated by hardware in auto baud rate detection mode.
Address offset: 0x0C
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| BRR[15:0] | |||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:16 Reserved, must be kept at reset value.
Bits 15:4 BRR[15:4]
BRR[15:4] = USARTDIV[15:4]
Bits 3:0 BRR[3:0]
When OVER8 = 0, BRR[3:0] = USARTDIV[3:0].
When OVER8 = 1:
BRR[2:0] = USARTDIV[3:0] shifted 1 bit to the right.
BRR[3] must be kept cleared.
21.8.5 USART guard time and prescaler register (USART_GTPR)
Address offset: 0x10
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| GT[7:0] | PSC[7:0] | ||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:16 Reserved, must be kept at reset value.
Bits 15:8 GT[7:0] : Guard time value
This bit-field is used to program the Guard time value in terms of number of baud clock periods.
This is used in Smartcard mode. The Transmission Complete flag is set after this guard time value.
This bit field can only be written when the USART is disabled (UE=0).
Note: If Smartcard mode is not supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575.
Bits 7:0 PSC[7:0] : Prescaler value
In IrDA Low-power and normal IrDA mode:
PSC[7:0] = IrDA Normal and Low-Power Baud Rate
Used for programming the prescaler for dividing the USART source 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 Smartcard mode:
PSC[4:0]: Prescaler value
Used for programming the prescaler for dividing the USART source 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
...
This bit field can only be written when the USART is disabled (UE=0).
Note: Bits [7:5] must be kept at reset value if Smartcard mode is used.
This bit field is reserved and must be kept at reset value when the Smartcard and IrDA modes are not supported. Please refer to Section 21.4: USART implementation on page 575.
21.8.6 USART receiver timeout register (USART_RTOR)
Address offset: 0x14
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| BLEN[7:0] | RTO[23:16] | ||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| RTO[15:0] | |||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
This bit-field gives the Block length in Smartcard T=1 Reception. Its value equals the number of information characters + the length of the Epilogue Field (1-LEC/2-CRC) - 1.
Examples:
BLEN = 0 -> 0 information characters + LEC
BLEN = 1 -> 0 information characters + CRC
BLEN = 255 -> 254 information characters + CRC (total 256 characters)
In Smartcard mode, the Block length counter is reset when TXE=0.
This bit-field can be used also in other modes. In this case, the Block length counter is reset when RE=0 (receiver disabled) and/or when the EOBCF bit is written to 1.
Note: This value can be programmed after the start of the block reception (using the data from the LEN character in the Prologue Field). It must be programmed only once per received block.
Bits 23:0 RTO[23:0] : Receiver timeout valueThis bit-field gives the Receiver timeout value in terms of number of bit duration.
In standard mode, the RTOF flag is set if, after the last received character, no new start bit is detected for more than the RTO value.
In Smartcard mode, this value is used to implement the CWT and BWT. See Smartcard section for more details.
In this case, the timeout measurement is done starting from the Start Bit of the last received character.
Note: This value must only be programmed once per received character.
Note: RTOR can be written on the fly. If the new value is lower than or equal to the counter, the RTOF flag is set.
This register is reserved and forced by hardware to “0x00000000” when the Receiver timeout feature is not supported. Please refer to Section 21.4: USART implementation on page 575 .
21.8.7 USART request register (USART_RQR)
Address offset: 0x18
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | TXFRQ | RXFRQ | MMRQ | SBKRQ | ABRRQ |
| w | w | w | w | w |
Bits 31:5 Reserved, must be kept at reset value.
Bit 4 TXFRQ : Transmit data flush request
Writing 1 to this bit sets the TXE flag.
This allows to discard the transmit data. This bit must be used only in Smartcard mode, when data has not been sent due to errors (NACK) and the FE flag is active in the USART_ISR register.
If the USART does not support Smartcard mode, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 3 RXFRQ : Receive data flush request
Writing 1 to this bit clears the RXNE flag.
This allows to discard the received data without reading it, and avoid an overrun condition.
Bit 2 MMRQ : Mute mode request
Writing 1 to this bit puts the USART in mute mode and sets the RWU flag.
Bit 1 SBKRQ : Send break request
Writing 1 to this bit sets the SBKF flag and request to send a BREAK on the line, as soon as the transmit machine is available.
Note: In the case the application needs to send the break character following all previously inserted data, including the ones not yet transmitted, the software should wait for the TXE flag assertion before setting the SBKRQ bit.
Bit 0 ABRRQ : Auto baud rate request
Writing 1 to this bit resets the ABRF and ABRE flags in the USART_ISR and request an automatic baud rate measurement on the next received data frame.
Note: If the USART does not support the auto baud rate feature, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
21.8.8 USART interrupt and status register (USART_ISR)
Address offset: 0x1C
Reset value: 0x0200 00C0
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | TCBGT | Res. | Res. | REACK | TEACK | WUF | RWU | SBKF | CMF | BUSY |
| r | r | r | r | r | r | r | r | ||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| ABRF | ABRE | Res. | EOBF | RTOF | CTS | CTSIF | LBDF | TXE | TC | RXNE | IDLE | ORE | NF | FE | PE |
| r | r | r | r | r | r | r | r | r | r | r | r | r | r | r |
Bits 31:26 Reserved, must be kept at reset value.
Bit 25 TCBGT : Transmission complete before guard time completion.
This bit is used in Smartcard mode. It is set by hardware if the transmission of a frame containing data has completed successfully (no NACK received from the card) and before the guard time has elapsed (contrary to the TC flag which is set when the guard time has elapsed).
An interrupt is generated if TCBGTIE=1 in USART_CR3 register. It is cleared by software, by writing 1 to TCBGTIF in USART_ICR or by writing to the USART_TDR register.
0: Transmission not complete or transmission completed with error (i.e. NACK received from the card)
1: Transmission complete (before Guard time has elapsed and no NACK received from the smartcard).
Note: If the USART does not support the Smartcard mode, this bit is reserved and must be kept at reset value. If the USART supports the Smartcard mode and the Smartcard mode is enabled, the TCBGT reset value is 1.
Bits 24:23 Reserved, must be kept at reset value.
Bit 22 REACK : Receive enable acknowledge flag
This bit is set/reset by hardware, when the Receive Enable value is taken into account by the USART.
When the wakeup from Stop mode is supported, the REACK flag can be used to verify that the USART is ready for reception before entering Stop mode.
Bit 21 TEACK : Transmit enable acknowledge flag
This bit is set/reset by hardware, when the Transmit Enable value is taken into account by the USART.
It can be used when an idle frame request is generated by writing TE=0, followed by TE=1 in the USART_CR1 register, in order to respect the TE=0 minimum period.
Bit 20 WUF : Wakeup from Stop mode flag
This bit is set by hardware, when a wakeup event is detected. The event is defined by the WUS bit field. It is cleared by software, writing a 1 to the WUCF in the USART_ICR register.
An interrupt is generated if WUFIE=1 in the USART_CR3 register.
Note: When UESM is cleared, WUF flag is also cleared.
The WUF interrupt is active only in Stop mode.
If the USART does not support the wakeup from Stop feature, this bit is reserved and kept at reset value.
Bit 19 RWU : Receiver wakeup from Mute mode
This bit indicates if the USART is in mute mode. It is cleared/set by hardware when a wakeup/mute sequence is recognized. The mute mode control sequence (address or IDLE) is selected by the WAKE bit in the USART_CR1 register.
When wakeup on IDLE mode is selected, this bit can only be set by software, writing 1 to the MMRQ bit in the USART_RQR register.
0: Receiver in active mode
1: Receiver in mute mode
Bit 18 SBKF : Send break flag
This bit indicates that a send break character was requested. It is set by software, by writing 1 to the SBKRQ bit in the USART_RQR register. It is automatically reset by hardware during the stop bit of break transmission.
0: No break character is transmitted
1: Break character will be transmitted
Bit 17 CMF : Character match flagThis bit is set by hardware, when the character defined by ADD[7:0] is received. It is cleared by software, writing 1 to the CMCF in the USART_ICR register.
An interrupt is generated if CMIE=1 in the USART_CR1 register.
0: No Character match detected
1: Character Match detected
Bit 16 BUSY : Busy flagThis bit is set and reset by hardware. It is active when a communication is ongoing on the RX line (successful start bit detected). It is reset at the end of the reception (successful or not).
0: USART is idle (no reception)
1: Reception on going
Bit 15 ABRF : Auto baud rate flagThis bit is set by hardware when the automatic baud rate has been set (RXNE will also be set, generating an interrupt if RXNEIE = 1) or when the auto baud rate operation was completed without success (ABRE=1) (ABRE, RXNE and FE are also set in this case)
It is cleared by software, in order to request a new auto baud rate detection, by writing 1 to the ABRREQ in the USART_RQR register.
Note: If the USART does not support the auto baud rate feature, this bit is reserved and kept at reset value.
Bit 14 ABRE : Auto baud rate errorThis bit is set by hardware if the baud rate measurement failed (baud rate out of range or character comparison failed)
It is cleared by software, by writing 1 to the ABRREQ bit in the USART_RQR register.
Note: If the USART does not support the auto baud rate feature, this bit is reserved and kept at reset value.
Bit 13 Reserved, must be kept at reset value.
Bit 12 EOBF : End of block flagThis bit is set by hardware when a complete block has been received (for example T=1 Smartcard mode). The detection is done when the number of received bytes (from the start of the block, including the prologue) is equal or greater than BLEN + 4.
An interrupt is generated if EOBIE = 1 in the USART_CR1 register.
It is cleared by software, writing 1 to EOBCF in the USART_ICR register.
0: End of Block not reached
1: End of Block (number of characters) reached
Note: If Smartcard mode is not supported, this bit is reserved and kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 11 RTOF: Receiver timeoutThis bit is set by hardware when the timeout value, programmed in the RTOR register has lapsed, without any communication. It is cleared by software, writing 1 to the RTOCF bit in the USART_ICR register.
An interrupt is generated if RTOIE=1 in the USART_CR1 register.
In Smartcard mode, the timeout corresponds to the CWT or BWT timings.
0: Timeout value not reached
1: Timeout value reached without any data reception
Note: If a time equal to the value programmed in RTOR register separates 2 characters, RTOF is not set. If this time exceeds this value + 2 sample times (2/16 or 2/8, depending on the oversampling method), RTOF flag is set.
The counter counts even if RE = 0 but RTOF is set only when RE = 1. If the timeout has already elapsed when RE is set, then RTOF will be set.
If the USART does not support the Receiver timeout feature, this bit is reserved and kept at reset value.
Bit 10 CTS: CTS flagThis bit is set/reset by hardware. It is an inverted copy of the status of the CTS input pin.
0: CTS line set
1: CTS line reset
Note: If the hardware flow control feature is not supported, this bit is reserved and kept at reset value.
Bit 9 CTSIF: CTS interrupt flagThis bit is set by hardware when the CTS input toggles, if the CTSE bit is set. It is cleared by software, by writing 1 to the CTSCF bit in the USART_ICR register.
An interrupt is generated if CTSIE=1 in the USART_CR3 register.
0: No change occurred on the CTS status line
1: A change occurred on the CTS status line
Note: If the hardware flow control feature is not supported, this bit is reserved and kept at reset value.
Bit 8 LBDIF: LIN break detection flagThis bit is set by hardware when the LIN break is detected. It is cleared by software, by writing 1 to the LBDCF in the USART_ICR.
An interrupt is generated if LBDIE = 1 in the USART_CR2 register.
0: LIN Break not detected
1: LIN break detected
Note: If the USART does not support LIN mode, this bit is reserved and kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 7 TXE: Transmit data register emptyThis bit is set by hardware when the content of the USART_TDR register has been transferred into the shift register. It is cleared by a write to the USART_TDR register.
The TXE flag can also be cleared by writing 1 to the TXFRQ in the USART_RQR register, in order to discard the data (only in Smartcard T=0 mode, in case of transmission failure).
An interrupt is generated if the TXEIE bit =1 in the USART_CR1 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 completeThis 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 software, writing 1 to the TCCF in the USART_ICR register or by a write to the USART_TDR register.
An interrupt is generated if TCIE=1 in the USART_CR1 register.
0: Transmission is not complete
1: Transmission is complete
Note: If TE bit is reset and no transmission is on going, the TC bit will be set immediately.
Bit 5 RXNE: Read data register not emptyThis bit is set by hardware when the content of the RDR shift register has been transferred to the USART_RDR register. It is cleared by a read to the USART_RDR register. The RXNE flag can also be cleared by writing 1 to the RXFRQ in the USART_RQR register.
An interrupt is generated if RXNEIE=1 in the USART_CR1 register.
0: data is not received
1: Received data is ready to be read.
Bit 4 IDLE: Idle line detectedThis bit is set by hardware when an Idle Line is detected. An interrupt is generated if IDLEIE=1 in the USART_CR1 register. It is cleared by software, writing 1 to the IDLECF in the USART_ICR register.
0: No Idle line is detected
1: Idle line is detected
Note: The IDLE bit will not be set again until the RXNE bit has been set (i.e. a new idle line occurs).
If mute mode is enabled (MME=1), IDLE is set if the USART is not mute (RWU=0), whatever the mute mode selected by the WAKE bit. If RWU=1, IDLE is not set.
Bit 3 ORE: Overrun errorThis bit is set by hardware when the data currently being received in the shift register is ready to be transferred into the RDR register while RXNE=1. It is cleared by a software, writing 1 to the ORECF, in the USART_ICR register.
An interrupt is generated if RXNEIE=1 or EIE = 1 in the USART_CR1 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 if the ORE flag is set during multibuffer communication if the EIE bit is set.
This bit is permanently forced to 0 (no overrun detection) when the OVRDIS bit is set in the USART_CR3 register.
Bit 2 NF : START bit Noise detection flagThis bit is set by hardware when noise is detected on a received frame. It is cleared by software, writing 1 to the NFCF bit in the USART_ICR register.
0: No noise is detected
1: Noise is detected
Note: This bit does not generate an interrupt as it appears at the same time as the RXNE bit which itself generates an interrupt. An interrupt is generated when the NF flag is set during multibuffer 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 21.5.5: Tolerance of the USART receiver to clock deviation on page 590).
Bit 1 FE : Framing errorThis bit is set by hardware when a de-synchronization, excessive noise or a break character is detected. It is cleared by software, writing 1 to the FECF bit in the USART_ICR register.
In Smartcard mode, in transmission, this bit is set when the maximum number of transmit attempts is reached without success (the card NACKs the data frame).
An interrupt is generated if EIE = 1 in the USART_CR1 register.
0: No Framing error is detected
1: Framing error or break character is detected
Bit 0 PE : Parity errorThis bit is set by hardware when a parity error occurs in receiver mode. It is cleared by software, writing 1 to the PECF in the USART_ICR register.
An interrupt is generated if PEIE = 1 in the USART_CR1 register.
0: No parity error
1: Parity error
21.8.9 USART interrupt flag clear register (USART_ICR)
Address offset: 0x20
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | WUCF | Res. | Res. | CMCF | Res. |
| rc_w1 | rc_w1 | ||||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | EOBCF | RTOCF | Res. | CTSCF | LBDCF | TCBGTCF | TCCF | Res. | IDLECF | ORECF | NCF | FECF | PECF |
| rc_w1 | rc_w1 | rc_w1 | rc_w1 | rc_w1 | rc_w1 | rc_w1 | rc_w1 | rc_w1 | rc_w1 | rc_w1 |
Bits 31:21 Reserved, must be kept at reset value.
Bit 20 WUCF : Wakeup from Stop mode clear flagWriting 1 to this bit clears the WUF flag in the USART_ISR register.
Note: If the USART does not support the wakeup from Stop feature, this bit is reserved and must be kept at reset value.
Bits 19:18 Reserved, must be kept at reset value.
Bit 17 CMCF : Character match clear flagWriting 1 to this bit clears the CMF flag in the USART_ISR register.
Bits 16:13 Reserved, must be kept at reset value.
Bit 12 EOBCF : End of block clear flag
Writing 1 to this bit clears the EOBF flag in the USART_ISR register.
Note: If the USART does not support Smartcard mode, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 11 RTOCF : Receiver timeout clear flag
Writing 1 to this bit clears the RTOF flag in the USART_ISR register.
Note: If the USART does not support the Receiver timeout feature, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 10 Reserved, must be kept at reset value.
Bit 9 CTSCF : CTS clear flag
Writing 1 to this bit clears the CTSIF flag in the USART_ISR register.
Note: If the hardware flow control feature is not supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 8 LBDCF : LIN break detection clear flag
Writing 1 to this bit clears the LBDF flag in the USART_ISR register.
Note: If LIN mode is not supported, this bit is reserved and must be kept at reset value. Please refer to Section 21.4: USART implementation on page 575 .
Bit 7 TCBGTCF : Transmission completed before guard time clear flag
Writing 1 to this bit clears the TCBGT flag in the USART_ISR register.
Note: If the USART does not support SmartCard mode, this bit is reserved and forced by hardware to 0. Please refer to Section 21.4: USART implementation on page 575 .
Bit 6 TCCF : Transmission complete clear flag
Writing 1 to this bit clears the TC flag in the USART_ISR register.
Bit 5 Reserved, must be kept at reset value.
Bit 4 IDLECF : Idle line detected clear flag
Writing 1 to this bit clears the IDLE flag in the USART_ISR register.
Bit 3 ORECF : Overrun error clear flag
Writing 1 to this bit clears the ORE flag in the USART_ISR register.
Bit 2 NCF : Noise detected clear flag
Writing 1 to this bit clears the NF flag in the USART_ISR register.
Bit 1 FECF : Framing error clear flag
Writing 1 to this bit clears the FE flag in the USART_ISR register.
Bit 0 PECF : Parity error clear flag
Writing 1 to this bit clears the PE flag in the USART_ISR register.
21.8.10 USART receive data register (USART_RDR)
Address offset: 0x24
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | RDR[8:0] | ||||||||
| r | r | r | r | r | r | r | r | r | |||||||
Bits 31:9 Reserved, must be kept at reset value.
Bits 8:0 RDR[8:0] : Receive data value
Contains the received data character.
The RDR register provides the parallel interface between the input shift register and the internal bus (see Figure 180 ).
When receiving with the parity enabled, the value read in the MSB bit is the received parity bit.
21.8.11 USART transmit data register (USART_TDR)
Address offset: 0x28
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | TDR[8:0] | ||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | |||||||
Bits 31:9 Reserved, must be kept at reset value.
Bits 8:0 TDR[8:0] : Transmit data value
Contains the data character to be transmitted.
The TDR register provides the parallel interface between the internal bus and the output shift register (see Figure 180 ).
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.
Note: This register must be written only when TXE=1.
21.8.12 USART register map
The table below gives the USART register map and reset values.
Table 110. USART register map and reset values
| Offset | Register | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0x00 | USART_CR1 | Res. | Res. | Res. | M1 | EOBIE | RTOIE | DEAT4 | DEAT3 | DEAT2 | DEAT1 | DEAT0 | DEDT4 | DEDT3 | DEDT2 | DEDT1 | DEDT0 | OVER8 | CMIE | MME | M0 | WAKE | PCE | PS | PEIE | TXEIE | TCIE | RXNEIE | IDLEIE | TE | RE | UESM | UE | |
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||
| 0x04 | USART_CR2 | ADD[7:4] | ADD[3:0] | RTOEN | ABRMOD1 | ABRMOD0 | ABREN | MSBFIRST | DATAINV | TXINV | RXINV | SWAP | LINEN | STOP [1:0] | CLKEN | CPOL | CPHA | LBCL | Res. | LBIDLE | LBDL | ADD7 | Res. | Res. | Res. | Res. | ||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||
| 0x08 | USART_CR3 | Res. | Res. | Res. | Res. | Res. | Res. | Res. | TCBGTIE | UCESM | WUFIE | WUS | SCARCNT2[0] | Res. | DEP | DEM | DDRE | OVRDIS | ONEBIT | CTSIE | CTSE | RTSE | DMAT | DMAR | SCEN | NACK | HDSEL | IRLP | IREN | EIE | ||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||
| 0x0C | USART_BRR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | BRR[15:0] | ||||||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||
| 0x10 | USART_GTPR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | GT[7:0] | PSC[7:0] | |||||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||
| 0x14 | USART_RTOR | BLEN[7:0] | RTO[23:0] | |||||||||||||||||||||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||
| 0x18 | USART_RQR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | TXFRQ | RXFRQ | MMRQ | SBKREQ | ABRRQ | |
| Reset value | 0 | 0 | 0 | 0 | 0 | |||||||||||||||||||||||||||||
| 0x1C | USART_ISR | Res. | Res. | Res. | Res. | Res. | Res. | TCBGT | Res. | REACK | TEACK | WUF | RWU | SBKF | CMF | BUSY | ABRF | ABRE | Res. | EOBF | RTOF | CTS | CTSIF | LBDF | TXE | TC | RXNE | IDLE | ORE | NF | FE | PE | ||
| Reset value | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||
| 0x20 | USART_ICR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | WUCF | Res. | CMCF | Res. | Res. | Res. | Res. | Res. | EOBCF | RTOCF | Res. | CTSCF | LBDCF | TCBGT CF | TCCF | Res. | IDLECF | ORECF | NCF | FECF | PECF | ||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||||||||
| 0x24 | USART_RDR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | RDR[8:0] | |||||||||
| Reset value | X | X | X | X | X | X | X | X | X | |||||||||||||||||||||||||
Table 110. USART register map and reset values (continued)
| Offset | Register | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0x28 | USART_TDR | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | Res | TDR[8:0] | ||||||||
| Reset value | X | X | X | X | X | X | X | X | |||||||||||||||||||||||||
Refer to Section 2.2 on page 39 for the register boundary addresses.