2024-07-28 11:00 AM - edited 2024-07-28 11:08 AM
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.
Solved! Go to Solution.
2024-10-27 06:49 AM - edited 2024-10-27 06:50 AM
Hi,
I figured out the problem. I was trying to send data to other pages while on a specific page. Basically, what happens is that the Nextion HMI gives an error code if I try to send data when I'm not on the correct page. So, I classified the transmitted data according to the page data received. Here is the code that works fine.
while (1)
{
if(u_Flag==OK){
if (RX_Data[1] == 0x31) {
nextion_Send_String("t11", "hello");
}
else if (RX_Data[1] == 0x32) {
nextion_Send_String("t21", "hello");
}
else if (RX_Data[1] == 0x33) {
nextion_Send_String("t31", "hello");
}
else if (RX_Data[1] == 0x34) {
nextion_Send_String("t41", "hello");
}
else if (RX_Data[1] == 0x30 || RX_Data[1] == 0x80) {
nextion_Send_String("t01", "hello");
}
u_Flag=NOK;
}
if(Flag==OKI){
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 || RX_Data[1] == 0x80) {
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;
}
Flag=NOKI;
}
2024-07-30 10:09 AM
@frkdkk wrote:When i use receive and transmit at the same time. Only transmit section works. I cannot get signal from buttons on HMI Display
Not sure what you mean here?
"Transmit" refers to sending stuff from your STM32 to the Display - yes?
"Receiving" refers to stuff coming from the Display into your STM32 - yes?
What "signal" do expect to get from the Display ?
Is the problem with the Display not sending, or with the STM32 not receiving?
Please see the posting tips for how to properly post source code:
2024-09-11 05:04 PM
use the </> when posting code so that it gets properly formatted. Makes it easier to read the code.
You're doing to much processing in the HAL_UART_RxCpltCallback
Instead, save the data to a secondary buffer and set a flag, enable the UART interrupt, then exit the interrupt.
Then check the flag in your main while loop and do the processing of the secondary buffer. All the while the UART can still receive data in the primary buffer during your processing.
2024-09-11 05:09 PM
Now that i look at more of your code, you are using blocking code when transmitting. You should use interrupts or DMA along with a queue buffer.
See this project https://github.com/karlyamashita/Nucleo-G431RB_Three_UART/wiki
2024-10-27 06:49 AM - edited 2024-10-27 06:50 AM
Hi,
I figured out the problem. I was trying to send data to other pages while on a specific page. Basically, what happens is that the Nextion HMI gives an error code if I try to send data when I'm not on the correct page. So, I classified the transmitted data according to the page data received. Here is the code that works fine.
while (1)
{
if(u_Flag==OK){
if (RX_Data[1] == 0x31) {
nextion_Send_String("t11", "hello");
}
else if (RX_Data[1] == 0x32) {
nextion_Send_String("t21", "hello");
}
else if (RX_Data[1] == 0x33) {
nextion_Send_String("t31", "hello");
}
else if (RX_Data[1] == 0x34) {
nextion_Send_String("t41", "hello");
}
else if (RX_Data[1] == 0x30 || RX_Data[1] == 0x80) {
nextion_Send_String("t01", "hello");
}
u_Flag=NOK;
}
if(Flag==OKI){
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 || RX_Data[1] == 0x80) {
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;
}
Flag=NOKI;
}