cancel
Showing results for 
Search instead for 
Did you mean: 

UART - starting the TX interrupt process

javidaboo
Associate II
Posted on September 23, 2004 at 07:49

UART - starting the TX interrupt process

4 REPLIES 4
javidaboo
Associate II
Posted on May 17, 2011 at 12:02

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.
danielh1
Associate II
Posted on May 17, 2011 at 12:02

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.

Daniel

javidaboo
Associate II
Posted on May 17, 2011 at 12:03

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

Barry
danielh1
Associate II
Posted on May 17, 2011 at 12:03

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