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