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.

CCS/MSP430F5438A: UART TX interrupt

Part Number: MSP430F5438A

Tool/software: Code Composer Studio

Dear team

My customer wanted to use UART TX interrupt. The following is his code

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-- ;
    }

}

In this logic, the interrupt is entered 9 times and can only be sent once, and the interrupt will not be entered later.

If it is changed to this below code, it is normal, but he used a 485 chip, he wanted to send it completely and then generate an interrupt. 

At this time, the pin will be switched to receive. Please help to get method.

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 --;

 
   }




  • Hi Susan,

    I don't quite understand what you mean. In below code, when huart->txlen == 0, the huart->txbuf is beyond the boundary of buffer array. 

        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 );
        }
    The second code is correct, but what does customer want to achieve in last byte sent?
  • I don't know of a trick to use the TXIFG to detect when the USCI is idle. (The eUSCI has TXCPTIFG for this, but the F5438A doesn't have those.)

    I think you'll have to spin on UCBUSY (one byte time) somewhere.

**Attention** This is a public forum