cancel
Showing results for 
Search instead for 
Did you mean: 

Can I write to a UART Data Register if the RXNE bit is set(data has been received in the RDR but not read yet) ?

PTiwa.3
Associate
 
3 REPLIES 3
Andrew Neil
Evangelist III

Yes.

There are actually two data registers:

  1. a read-only register - reading this gives you the received byte;
  2. a write-only register - writing to this provides a byte to be transmitted.

The RXNE bit refers only to the read-only receive register.

Thanks Andrew.

Iam using STm32F103 series controller, which has one Data Register(which can be read/written) and separate internal Receive Data Buffer and Write Data Buffer.

So, let's say If the UART receives/receiving a byte and at the same moment I write to the UART Data Register(to be transmitted on TX line), will the data byte be successfully transmitted?

And will I be able to read the data byte that came/was coming on the RX line at the moment?

Physically, there are two distinct registers and they share the same address:

0693W00000QKr5NQAT.png 

0693W00000QKr5rQAD.png 

Note that this is pretty much standard across all microcontrollers (and standalone UARTs) - not specific to ST or STM32.

This is how full-duplex operation is achieved.

"If the UART receives/receiving a byte"

That goes into RDR

"I write to the UART Data Register(to be transmitted on TX line)"

That goes into TDR

"will the data byte be successfully transmitted?"

Yes.

Note that an upshot of this is that reading-back DR will not give you what you wrote to DR.