How do I process just UART RX interrupt events while using HAL_UART_Transmit_IT
I've run into another hurdle I don't seem to be able to solve myself while trying to learn embedded STM32 programming. I have a simple test program that transmits characters over a UART with the RX and TX pins looped together and receives them using interrupts. When I transmit the data using HAL_UART_Transmit, I can process the received characters in my IRQHandler fine. But when I use HAL_UART_Transmit_IT, my IRQHandler puts 2 characters in my receive buffer for every character I transmit. I'm pretty sure this is because my IRQHandler is getting called for every character transmitted and every character received. You can see how I tried to only process received characters in my IRQHandler below but it hangs up after a few characters. Any ideas on what I'm doing wrong or any ideas on a better way to do this will be greatly appreciated.
Thanks
PS In the long run, I'd like to make this work with DMA and end the transfer using the character match interrupt. I've got that working on a STM32H7A3 Nucleo board but not on the STM32H7B3Discovery board that I need to use. So I'm working on this IT method for now.
initUART4();
uint8_t txBuffer[] = { "$PUBX,00*33\r\n" };
memset(rxBuffer, 0, sizeof(rxBuffer));
memset(gpsMessage, 0, sizeof(gpsMessage));
msgReceivedUART4 = false;
HAL_UART_Receive_IT(&uart4Handle, rxBuffer, 1);
HAL_UART_Transmit(&uart4Handle, txBuffer, sizeof(txBuffer), 2000); //This works
//HAL_UART_Transmit_IT(&uart4Handle, txBuffer, sizeof(txBuffer)); //This doesn't work
while (1)
{
//Do other stuff
if(msgReceivedUART4)
{
//process UART4msg
HAL_Delay(1);
}
}
}
void UART4_IRQHandler()
{
HAL_UART_IRQHandler(&uart4Handle);
// if (__HAL_UART_GET_FLAG(&uart4Handle, UART_FLAG_RXNE))
// {
if (rxBuffer[0] != 0)
{
gpsMessage[gpsMsgCount] = rxBuffer[0];
gpsMsgCount++;
}
if (rxBuffer[0] == '\n')
{
fifoEnqueue(rxBuffer);
msgReceivedUART4 = true;
}
else
HAL_UART_Receive_IT(&uart4Handle, rxBuffer, 1);
// }
}