USART Tx flag

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The USART status reg has 2 Tx flags:

-bit 6 Txcomplete (TXCIF)

-bit 5 Datareg empty (DREIF)

 

For sending a byte, polling DREIF

until =1 then sending data works (no interrupt)

Using TXCIF instead of DREIF does not work

 

The datasheet mentions data can be written only if DREIF=1

so there must be a delay between TXCIF=1 and DREIF=1

For interrupt driven Tx I want to use TXCIF-int because DREIF can

not be cleared without writing new data.

Should I wait for DREIF in the TXCIF-int before sending and

how much is the delay?

What is the purpose of TXCIF?

 

Last Edited: Sat. Oct 28, 2017 - 12:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

GBaars wrote:

What is the purpose of TXCIF?

 

It tells you that the stop bit(s) have finished being transmitted and that it is now safe to turn off any line drivers if running with a half-duplex link. Or any transmitter for an RF link. Or similar.

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

;works:

lbl:

  lds      r17,USARTC0_status

  sbrs    r17,5                           ;wait for DREIF

  rjmp   lbl

  sts     USARTC0_DATA,r16      ;write clears DREIF

  ret

 

;does not work

lbl:

  lds      r17,USARTC0_status

  sbrs    r17,6                          ;wait for TXCIF

  rjmp   lbl

  sts     USARTC0_DATA,r16

  ldi      r17,1<<6

  sts     USARTC0_status,r17      ;clear TXCIF

  ret

 

 

 

main:

   ldi r16,0x55     ;data

   rcall lbl

   rjmp main

Last Edited: Sat. Oct 28, 2017 - 02:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But it depends what you are trying to achieve. "normal" use uses the DRE. Only worry about TXC if you need to act after the last bit has left the TXD pin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

GBaars wrote:
so there must be a delay between TXCIF=1 and DREIF=1

You seem to suggest that TXCIF happens before DREIF.

 

I believe it's the other way around - first DREIF and later TXCIF:

 

  1. User code stores byte to transmit into data register.
  2. Hardware does a parallel transfer from the data register to the shift-out register.
  3. When data register contents has been transferred DREIF happens.
  4. Hardware shifts bits out of the shift register serially.
  5. When last bit has been shifted out TXCIF happens.

 

Note that as soon as 3 has happened the user code is free to store another byte into the data register. Hardware will not transfer it to the shift-out register until 5 has happened.

 

I am not an XMega man so I might be wrong, but I doubt it. This is how most all UARTs have worked since time eternal.

 

 

      1   0   1   1   1   0   0   1
      |   |   |   |   |   |   |   |
1. Application writes byte into data register.
      |   |   |   |   |   |   |   |
      v   v   v   v   v   v   v   v
    +-------------------------------+
    | 1 | 0 | 1 | 1 | 1 | 0 | 0 | 1 |
    +-------------------------------+ 
      |   |   |   |   |   |   |   |
2. Hardware transfers byte into shift-out register.
      |   |   |   |   |   |   |   |
      v   v   v   v   v   v   v   v
    +-------------------------------+
    | 1 | 0 | 1 | 1 | 1 | 0 | 0 | 1|
    +-------------------------------+ 

3. Data register now empty so DREIF happens.

4. Hardware shifts bits out of shift-out register serially (here, 8 shifts in total):

    +-------------------------------+
    | . | 1 | 0 | 1 | 1 | 1 | 0 | 0 +--> 1
    +-------------------------------+ 

    +-------------------------------+
    | . | . | 1 | 0 | 1 | 1 | 1 | 0 +--> 0
    +-------------------------------+ 

    +-------------------------------+
    | . | . | . | 1 | 0 | 1 | 1 | 1 +--> 0
    +-------------------------------+ 

                    .
                    .
                    .
     
    +-------------------------------+
    | . | . | . | . | . | . | . | . +--> 1
    +-------------------------------+ 

5. All bits shifted out so TXCIF now happens.

 

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You do not use TXCIF to know when it is OK to write to the data register. You are meant to use DREIF.

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

http://www.atmel.com/images/doc8...

confirms DREIF is first, still code doesn't work.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

GBaars wrote:

http://www.atmel.com/images/doc8...

confirms DREIF is first, still code doesn't work.

 

But back in post #3 you said that when using DREIF the code does work.

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So what is the initial state of  DREIF and TXCIF? Because in your program you are waiting for the flags before sending any data. What is the initial state of "transmission complete" before you even sent anything?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

reset sets both

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

GBaars wrote:

reset sets both

 

I thought that doesn't make sense, so I checked the datasheet.

 

Turns out TXCIF reset value is 0, as I expected.

Last Edited: Sat. Oct 28, 2017 - 02:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

THought I read reset sets both, I feel stupid.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't.

 

All is well that ends well.

 

If I am to assess my stupidity based on the misteaks I have made then I'm an amoeba.. :-)

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

These guys make me feel stupid all the time.  But they are nice about it.  They just like to help.