cancel
Showing results for 
Search instead for 
Did you mean: 

UART DR vs TDR/RDR registers

oldone
Associate II
Posted on April 16, 2018 at 17:30

I don't understand something, what's the point of TDR and RDR registers if during the Receive and Transmit functions they read/write into the DR register.

Moreover UART is normally full duplex but if we read/write into the same register we only can be half duplex at the most.

Could you explain me this point please, thanks.

#hal-uart #stm32f-uart
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on April 16, 2018 at 19:01

Observe that TDR and RDR are two independent registers, Write DR goes to TDR, Read DR comes from RDR

0690X00000604XYQAY.jpg

You can't read the TDR, and you can't read the Transmit and Receiver Shift Register either because those are mechanics happening behind the scene into which you have no direct visibility.

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

View solution in original post

7 REPLIES 7
Posted on April 16, 2018 at 18:16

Peripheral registers aren't memory, the read and write can go to entirely different internal functionality.

Think of it like a car painted two different colours down the center line, depending on which side you view the car from it will appear a different colour, but it doesn't change the make/model, and the guy on the driver side gets access to the steering wheel and pedals.

Many of the earlier STM32 families used USART->DR to talk to RDR and TDR depending if you were reading or writing. In newer models the registers are described separately. The mechanics of the holding registers and the shift registers inside the peripheral remain materially the same.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
henry.dick
Senior II
Posted on April 16, 2018 at 19:08

You should think of DR as the access point for the shift registers associated with TX or RX. Those shifter registers reflect the data transmitted over the TX or RX line. They are not directly accessible to user code, however.

Instead, you access them via the DR register: a read of DR reads the RX register and a write to DR writes to the TX register.

This gets more complex on some MCUs when a FIFO buffer is involved.

Posted on April 16, 2018 at 18:42

Ok but it's difficult to get a idea about it if their not memories, what could they be for exemple ?

But the fact that we use only one 'register' (DR) to write and read means that it isn't full duplex right ? If no, i really don't understand how it could be

:)

Posted on April 16, 2018 at 18:53

>>means that it isn't full duplex right ?

No

Like I said you need to stop using this 'memory' concept where it's one location and you read and write the same content.

You're talking to random logic, which is more like a meat grinder. The data is being acted on and processed, and might not come out of the same port or in the same form.

The data you put in the transmit/write side isn't going to appear in the receive/read side unless you wire the RX and TX pins together.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 16, 2018 at 18:59

Note that this is standard behaviour in many (most? all?) microcontrollers: there is a single address in the address space; writing to it sends stuff to the transmitter, and reading from it retrieves stuff from the receiver.

Posted on April 16, 2018 at 19:01

Observe that TDR and RDR are two independent registers, Write DR goes to TDR, Read DR comes from RDR

0690X00000604XYQAY.jpg

You can't read the TDR, and you can't read the Transmit and Receiver Shift Register either because those are mechanics happening behind the scene into which you have no direct visibility.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 16, 2018 at 20:26

Alright ! Thank you, that's very helpful