STM32F767 UART RX interrupt unreliable with Dacai HMI (UART7, HAL_UART_Receive_IT)
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:
- 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!
