Nextion HMI UART Issue
Hi,
I am using an STM32F407 Evaluation Board in my project, along with a Nextion HMI Display that communicates with the MCU over UART.
In this project, I send data every 1 second using a TIM interrupt with UART Polling Mode, and I receive data from the Nextion HMI using UART in interrupt mode (UART IT).
The issue arises when both transmit (TX) and receive (RX) operations happen simultaneously. The reception completes successfully, but the transmitted data from the Nextion HMI behaves incorrectly. However, if I perform only the receive or only the transmit operation, everything works fine.
I suspect that the problem occurs because the transmit and receive operations are colliding or overlapping.
I am attaching screenshots that show how the system should work and the problems I am encountering.
Could you help me identify where I might be making a mistake?
I am also struggling to find a way to transmit data using UART in interrupt mode (UART IT). I could use some help with that part as well.
/* USER CODE BEGIN 0 */
int a=0, b=0,c=0;
uint8_t RX_Data[5];
uint8_t end_Command[3] = {0xFF, 0xFF, 0xFF};
char nextion_Buffer[512];
void nextion_Send_String(char *ID, char *string)
{
int len=0;
len = sprintf(nextion_Buffer, "%s.txt=\"%s\"", ID, string);
HAL_UART_Transmit(&huart3, (uint8_t*)nextion_Buffer, len, 1000);
HAL_UART_Transmit(&huart3, end_Command, 3, 100);
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart->Instance == USART3)
{
if(RX_Data[1] == 0x31)
{
a=1;
}
else if(RX_Data[1] == 0x32)
{
a=2;
}
else if(RX_Data[1] == 0x33)
{
a=3;
}
else if(RX_Data[1] == 0x34)
{
a=4;
}
else if(RX_Data[1] == 0x30 || 0xFF)
{
a=0;
}
if(RX_Data[2] == 0x03)
{
b=3;
}
else if(RX_Data[2] == 0x04)
{
b=4;
}
else if(RX_Data[2] == 0x05)
{
b=5;
}
else if(RX_Data[2] == 0x06)
{
b=6;
}
if(RX_Data[3] == 0x30)
{
c=30;
}
else if(RX_Data[3] == 0x31)
{
c=31;
}
}
HAL_UART_Receive_IT(&huart3,RX_Data, sizeof(RX_Data));
}
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start_IT(&htim8);
HAL_UART_Receive_IT(&huart3,RX_Data, sizeof(RX_Data));
/* USER CODE END 2 */
/* USER CODE BEGIN 4 */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if(htim->Instance == TIM8)
{
nextion_Send_String("t01","hello");
}
}
/* USER CODE END 4 */
