??? 06/01/05 07:41 Read: times |
#94169 - one of ways Responding to: ???'s previous message |
hi,
Hans Van Pelt said:
An ISR is just another piece of program, and the serial ISR will be executed every time after the UART HARDWARE has completed sending out the previous byte. Regardless of what you are doing in main. ...except when you disable global or the UART interrupt somehow. The TI flag gets set by the UART hardware after it has sent out the byte you last put in SBUF completely.
At classic C51, TI flag is set by hardware at the end of the 8th bit time in mode 0 or at the beginning of the stop bit in the other modes. If be pedant, so this occurs at S1P1 of the tenth machine cycle after "write to SBUF." You should NOT set TI to 1 yourself. Leave that to the hardware! The idea behind interrupt driven serial transmission is this:
In the main: - Prepare a set of bytes you want to send, for instance like you do in an array, but for serious applications fifo's are used, - Put the first byte in SBUF, - Go and do other things. Indeed, this is the one of ways to utilize UART interrupt. But this is not the one and only one way. I seen others ways which looks correct and elegant as well, like next: - After preparing bytes and their counter and pointer, just set TI flag. Rest of work is made inside interrupt. After data has been sent, interrupt reports with clear user-made UART_BUSY flag. This is example, where you just set TI flag instead read byte from FIFO/array and move it to SBUF for transfer initialization. Really, why should I do the same work twice in different places, yeah? - The example below I seen in one of projects where the only transmit has been utilized. There were UART mode 0 + external shift registers as output port expanders. So, at initialization time the serial interrupt is disabled (ES=0) although TI is set during SCON configuration then. Any time when we need to send data, we just enable serial interrupt (ES=1). If sent byte is not last one, the serial ISR clears TI and loads next byte into SBUF. If the last byte has been sent then the serial ISR just disables itself (ES=0) and does not clear TI. By this way, ISR comes to defined start stage of work itself and indicates the end of transmit with cleared ES. Indeed, such way has troubles with data receiving interrupt (RI=1). Anyway this way has been used with transmit only so no problem. Finally, what I have to say: there are many ways how to do things and we should not say anybody: "do this way only". We just show how it may be done and anybody thinks what is the best for him. Regards, Oleg |
Topic | Author | Date |
inetrrupt driven serial | 01/01/70 00:00 | |
RE: inetrrupt driven serial | 01/01/70 00:00 | |
interrupt driven serial | 01/01/70 00:00 | |
It means Done | 01/01/70 00:00 | |
RE: interrupt driven serial | 01/01/70 00:00 | |
one of ways | 01/01/70 00:00 | |
thanks to all | 01/01/70 00:00 | |
RE: thanks to all | 01/01/70 00:00 | |
Wheel re-invention award | 01/01/70 00:00 | |
good subject !![]() | 01/01/70 00:00 |