Clearing SCI Transmit Interrupt Flag

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Clearing SCI Transmit Interrupt Flag

3,060 Views
slammers
Contributor I
I am using a MC9S12C64 and am trying to use the transmit interrupt to send each charcter out the serial port. However, I can not seem to clear the Interrupt flags. When I get an Interrupt for TDRE or TC, I read SCISR1 and then write to SCIDRL as sugegsted in the datasheet but the interrupts just continue indefinitley even after I am not longer sending data.

From my understanding, TDRE is set one the transmit buffer is free. I write to the buffer for the next character. If no characters are to be sent I do not write to the data register.

This will cause TC interrupt since the TDRE flag is set and no data is being transmitted.

Now both TC and TDRE are set. The SCI interrupt will not continualy be called evern though no characters are being sent.

How can you clear these flags so no interrupts occur after I have sent all my information?

Thanks Shawn
Labels (1)
0 Kudos
Reply
2 Replies

1,150 Views
mjbcswitzerland
Specialist V

Hi Shawn

Tonyp is right. The Tx interrupt is active whenever the output buffer is empty, which is true when nothing has been sent yet. The strategy is:

FIRST WRITE (egs for UART 1):

if (SCISR1_1 & TDRE) {                // tx not busy
    ucDummy = SCISR1_1;               // read interrupt flags to ensure empty flag is reset when the character is written
    SCIDRL_1 = ucTxByte;              // send first byte
    SCICR2_1 |= (TIE);                // enable TX interrupt
}

ON TX interrupts

    if (SCISR1_1 & RDRF) {
        if (more to send) {
            SCIDRL_1 = ucTxByte;     // send next byte
        }
        else {
            SCICR2_1 &= ~(TIE);      // disable Tx interrupts
        }
    }

Regards

Mark Butcher
www.mjbc.ch / www.uTasker.com

1,150 Views
tonyp
Senior Contributor II
You're posting in the wrong group.  S12 is in the 16-bit MCU section.  Nevertheless ...
 
To stop TX interrupts from firing once you're done sending bytes, you neeed to turn off TX interrupts from within the TX ISR when you no longer have another byte to send.  Re-enable TX interrupts when any byte is added to the TX queue (e.g., in your PutChar routine).
 
Hope this helps.