Start a new topic

STM32 and Nextion Display

First of all, I've already read a lot of topics and documentation and somehow it is not working yet, this is why I came here ask you.


 At my code i'm trying read a button at the screen and then toggle a led and increment number every time I push the button.


What is working? The dual state buttom from de display it's making my led switch as it should be.


I just can't write at the nextion display, i've tryed a lot of stuff, can someone just send me the part of a code that works on Keil uVision?  

bufferTX [2] = 0xFF;
	address [0] = 0;

  while (1)
		HAL_UART_Transmit (&huart1, "n0.val=", 1, 10);
		HAL_UART_Transmit (&huart1, address, 1, 10);
		HAL_UART_Transmit (&huart1, &bufferTX[2], 3, 10);
		HAL_UART_Receive (&huart1, bufferRX, 10, 100);
		if (bufferRX[0]== 0xaa) 
		if (bufferRX[0]== 0xbb) 


So unless this is for an STM32 Cortex M0

 - my guess is that the Keil uVision compiler means commercial or academic project

I'm using STM32F401RE, it is a cortex M4 My doubt it's about sending the message, because a I just have the function HAL_UART_Transmit, but Arduino has two, write_text and write. I know that the communication it's working, I'm just not sure about sending data correctly. I guess the problem is when I send n0.val=, because it's a string...

So indeed, the Cortex M4 is not one that ST pays for the Keil licencing.

 - meaning this project is commercial or academic.

When Academic, you must earn your degree.

When Commercial, we can offer Enhanced Support in web storefront.

RM0368 is 841 pages, PM0214 is another 260 pages.

Perhaps Keil and Arduino shouldn't be mentioned in the same sentence.

Sorry guy, but I'm not understandig yout point.

I have a nextion display and I have my own MCU, I just came here for some help the same away you guys helped thousand you people at this forum.

I just wanna some example or a tip from someone who uses STM32 with this display.

Your question is indeed less Nextion related

 - more of used Programming Language

 - more of used Compiler

 - more of used MCU

No, it is all about nextion.

If I'm here, it's because I wanna some help.

It's not a normal UART communication, and each MCU has it's own secrets.

I've read others topics and you guys are too rude, if you can't help me, just say you don't know.

Read Nextion TTL Serial post also on the forum (search bar above)

   A Nextion command is text based n0.val=23ÿÿÿ

Read the Nextion Instruction Set

You code above 

 - receiving is single byte

    - no Nextion Return Data (as per NIS) could ever be received

 - transmitting is perhaps malformed, but basic debugging would reveal

Keil compiler for an M4, indeed didn't sound like Hobby

Ok, thanks, I'll keep trying by myself.

I'm a electrical engineering student, i'm not just a hobbyist.

But you shouldn't take care with where I'm gonna use my own stuff, I've just asked some help.

Interesting approach

 - "just say you don't know", I like that one - its innovative and funny

It's that when I help a hobbyist from my spare time

   I do so because I want to help them over a hurdle

Commercial projects however should they not make a contribution?

 - they pay their asking employee much, and nothing for my time.

Academics, I only hurt them when I do it for them

 - they learn nothing, graduate and become useless to their employer.

So, indeed different scenarios

Your MCU doesn't know what Text is

 - Text is a regional linguistic construct

    - varies ASCII <> KS_C_5601-1987 <> gb2312 <> iso-8859-1 <> iso-8859-5

 - dig into TTL Serial

 - your MCU doesn't send "A" it sends a byte

    char arrays should be a basic Keil structure

 - value destined for n0 needs to be converted into Text

Hook up your MCU to a Terminal program

 - confirm what you are sending is what you meant

Nextion Instruction Set

 - all commands are terminated with 3 trailing 0xFF bytes

Now I got your point, maybe because I'm not fluent in english but now it's clear for me.

You should know that cortex M4 can be used with some limits for free, and this is my case. You shouldn't just jugde that a powerfull MCU its just related with comercial projects.

I'm indeed learning this stuff for future projects at college, but if i came ask something it's because I already spent some hours looking the answer by my self.

Actually I was judging by how much ARM asked me to pay for Keil liciencing.

 - such rates are well beyond a student or hobbyist budget

An MCU logic needs to be broken down to extremes

Arduino C++ doesn't really expose much in terms of Registers to the user

A compiler like ones from mikroE,

    perhaps more user friendly more libraries built for the user, still accessing all Registers

And a compiler like Keil is meant for absolute total control

    Mostly all by Registers, but nothing buried and hidden in library code away from the user.

So with Keil, there is indeed much to ensure that all Registers are set proper

 - consider the level of programming logic required higher

 - don't assume that anything has been done already for you

 - be prepared to build your functions for any functionality that seems missing

Which ever encoding the HMI is in and Nextion Fonts generated for

 - memorize the character table and the corresponding byte values

   value of 23 is not sent as a single byte for n0, but has to be Text

   meaning two bytes 0x32 0x33

 - you may need to build it from scratch

Assume nothing,

- you are going to have to dig deep into the docs 1000+ pages for M4

- then you are going to have to dig into every Keil function call

   - you have to learn your compiler, and Keil's version of C

Serial buffers, don't assume, dig in to find out

 - the STM32F401 will only have a 3 word hardware buffer

    - one byte being sent, and max 2 in the queue

    At 84 MHz this will be filled within a few cycles .. < microseconds

 - the use of interrupts may not be automatically set up for you

   TX interrupt when the TX register is empty

   RX interrupt when the RX register is full and byte is ready

 - Software buffers to work in conjunction with the interrupts

greetings every one.

i seriously need help. i was having challenges with speed on arduino (too slow) with large codes. i decided to switch to stm32f103c8t6. but i cant communicate the nextion display and STM32.

am using arduino IDE, with ( library, 4.3inch display basic. i have no troubles using arduino with this library, but when i follow same procedure it doesn't work for the STM32 controller.

may be some modification is required on d library to communicate with display.

i tried both the softwareserial and hardware serial but no success.

when i use the softwareserial and compile the code it ends up with error. if i use the hardwareserial the code compiles but no communication.

please help.

(softwareserial )

//#include "Arduino.h"

#include "stdio.h"

#include <SoftwareSerial.h>

#include "Nextion.h"

SoftwareSerial nextion(2, 3);// Nextion TX to pin 4 and RX to pin 5 of Arduino

Nextion myNextion(nextion, 115200);

(hardware serial)

 #include "stdio.h"

#include "Nextion.h"

#define nextion Serial2

Nextion myNextion(nextion, 115200);

Login or Signup to post a comment