Hi, gentlemen, I am a 8051 starter. One simple question: I am trying to use a interrupt driven serial I/O. Will a writing operation to SBUF set TI to high, or in the other way, to set TI will trigger to transmit the contents of SBUF? Thanks in advance!!
In general, on many processors, (example, infineon c166) the hardware sets the ti bit approx when the data bit (or the first stop bit) leaves the shift register. That implies you must 'prime' the output buffer, tbuf. An excellent example is Joe Campbell's book on Serial Comm for C programmers.
TI will be set when the last data bit of your byte is shifted out, that is at the same time the stop bit is being signalled on the line. For ISR based comm. you'll need to detect an empty send buffer (the one you create in software, usually a ring) and if empty queue the data and set TI manually to start the process. Likewise for receive, you'll need to have a way to know if there is anything pending in your recv. ring buffer. Using XDATA buffers 256 bytes in size gives your 8-bit index a nice auto-wrap feature. Go to Intel's developer site and pick up PDF document called MCS-51 MICROCONTROLLER FAMILY USER'S MANUAL, it is "the authority" on 8051/8052 cores, IMHO. - Mark
By the way, there is a potential problem with the 8051's TI bit in that it tells you the data byte has been sent while it is still signalling the stop bit. It is possible to stuff a char into SBUF so quickly that the next char's start bit truncates the previous char's stop bit causing the receiving UART to flag a framing error. Just be on your toes for this. - Mark