This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

I need an interrupt when SCI TX shift register becomes empty

Other Parts Discussed in Thread: HALCOGEN, TMS570LS0432

I am using the SCI driver provided by HALCOGEN and FreeRTOS. I am using a GIO to send an enable line to an external RS485 transceiver. When I need to transmit I raise the GIO and transmit. My problem is I need to clear the GIO when the transmission is completed. I have tried clearing the GIO in linHighLevelInterrupt() when the tx_length is zero but the GIO clears too early and the last byte does not get sent by the transceiver. It appears that I am getting the TX ready interrupt before the TX shift register has finished sending all bits. How can I get an interrupt when the transmission is truly complete? Here's my modification of the  linHighLevelInterrupt() switch case 12:

    case 12U:
        /* transmit */
        /*SAFETYMCUSW 30 S MR:12.2,12.3 <APPROVED> "Used for data count in Transmit/Receive polling and Interrupt mode" */
           --g_sciTransfer_t.tx_length;
        
        if ((g_sciTransfer_t.tx_length) > 0U)
        {
            uint8 txdata = *g_sciTransfer_t.tx_data;
            scilinREG->TD = (uint32)(txdata);
            /*SAFETYMCUSW 567 S MR:17.1,17.4 <APPROVED> "Pointer increment needed" */
            g_sciTransfer_t.tx_data++;
        }
        else
        {
            scilinREG->CLEARINT = SCI_TX_INT;
            sciNotification(scilinREG, (uint32)SCI_TX_INT);
            
               // if TX send reg is empty then we can
               // turn off the ENABLE line
               gioSetBit(gioPORTA, LIN_EN, FALSE);
        }
        break;

  • Hello,
    What device are you using?

    In general, transmit Interrupt is generated after the first transfer from SCITD to SCITXSHF then you can use TX EMPTY flag to monitor SCITXSHF and SCITD registers. SCI sets TX EMPTY flag when both SCITXSHF and SCITD registers are empty.

    Best regards
    Miro
  • I am using a TMS570LS0432 and FreeRTOS.

    This answer requires some task to spin waiting for the TX EMPTY flag to go high. I certainly don't want to spin in the ISR. I don't really want to rely on my task as it wakes up every 10 mSec and that is too long to hold the GIO line after a transmission is done.

    Short answer is there is no interrupt when TX EMPTY flag goes high? That's disappointing.

    My scope showed that, at 9600 baud, it takes approximately 1.75 mSec between the time I get my last SCI_TX_INT interrupt and the time the transmission has actually passed completely out of the RS485 port. My work around was to create a task in FreeRTOS dedicated to clearing the GIO. When get a SCI_TX_INT interrupt and the tx_length is zero then I wake up this task; it does a vTaskDelay for 2 mSec, drops the GIO line and then does a vSuspend. This pretty consistently holds the enable GIO for 0.256 mSec after the transmission has cleared the RS485 line.

    I would have been happier to be able to drop the line immediately after the transmission cleared the RS485 line but this is pretty close.