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.

MSP430F5438A 串口中断发送问题

串口采用中断方式发送数据,开启发送中断前 UCTXIFG是置位的,所以当我使能发送中断时会立刻产生中断。

但是当我发送完成后,后面就不产生中断了,UCTXIFG位一直是0,这是怎么回事?

  • 能否给出您的程序?
  • void UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
    {
      
        huart->txbuf = pData;
        huart->txlen = Size;
                
        /* 使能串口发送中断 */
        USCI_A_UART_enableInterrupt(huart->baseAddress, USCI_A_UART_TRANSMIT_INTERRUPT );
    
    }
    
    
    void TX_IT_Callback(UART_HandleTypeDef *huart)
    {
      
        if(huart->txlen == 0U)
    { USCI_A_UART_transmitData(huart->baseAddress,*huart->txbuf); /* Disable the UART Transmit Data Register Empty Interrupt */ USCI_A_UART_disableInterrupt(huart->baseAddress, USCI_A_UART_TRANSMIT_INTERRUPT ); } else { USCI_A_UART_transmitData(huart->baseAddress,*huart->txbuf++); huart->txlen-- ; } }

    这个逻辑下进入中断是9次,只能发一次,后面不会再进入中断了。

    如果改为这样就正常了,但是我用了一个485芯片,想彻底发送完然后产生中断,此时切换引脚为接收,原因和方法请研究一下

     if(huart->txlen == 1U)
        {
          
          USCI_A_UART_transmitData(huart->baseAddress,*huart->txbuf);      
      
          /* Disable the UART Transmit Data Register Empty Interrupt */
          USCI_A_UART_disableInterrupt(huart->baseAddress, USCI_A_UART_TRANSMIT_INTERRUPT );
       
          huart->txlen --;
    
        }
    

  • 在下面的代码中,当huart-> txlen == 0时,huart-> txbuf超出了缓冲区数组的边界。

    if(huart->txlen == 0U) {

    USCI_A_UART_transmitData(huart->baseAddress,*huart->txbuf);

    /* Disable the UART Transmit Data Register Empty Interrupt */
    USCI_A_UART_disableInterrupt(huart->baseAddress, USCI_A_UART_TRANSMIT_INTERRUPT );
    }

    而您下面的第2个代码是正确的

    请问您现在在发送的最后一个字节中实现什么功能?