cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F446 UART: Reading received 9th bit (i.e. DR[8]) in USART_DR when PCE=0 and M=1 in USART_CR1

JArmi.1
Associate II

I want to interface to an existing RS-485 bus where the 9th bit (normally reserved for parity) is set to 1 for the first two packets of each frame (as an addressing mechanism) and then cleared to 0 for the subsequent "data" bytes.

If I set PCE=0 in register USART_CR1, that will disable parity generation (on TX) and checking (on RX), which is what I want.

Since I need 9 bits of data (in addition to the start and stop bits), I also need to set M=1 in register USART_CR1

So far so good.

When transmitting, I should be able to load all 9 bits into DR[8:0] in USART_DR and they will be transmitted as-written by my code.

But on reception, I am not sure (from the Reference Manual https://www.st.com/resource/en/reference_manual/dm00135183-stm32f446xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf)

It says the following (in section 25.6.2 on PDF page 838)

"When transmitting with the parity enabled (PCE bit set to 1 in the USART_CR1 register), the

value written in the MSB (bit 7 or bit 8 depending on the data length) has no effect because

it is replaced by the parity.

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

bit."

So I am assuming, though it isn't stated, that DR[8] will contain the actual 9th bit that was received.

Is this correct? I just want to be 100% sure before I place an order for a Nucleo board!!!

3 REPLIES 3

The USART_DR is a 16-bit wide register in most STM32 implementations, of which 9-bits are used.

You get to see all the bits from the wire, so with parity enabled you're expected to mask the bits you're interested in. Most people self-mask the data register by casting into an 8-bit char.

The 9-bit No Parity mode is typical of the 8051 multi-processor protocol, data comes in/out LSB first.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

> So I am assuming, though it isn't stated, that DR[8] will contain the actual 9th bit that was received.

Yes, this way UART can send and receive 9 bits. It works here.

-- pa

JArmi.1
Associate II

Thanks to all who answered. I'm sorry to bother you, and just wished the reference manual gave clearer guidance so I didn't have to ask others or do my own experiments to try and figure it out.