cancel
Showing results for 
Search instead for 
Did you mean: 

How to see the sent value in UART Data Register?

MMust.5
Senior II


_legacyfs_online_stmicro_images_0693W00000dDVEzQAO.pngI send the number 5 via UART to the Data Register, at a speed of 600 bit / s.

I watch the Data Register in Keil.

The Data Register value is always zero.

Is it because the data transfer is very fast?

In my case 1/600==0.00166 seconds per bit.

I set Breakpoint to UART4->DR=data; but the Data Register still has zero.

uint8_t data = 5;

while (1)

{

 UART4->DR=data;

}

8 REPLIES 8
TDK
Guru

You can't. DR is a register to interface with the hardware, not bytes in memory. Data written to DR is (typically) immediately put into the outgoing shift register, no way to read it. Data read from DR is what data has been received.


_legacyfs_online_stmicro_images_0693W00000dDVGgQAO.png

If you feel a post has answered your question, please click "Accept as Solution".
Pavel A.
Evangelist III

The value written into the DR register is write-only, it cannot be read back.

When the DR is read, it returns the last received value.

Now you can answer your own question.

>>When the DR is read, it returns the last received value.

The last value received by the DR register was the number 5.

uint8_t data = 5;

UART4->DR=data;

The value from the DR register is transferred to the RDR register.

I cannot read the value from the RDR register.

It turns out I send the data through DR as in a black hole and I can't observe them?

>>When the DR is read, it returns the last received value.

uint8_t data = 5;

while (1)

{

 UART4->DR=data;

 printf("%d\n", UART4->DR);

}


_legacyfs_online_stmicro_images_0693W00000dDVJzQAO.png

It is not a MEMORY, you're looking into a PERIPHERAL with all sorts of combinatorial logic that may, or may not reflect back to you the content written.

Like TIM->CNT, if the timers clocking, you'll see a different value every time you read it.

Further reading DR or RDR impacts logic/flags in SR

For peripherals with FIFO's looking into them in the Peripheral View will break the usage elsewhere as that data is now gone..

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

> It turns out I send the data through DR as in a black hole and I can't observe them?

You can observe them on the line. But you can't read them via the debugger. Like it or not, that's how it is.

If you feel a post has answered your question, please click "Accept as Solution".

No, I meant the value received by the UART, from outside (and only when it is available). 5 is the value you wrote to the DR, it goes to the black hole.

But you have found the solution.

Every time before writing to the DR, save the value into a variable. There you will find it 🙂