cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F767 UART RX interrupt unreliable with Dacai HMI (UART7, HAL_UART_Receive_IT)

Dhinakaran
Associate

Hi, I am using an STM32F767ZI to communicate with a Dacai HMI display over UART7 at 9600 baud. Sending data from the STM32 to the HMI works perfectly, but receiving data from the HMI is unreliable. The same HMI works fine when communicating with other MCUs—both TX and RX work reliably.
When I touch:

  • screen ID = 0
  • control ID = 12

HMI tool shows this frame:

 

EE B1 11 00 00 00 0C 11 31 32 00 FF FC FF FF ( Data : 12 ( 31 32 ) )
Data reception does not match actual touch event
  • HMI → STM32 reception is very unreliable
  • Callback (HAL_UART_RxCpltCallback) is triggered rarely
  • Breakpoint inside callback is almost never hit
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
  if (huart->Instance == UART7) {
    HAL_GPIO_TogglePin(GPIOB, LD1_Pin);  // debug

    uint8_t b = rx_byte;

    if (frameIndex == 0 && b != 0xEE) {
      HAL_UART_Receive_IT(&huart7, &rx_byte, 1);
      return;
    }

    if (frameIndex == 1 && b != 0xB1) {
      clearFrameBuffer();
      if (b == 0xEE) frame[frameIndex++] = b;
      HAL_UART_Receive_IT(&huart7, &rx_byte, 1);
      return;
    }

    if (frameIndex == 2 && b != 0x11) {
      clearFrameBuffer();
      HAL_UART_Receive_IT(&huart7, &rx_byte, 1);
      return;
    }

    frame[frameIndex++] = b;

    if (frameIndex >= 15) {
      if (frame[frameIndex - 4] == 0xFF && frame[frameIndex - 3] == 0xFC &&
          frame[frameIndex - 2] == 0xFF && frame[frameIndex - 1] == 0xFF) {
        frameReady = 1;
        clearFrameBuffer();
      }
    }
    HAL_UART_Receive_IT(&huart7, &rx_byte, 1);
  }
}

I suspect this issue might be related to timing, buffer handling, or UART configuration, but I am not sure what is causing the missed data.

Any help or debugging suggestions would be greatly appreciated!

 

 

1 REPLY 1
Peter BENSCH
ST Employee

Welcome @Dhinakaran, to the community!

Please first verify the low‑level UART side:

  1. Check UART7 configuration
    • Word length = 8bits, Parity = None, Stop bits = 1, Oversampling = 16, Mode = RX + TX, baud = 9600
    • Disable hardware flow control (RTS/CTS) unless the HMI uses it

  2. Use continuous reception, not 1‑byte re‑arming
    • Start with
      HAL_UART_Receive_IT(&huart7, rx_buf, RX_BUF_LEN);
      once in main() and parse the frame in the callback (or use DMA + idle‑line)
    • Re‑arming HAL_UART_Receive_IT() for a single byte at the end of the callback is slow and any interrupt latency can cause missed bytes, especially if other interrupts have higher priority

  3. Interrupt priority
    • Ensure USART7_IRQn has a high priority (lower numerical value) and is not masked by SysTick or other heavy ISRs

  4. Use a logic analyser on UART7 RX to confirm that every frame from the HMI is present and correctly timed

  5. If possible, map the HMI to another UART (e.g. USART3) with the same code. If it works there, focus on UART7 pins/clock/AF configuration

These points usually fix rarely called HAL_UART_RxCpltCallback problems on STM32F7 when TX works but RX is unreliable.

Hope that helps?

Regards
/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.