简体   繁体   English

MSP430 UART TX中断启用/禁用

[英]MSP430 UART TX Interrupt Enabling/Disabling

I have RX interrupts working just fine, but I wanted to add TX interrupts. 我的RX中断工作正常,但是我想添加TX中断。 I respond to long commands over the UART and don't want to waste cycles waiting for the TX to complete before sending along the next byte. 我通过UART响应长命令,不想浪费时间等待TX完成再发送下一个字节。 I am trying to enable interrupts, transmit the data that needs to be transmitted, then disable the interrupts until the next TX packet comes along. 我试图启用中断,传输需要传输的数据,然后禁用中断,直到出现下一个TX数据包。

This works fine for the FIRST payload that I send out. 这对于我发出的FIRST有效负载效果很好。 I see it go out just fine. 我看到它熄灭就好了。 However as soon as I disable TX Interrupts once, I am never able to enter the ISR again. 但是,一旦我禁用TX中断,就永远无法再次进入ISR。 How on the MSP430 does one enable TX Interrupts on the UART and have it ever get into the ISR again? 如何在MSP430上使能UART上的TX中断并使它再次进入ISR?

Below where you see EUSCI_A_UART_enableInterrupt call, shouldn't this line trigger my ISR every time the interrupt gets enabled? 在下面看到EUSCI_A_UART_enableInterrupt调用的位置,该行是否应在每次启用中断时触发ISR? If not, HOW DO I GET BACK INTO THE ISR AGAIN? 如果没有,我该如何重新回到ISR?

Here's the Transmit code: 这是发送代码:

void UartSendChar(uint8_t tx_char)
{
    ring_buffer_put(_rbdTx, &tx_char);
    EUSCI_A_UART_enableInterrupt(EUSCI_A1_BASE, EUSCI_A_UART_TRANSMIT_INTERRUPT); // Enable interrupt
}

Here's my ISR: 这是我的情监侦报告:

void EUSCI_A1_ISR(void)
{
    int c=-1;
    switch(__even_in_range(UCA1IV,USCI_UART_UCTXCPTIFG))
    {
    case USCI_NONE: break;
    case USCI_UART_UCRXIFG:
       ...
    case USCI_UART_UCTXIFG:
        // If there's something in the Ring Buffer, transmit it
        // If not, then disable TX interrupts until new data gets written.
        if (ring_buffer_get(_rbdTx, &c) == 0)
        {
            EUSCI_A_UART_transmitData(EUSCI_A1_BASE, (uint8_t)c);
        }
        else
        {
            EUSCI_A_UART_disableInterrupt(EUSCI_A1_BASE, EUSCI_A_UART_TRANSMIT_INTERRUPT);
        }

I figured out the problem. 我解决了这个问题。 In this particular MSP430, when the interrupt vector is read and it shows a TX interrupt, the TXIFG bit automatically gets cleared by the micro. 在此特定的MSP430中,当读取中断向量并显示TX中断时,单片机会自动将TXIFG位清零。 (How nice of it) (真好)

In order to get this ISR to fire again after re-enabling TX interrupts, the TXIFG bit must be manually set back to 1 again, which shows an interrupt pending. 为了使ISR在重新使能TX中断后再次触发,必须将TXIFG位再次手动设置为1,这表示有一个未决的中断。 That way, when interrupts are enabled after data is shoved into the queue, the TXIFG bit is set, so the ISR executes and ships the data off. 这样,当将数据放入队列后允许中断时,TXIFG位置1,因此ISR执行并发送数据。

Now my ISR looks like this: 现在,我的ISR如下所示:

void EUSCI_A1_ISR(void)
{
    int c=-1;
    switch(__even_in_range(UCA1IV,USCI_UART_UCTXCPTIFG))
    {
    case USCI_NONE: break;
    case USCI_UART_UCRXIFG:
       ...
    case USCI_UART_UCTXIFG:
        // If there's something in the Ring Buffer, transmit it
        // If not, then disable TX interrupts until new data gets written.
        if (ring_buffer_get(_rbdTx, &c) == 0)
        {
            EUSCI_A_UART_transmitData(EUSCI_A1_BASE, (uint8_t)c);
        }
        else
        {
            EUSCI_A_UART_disableInterrupt(EUSCI_A1_BASE, EUSCI_A_UART_TRANSMIT_INTERRUPT);

            // Set TXIFG manually back to 1 for next time.
            HWREG16(EUSCI_A1_BASE + OFS_UCAxIFG) |= EUSCI_A_UART_TRANSMIT_INTERRUPT;

        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM