2004-09-22 10:49 PM
UART - starting the TX interrupt process
2011-05-17 03:02 AM
Im implementing the UART in an interrupt mode. I have a transmit queue feeding the SBUF for Tx. The process is easy, once data has been written to SBUF, at the end of the transfer my interrupt handler will be called. If data is available in the queue, it will be written to the SBUF and TI will be cleared. If data is not advailable, no data will be written and TI will be cleared (stopping the interrupt process).
My question is: If data is written to my transmit buffer after the aboue operation has stopped, how do I start the Tx interrupt process? My best guess would be to set TI=1 every time data is written to the transmit queue.2011-05-17 03:02 AM
You are correct, this is the easiest way to start buffered transmission.
You will also need a busy flag which will show to your main program that the transmission process is still in progress, so that a new transmission should not be started, and the transmission buffer should not be modified. You set the busy flag together with TI, and the interrupt function clears it after the last byte has been transmitted. Have a nice time. Daniel2011-05-17 03:03 AM
Thanks Daniel,
I’ll implement the busy flag approach. What is stated in the Doc (for mode 1) is an Interrupt be will asserted at the beginning of the stop bit transition. It appears that if TI is set my by application while a byte in the transition buffer the interrupt handler would be called immediately and the transmission buffer would be over-written. This is what I'm reading into the discription. Barry Barry2011-05-17 03:03 AM
Quote:
What is stated in the Doc (for mode 1) is an Interrupt be will asserted at the beginning of the stop bit transition. It appears that if TI is set my by application while a byte in the transition buffer the interrupt handler would be called immediately and the transmission buffer would be over-written. This is what I'm reading into the discription. This is exactly why you need a busy flag. Simply monitoring the transmission counter is not good enough. When your interrupt function sees that the transmit counter is empty, it can safely clear this flag: the last byte has been transmitted, and the SBUF register is free to accept another byte. Daniel