STM32H7 problem with UART Rx IT callback
Hello everyone!
After many hours of grinding through forums & discussing with ChatGPT (really, ChatGPT is like my best friend now), I still fail to understand what must be a simple notion with an easy solution. This is why I'm posting this in forums.
I have a device which is transmitting data constantly (with about 4-5 Mbits/sec rates). I use HAL_UART_Transmit_DMA method for it. This part works correctly.
I also need to receive some commands from the PC to configure or signal the device. The frequency of this command reception is very low (about 1-2 commands per 10 seconds, usually). I try using HAL_UART_Receive_IT method for it (because from what I understand, it is best practice for such a requirement).
I want the UART interrupt to trigger only on actual data reception (like RXNE - Receive Data Register Not Empty). I have a buffer of 1 byte long and I try filling it via the following command ->
uint8_t rxBuffer[1];
__HAL_USART_ENABLE_IT(&husart3, USART_IT_RXNE);
HAL_USART_Receive_IT(&husart3, (uint8_t*)rxBuffer, 1);
I need the callback function to fire only when I get data in the buffer. Instead, I discover in debugging that it fires repeatedly, messing up with the data transmission DMA. This is my callback function:
void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart)
{
commandRecieved = 1;
command = rxBuffer[0];
memset(rxBuffer, 0, sizeof(rxBuffer));
HAL_USART_Receive_IT(&husart3, (uint8_t*)rxBuffer, 1);
}
(my plan was to use the commandRecieved flag and command in the main while(1) function, then clear them after handling the command)
What am I missing here? What can I do so that callback function only fires when the buffer is full (i.e. I received a command from PC) instead of firing all the time?
Regards
