Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/28/05 18:27
Read: times


 
#101687 - Virtually the same doesn't mean correct
Responding to: ???'s previous message
When I said both sequences are virtually the same I did not mean that it was correct. It means that one is just as bad as the other.

Here's what's supposed to be happening:
You make sure TI is cleared:
TI = 0;

You start a transmission:
SBUF = x;

The UART engine starts working and transmits the byte. When it is done it sets the TI bit. You should wait for that:
while (TI==0)
{//wait for TI to become 1
}

Now you can clear this flag:
TI = 0;

And start the transmission of the second byte:
SBUF = x;

And then you wait again:
while (TI==0)
{//wait for TI to become 1
}


This is all assuming the interrupt for the UART is disabled or does NOT touch TI.

An alternative is to let the interrupt clear the TI flag and communicate that event to the main program so it can wait for it and then send the next byte.

The third option is to use another ring buffer to put all the data to be sent in and use that in the interrupt to fill SBUF asap when TI gets set.

List of 7 messages in thread
TopicAuthorDate
Serial communication 1 master 6 slaves            01/01/70 00:00      
   Double Post            01/01/70 00:00      
      not looking better answers            01/01/70 00:00      
         Virtually the same doesn't mean correct            01/01/70 00:00      
            thanks            01/01/70 00:00      
   the mouse ate an elephant            01/01/70 00:00      
      thanks anyway            01/01/70 00:00      

Back to Subject List