Nextion display - unabled to communicate with stm32f401RE CubeIDE

Hello everyone,

for a project at the university i have to programming an nextion display with a stm32f401re or a stm32g474re. (i can choose between them, i have both here). My problem is that i have configurate the display with the nextion editor. There i can change the text and it works. When i use the stm32f401re, connect the tx from the display to the rx from the processor (D0) and the rx from the display to the tx from the processor(D1) and the 5v with 5v, GND with GND, then i don`t can change the values. In my programm, i write

HAL_UART_Transmit(&huart2, (uint8_t*)"t0.txt=\"Hello\"\xFF\xFF\xFF", sizeof("t0.txt=\"Hello\"\xFF\xFF\xFF"), 1000);

HAL_Delay(1000);

When i use a logic analyzer on the pin tx, i see, that i get datas. Furthemore i looked at PuTTy. There i get the correct messages.

My baudrate is 9600 bps. in addition my clock settings are:

|Clock Source|HSE (8 MHz extern)|
|PLL Source|HSE|
|PLL_M|8|
|PLL_N|336|
|PLL_P|4|
|PLL_Q|7|
|System Clock (SYSCLK)|84 MHz|
|AHB Prescaler|1|
|APB1 Prescaler|2|
|APB2 Prescaler|1|
|UART Clock |42 MHz|

In addition i looked which signal level that display need. It need 3.3V. The stm32f401re had also an signal level of 3.3V. So this is also fine.

Now i have no idea what the problem is. Has anyone an idea?

If I understand correctly, you succeed in sending a messagefrom STM board to Nextion display.
So what is your problem exactly?

Unfortunately not. I want to send the message with USART. The message will send correctly on the TX-Pin but it doesnt reach the display. The display doesnt get this message. I checked it with PuTTy and with an logic analyzer, the stm32 send the message correctly but the display doesnt answer on this message. The message is correctly written, the signal level is correct, the wire is correct (rx to tx and tx to rx, gnd to gnd and 5v to 5v). So i dont understand why the display doesnt react to my message

Is the Nextion set for 9600 baud?

Yes,the nextion and the stm32 is set for 9600 baud

Your data stream will have a trailing null on the end. Does that matter ?

I had to use a printable character x40 instead of xFF to see what it is doing:

#include <iostream>
int main() {
    int x = sizeof("t0.txt=\"Hello\"\x40\x40\x40");
    std::cout << x << std::endl;
    printf( "%s", (uint8_t*)"t0.txt=\"Hello\"\x40\x40\x40") ;
    return 0;
}

18
t0.txt="Hello"@@@   (17 chars plus trailing null)

Did you try to send the same message from terminal program? Did the Nextion received it?

I think it doesn`t matter. I read that it will be used only the "real" letters, the 0 shows only the determination. But i´m new on this topic so i can be wrong.

Yes, i tried to send it from the terminal program but Nextion didn`t received it

Is the Nextion on the correct page when you send the text?

EDIT: What model of Nextion are you using?

So the issue is not with the sending from STM32, but with Nextion receiving.

Maybe you can play with this just incase your hex escaping is not interpreted as you expect:

uint8_t stopN[] = {0xFF, 0xFF, 0xFF};
HAL_UART_Transmit(&huart2, (uint8_t*)"t0.txt=\"Hello\""), sizeof( "t0.txt=\"Hello\"" ) , 1000 ) ;
HAL_UART_Transmit(&huart2, stopN, sizeof( stopN ) , 1000 ) 

HAL_Delay(1000);

You can show a receiving object for your "hello" string something equivalent to this example? :

So thank you everyone, i got a new update. At the moment it works when i first send the message and then cut the gnd or the current pin. So i have to cut them off and put the pin again inside. Then the text change. But now i have to built a circuit which cut after sending the message the current. Or have anyone another idea, how i can cut of the current for a ms?

It can't be right that you have to manipulate the power wires, after sending data, before something displays.
Have you now changed the format of the data stream you send to the Nextion or what did you do to get this far ?

I think that you are the only person who has ever needed to do this to transfer Serial input from an mcu to a Nextion.

I previously asked about the model of Nextion, because the Intelligent series is 5v ttl Serial, where the other other series are 3.3v.