USART UDR0 register doubt!!

Thread Starter

baba_bhuri

Joined Jul 2, 2013
17
This query follows from my previous thread "USART interrupt problem".
How UDR0 is shared by reciever and transmitter of USART?
Also,in the ISR instead of using global variable ,I replaced the ISR body with :
{
UDR0 = UDR0
}
And ,it still worked. The code works correctly.
Could anyone explain how does this happen??
 

tshuck

Joined Oct 18, 2012
3,534
Read page 194 in the datasheet, it says that UDRn is used to address two different registers, TXB and RCB, two registers associated with transmission and reception, respectively. The decision which register is desired is determined by wether you are attempting to write to or read from UDR0...
 

Thread Starter

baba_bhuri

Joined Jul 2, 2013
17
Thank's for the reply. But the datasheet just mentions that when you read from UDR0 buffer , data is recieved and when you write into it ,then transmission takes place.
When the statement : c =UDR0; is executed (after data is received) ,immediately afterwards what does UDR0 contain ? Is the value flushed out to make space for transmission byte?
I replaced the ISR body with { UDR0 =UDR0;} The program works fine.
So ,what sense {UDR0 =UDR0} makes if I assume that UDR0 flushes after recieving byte? And if that's not so simply leaving the ISR body empty should also do the job.
 

tshuck

Joined Oct 18, 2012
3,534
UDR0 is probably not a physical register, but has two registers mapped to its location. Like I said, reading or writing will select which register will be addressed, so in the case of
Rich (BB code):
 UDR0 = UDR0;
, it would bethe same as writing:
Rich (BB code):
 TXB = RXB // this means nothing to a compiler
, not quite the same as leaving your ISR empty...
 
Top