09.12.2012 Views

RM0090: Reference manual - STMicroelectronics

RM0090: Reference manual - STMicroelectronics

RM0090: Reference manual - STMicroelectronics

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Universal synchronous asynchronous receiver transmitter (USART) <strong>RM0090</strong><br />

26.3.7 Parity control<br />

Parity control (generation of parity bit in transmission and parity checking in reception) can<br />

be enabled by setting the PCE bit in the USART_CR1 register. Depending on the frame<br />

length defined by the M bit, the possible USART frame formats are as listed in Table 118.<br />

Table 118. Frame formats<br />

Even parity<br />

The parity bit is calculated to obtain an even number of “1s” inside the frame made of the 7<br />

or 8 LSB bits (depending on whether M is equal to 0 or 1) and the parity bit.<br />

E.g.: data=00110101; 4 bits set => parity bit will be 0 if even parity is selected (PS bit in<br />

USART_CR1 = 0).<br />

Odd parity<br />

M bit PCE bit USART frame (1)<br />

0 0 | SB | 8 bit data | STB |<br />

0 1 | SB | 7-bit data | PB | STB |<br />

1 0 | SB | 9-bit data | STB |<br />

1 1 | SB | 8-bit data PB | STB |<br />

1. Legends: SB: start bit, STB: stop bit, PB: parity bit.<br />

The parity bit is calculated to obtain an odd number of “1s” inside the frame made of the 7 or<br />

8 LSB bits (depending on whether M is equal to 0 or 1) and the parity bit.<br />

E.g.: data=00110101; 4 bits set => parity bit will be 1 if odd parity is selected (PS bit in<br />

USART_CR1 = 1).<br />

Parity checking in reception<br />

If the parity check fails, the PE flag is set in the USART_SR register and an interrupt is<br />

generated if PEIE is set in the USART_CR1 register. The PE flag is cleared by a software<br />

sequence (a read from the status register followed by a read or write access to the<br />

USART_DR data register).<br />

Note: In case of wakeup by an address mark: the MSB bit of the data is taken into account to<br />

identify an address but not the parity bit. And the receiver does not check the parity of the<br />

address data (PE is not set in case of a parity error).<br />

Parity generation in transmission<br />

If the PCE bit is set in USART_CR1, then the MSB bit of the data written in the data register<br />

is transmitted but is changed by the parity bit (even number of “1s” if even parity is selected<br />

(PS=0) or an odd number of “1s” if odd parity is selected (PS=1)).<br />

Note: The software routine that manages the transmission can activate the software sequence<br />

which clears the PE flag (a read from the status register followed by a read or write access<br />

to the data register). When operating in half-duplex mode, depending on the software, this<br />

can cause the PE flag to be unexpectedly cleared.<br />

763/1416 Doc ID 018909 Rev 3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!