USART UDR0 register doubt!!

Discussion in 'Embedded Systems and Microcontrollers' started by baba_bhuri, Jul 5, 2013.

  1. baba_bhuri

    Thread Starter New Member

    Jul 2, 2013
    17
    1
    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??
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    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...
     
  3. baba_bhuri

    Thread Starter New Member

    Jul 2, 2013
    17
    1
    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.
     
  4. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    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
    Code ( (Unknown Language)):
    1.  UDR0 = UDR0;
    , it would bethe same as writing:
    Code ( (Unknown Language)):
    1.  TXB = RXB // this means nothing to a compiler
    , not quite the same as leaving your ISR empty...
     
    baba_bhuri likes this.
  5. baba_bhuri

    Thread Starter New Member

    Jul 2, 2013
    17
    1
    Thank's again . I seem to understand it now.
     
  6. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    The diagram on page 177 may help you understand the structure a little better...
     
Loading...