2023-06-09 08:54 AM - edited 2023-11-20 03:32 AM
I 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;
}
2023-06-09 09:02 AM - edited 2023-11-20 03:32 AM
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.
2023-06-09 09:04 AM
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.
2023-06-09 09:11 AM
>>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;
2023-06-09 09:17 AM
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?
2023-06-09 09:25 AM - edited 2023-11-20 03:32 AM
>>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);
}
2023-06-09 09:35 AM
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..
2023-06-09 10:11 AM
> 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.
2023-06-09 12:16 PM
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 :)