cancel
Showing results for 
Search instead for 
Did you mean: 

UART HMI Display Receive-Transmit Issue

frkdkk
Associate

Hi,

I am Faruk.

What i am trying to do is, sending data that i collacted from ADC Ports to Nextion HMI Display. Also at the same time i am getting signals from buttons on the Nextion HMI Display. I use UART pins of Nextion HMI Display. 5V RX TX GND.

If i dont transmit any data to HMI Display i can get signals from buttons on HMI Display. One of the buttons start saving data to SD Card. The other ones increase and decrease the output signal that goes out from DAC. 

When i use receive and transmit at the same time. Only transmit section works. I cannot get signal from buttons on HMI Display. I am uploading the code here. I just couldnt figure it out why it doesent work correctly. I need some help about this situation. This is my final project. I am gonna test it on Friday. So i have to figure it out. I also uploaded the main.c file. 

 

//Data sending to Nextion HMI Display
void nextion_Send_Float(char *obj, float num, int dp)
{
 
int32_t number = num*(pow(10,dp));
 
uint8_t *nextion_Buffer = malloc(50*sizeof(char));
int len = sprintf((char *)nextion_Buffer, "%s.vvs1=%d", obj, dp);
HAL_UART_Transmit(&huart3, nextion_Buffer, len, 10);
HAL_UART_Transmit(&huart3, end_Command, 3, 10);
 
len = sprintf((char *)nextion_Buffer, "%s.val=%ld", obj, number);
HAL_UART_Transmit(&huart3, nextion_Buffer, len, 10);
HAL_UART_Transmit(&huart3, end_Command, 3, 10);
 
 
free(nextion_Buffer);
 
 
 
}
 
 
void nextionData()
{
 
nextion_Send_Float("x6", Vout, 2);
nextion_Send_Float("x7", Iout, 2);
nextion_Send_Float("x8", Vout, 2);
nextion_Send_Float("x9", Iout, 2);
nextion_Send_Float("x10", V1L, 2);
nextion_Send_Float("x11", I1L, 2);
nextion_Send_Float("x12", V2L ,2);
nextion_Send_Float("x13", I2L, 2);
nextion_Send_Float("x14", V3L, 2);
nextion_Send_Float("x15", I3L, 2);
nextion_Send_Float("x16", V12L, 2);
nextion_Send_Float("x17", I12L, 2);
nextion_Send_Float("x18", V23L, 2);
nextion_Send_Float("x19", I23L, 2);
nextion_Send_Float("x20", V13L, 2);
nextion_Send_Float("x21", I13L, 2);
nextion_Send_Float("x22", temp, 2);
nextion_Send_Float("x0", Vout, 2);
nextion_Send_Float("x1", Iout, 2);
 
}
 
 
 
//Getting signal from Buttons on HMI Display. Also changing the output value with DAC.
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart == &huart3)
{
 
 
if(RX_Data[2] == 0x03)
{
 
if(dac_V == 0){ dac_V = 0; }
else { dac_V -= 0.5; }
send_V = (int)map(dac_V,0,20,0,1275);
 
 
}
 
if(RX_Data[2] == 0x04)
{
if(dac_V == 20){ dac_V = 20; }
else{ dac_V += 0.5; }
send_V = (int)map(dac_V,0,20,0,1275);
 
 
}
 
if(RX_Data[2] == 0x05)
{
if(dac_I == 0){ dac_I = 0; }
else{ dac_I -= 50; }
send_I = (int)map(dac_I,0,3000,0,1275);
 
}
 
if(RX_Data[2] == 0x06)
{
if(dac_I == 3000){ dac_I = 3000; }
else{ dac_I += 50; }
send_I = (int)map(dac_I,0,3000,0,1275);
 
}
 
 
 
 
if(RX_Data[3] == 0x30)
{
sd_Flag=START;
}
 
else if(RX_Data[3] == 0x31)
{
sd_Flag=STOP;
}
 
 
 
HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R,send_V);
HAL_DAC_SetValue(&hdac, DAC_CHANNEL_2, DAC_ALIGN_12B_R,send_I);
 
 
  HAL_UART_Receive_IT(&huart3, RX_Data, sizeof(RX_Data));
 
 
}
 
 
 
 
}

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)  
{
 
if(htim->Instance == TIM1) // Interrupts every 50us for ADC to collact data
{
 
HAL_ADC_Start_DMA(&hadc1, (uint32_t*) adc_Buffer, sizeof(adc_Buffer)); 
 
}
 
if(htim->Instance == TIM8)  // Interrupts every 1sec to tranmit data to HMI Display
{
 
  nextionData();
 
}
 
 
}

 

 

0 REPLIES 0