Start a new topic

Microc Arm

I want to example with stm32f4 and nextion 

read command 
 if(UART3_Data_Ready()&& i<=6) // If data is received
  {     rx_array[i]=Uart3_Read();     i++;   }
I dont send " write command "
UART3_Write_Text("n0.val++");

I dont find problem about

rar
(1.05 MB)
rar
(237 KB)

I am not certain of your need


The Nextion Instruction Set defines what is needed to be sent and received over serial

You will have to consult mikroC libraries on how you need to send via serial



I dont send any data from stm32f4 to Nextion LCD

I want to help

I dont understand for my problem


UART3_Write_Text("t0.txt=");

 

        UART3_Write(0x22);// " işareti

 

        UART3_Write_Text("4");

 

        UART3_Write(0x22); // " işareti

 

          UART3_Write(0xFF);

 

          UART3_Write(0xFF);

 

          UART3_Write(0xFF);

Which is not understood?

- How to configure and use your STM32F4 MCU UART?

- How to use mikroC for ARM?

- How to use Nextion Instruction Set


All three need to be understood, and understood very finely.

- Get the many Documents for STM32F4 from st.com

- Get whatever Documents and mikroC help from forum.mikroe.com

- Get Nextion documents in the Announcement section of Nextion Forum

    by following the links Nextion User Manual (updating) and

    by following the links Nextion FAQs


Nextion Instruction Set:

  Most of the iso-8859-x character sets define ÿ as 0xFF

  IF using iso-8859-1 in Nextion Editor HMI settings

  The nextion needs to receive over serial the characters t0.txt="4"ÿÿÿ


mikroC for ARM Help:

   UART3_Write_Text function says string must be zero terminated

   You will need to become familiar with your compiler requirements


STM32F4

   Has many settings for timing, pins, interrupts, buffers, registers

   You will need to become familiar with the ST documentation of MCU


The STM32 series MCU will not check for you

  - if the RX receive buffer is clear or has byte waiting

  - if the TX transmit buffer is clear and ready to send or is full with byte

YOU will need to check these conditions in your code


I do not believe the code for UART Library is available,

   so you do not know what has or has not been taken care of yet

mikro string handling is funky at best, I have many issues in pascal


No idea or way to tell if you have configured your registers properly


STM32 is very good chip, but many many details user must take care for.

- if this chip is too advanced and difficult, perhaps start with easier MCU

  - perhaps return to STM32F4 after basics has been understood.

Ali,


For the record, your code

          UART3_Write_Text("t0.txt=");

          UART3_Write(0x22);// " işareti

          UART3_Write_Text("4");

          UART3_Write(0x22); // " işareti

          UART3_Write(0xFF);

          UART3_Write(0xFF);

          UART3_Write(0xFF);


Appears that this would send the Nextion required format for t0.txt="4"ÿÿÿ to set t0.txt to display 4.


So you would need to check if these bytes are actually being transmitted from your STM32F4.

This could be accomplished with a logic analyzer.


There could be many issues in the MCU and way mikroC has configured your STM32F4 registers.

- this is beyond my scope to look for and troubleshoot such issues.

- is the voltage from STM32F4 sending on UART3 meeting required 3.3-5.0V?

- Many many issues to check and double check on your end and your duty.


Uart read code. This code run correctly.  But I dont send code from stm32f4


nextion send code is //0x65 0x00 0x02 0x00 0xFF 0xFF 0xFF

 

 I want to send code is t0.txt="123" from STM32F4  to nextion




  

// LCD bağlantıları tanımlanıyor
sbit LCD_RS at GPIOE_ODR.B8; // LCD E portunun 4,5,6,7,8,9,10
sbit LCD_EN at GPIOE_ODR.B10;
sbit LCD_D4 at GPIOE_ODR.B4;
sbit LCD_D5 at GPIOE_ODR.B5;
sbit LCD_D6 at GPIOE_ODR.B6;
sbit LCD_D7 at GPIOE_ODR.B7;
// LCD bağlantıları tanımlandı

 /*
bit                        1–bit        0 or 1
sbit                        1–bit        0 or 1
(unsigned) char                1        0 .. 255
signed char                1        - 128 .. 127
(signed) short (int)        1        - 128 .. 127
unsigned short (int)        1        0 .. 255
(signed) int                2        -32768 .. 32767
unsigned (int)                2        0 .. 65535
(signed) long (int)        4        -2147483648 .. 2147483647
unsigned long (int)        4        0 .. 4294967295
*/


long page,component;
char rx_buffer,rx_array[8]; // change value to adjust for buffer size
int i=0,j=0;
char txt[4];
 char dizi[]="a";
////////////////////////////////////////////////////////////
/*
   Burada hexadesimal sayının ekranda doğru görülebilmesi için yüksek değerli 4 biti alınıyor. Daha sonra karaktere dönüştürülüyor.
Mesela 0x65 sayısının 6’sı alınıyor 
ve daha sonra 48 ile toplanarak ‘6’ karakterine dönüştürülüyor. 
Fakat rakam 10 ve 10’dan büyükse yani A,B.C.D.E.F olursa 
55 ile toplanarak karaktere dönüştürülüyor. 
Karaktere dönüştürülmezse LCD’de farklı görünecektir. 



*/
 int short ascii2Hex(char ascii){
        int short hexValue;
        if (ascii>57) {
           hexValue = (ascii-55);
         }
        else {
           hexValue = (ascii-48);
         }
        return hexValue;
}



void hextostr(char eleman)
{
  char sol,sag;
  sol=(eleman>>4)&0x0F;
  if(sol>=10)
  {
   sol+=55;
  }
  else
    sol+=48;

    sag=eleman&0x0F;
  if(sag>=10)
  {
   sag+=55;
  }
  else
    sag+=48;
    txt[0]='0';
    txt[1]='x';
    txt[2]=sol;
    txt[3]=sag;
}
////////////////////////////////////////////////////////////

void main()
{
  GPIO_Digital_Output(&GPIOE_BASE, _GPIO_PINMASK_9); //R/W pini şaseye çekiliyor.
  GPIOE_ODR.B9=0;
  // UART ayarlamaları yapılıyor.
  UART3_Init_Advanced(115200, _UART_9_BIT_DATA, _UART_EVENPARITY, _UART_ONE_STOPBIT, &_GPIO_MODULE_USART3_PD89);
  // UART3_Init(9600);
  USART3_CR1bits.RXNEIE = 1; // enable uart rx interrupt
  NVIC_IntEnable(IVT_INT_USART3); // enable interrupt vector
  EnableInterrupts(); // enable core interrupts
  Lcd_Init(); //LCD kullanıma hazır hale getiriliyor.
  Lcd_Cmd(_LCD_CLEAR); //LCD ekran temizleniyor.

  while(1)// Endless loop
  {     //'t0.txt="Hello!"'
       //0x74 0x31 0x2E 0x74 0x78 0x74 0x3D 0x22 0x48 0x65 0x6C 0x6C 0x6F 0x21 0x22 0xFF 0xFF 0xFF

  // SAYFA NUMARASI GELECEK
      if(i==6)
        {
            USART3_CR1bits.RXNEIE = 0;
            hextostr(rx_array[2]);
            UART3_Write_Text("t0.txt=");
            UART3_Write(0x22);// " işareti
            UART3_Write_Text(dizi);
            UART3_Write(0x22); // " işareti
            UART3_Write(0xFF);
            UART3_Write(0xFF);
            UART3_Write(0xFF);
            Delay_ms(30);
            lcd_out(1,1,txt);
            if(rx_array[2]==0x02)
            {
            lcd_out(3,1,"tamam");
            }
            hextostr(rx_array[1]);
            lcd_out(2,1,txt);
            i=0;
            USART3_CR1bits.RXNEIE = 1;
        }



  }
}

///////////////////////////////////////////////////////////////////////////

void interrupt() iv IVT_INT_USART3 ics ICS_AUTO {
// Gelmesini beklediğim bilgi
//0x65 0x00 0x01 0x00 0xFF 0xFF 0xFF

  if(UART3_Data_Ready()&& i<=6) // If data is received
  {
    rx_array[i]=Uart3_Read();
    i++;

  }

}

  





USART3_CR1bits.RXNEIE = 0; hextostr(rx_array[2]); UART3_Write_Text("t0.txt="); UART3_Write(0x22);// " işareti UART3_Write_Text(dizi); UART3_Write(0x22); // " işareti UART3_Write(0xFF); UART3_Write(0xFF); UART3_Write(0xFF); Delay_ms(30);



I dont understand for my fail


Has someone played a joke on you?  Where did this code come from?

Is this school assignment with many mistakes you must identify and correct?


I am not sure what parts of the code actually work for real.


Where did you get UART setting from?

Ln 84: UART3_Init_Advanced(115200, _UART_9_BIT_DATA, _UART_EVENPARITY, _UART_ONE_STOPBIT, &_GPIO_MODULE_USART3_PD89);

WHY?  What made you think such settings should be correct?

- The Nextion ships with baudrate set to default 9600,

- Only if you changed Nextion baud setting to 115200 could this be correct.

- Higher baudrates need precision, many many factors that can cause error

   - work with 9600 first, then if fine - move upward.

   - when communications become unstable move downward

The MOST common UART setting is 8N1

  - 7E1 was common in Internet very very beginnings like in 1984

  - 9E1 super uncommon, very specific requirement of special cases

  - So I wonder why you thought 9E1 should be appropriate.


Programming has to be done with MUCH thought for LITTLE code

The STM32F4 MCU will follow your given instructions without questioning

 -- even if your instruction will result in STM32F4 dies.

Think of your MCU as naive little boy, it trusts you to not give death instruction

    so when you give it an instruction it assumes you tell it safely - and will do it

YOU must think what you are telling it to do

    this is why first steps is to always read and read and more read.


When you turn off the interrupt to receive, you already miss important bytes coming in

but UART byte being received in buffer will trigger interrupt every time

- interrupt should not be ignore bytes, buffer should be bigger.

Why did you pick that it stop storing bytes after 7 bytes received

 - many nextion scenarios will have more bytes than 7

Here you should read about circular buffer using head, tail, maybe.

Hardware interrupt routines should be as small as possible

  - and not to create more conditions that branch elsewhere.

Maybe this work for the first touch event, but you have set your code such to soon fail



Important to note that mikroC:

 - although I personally do not like the way used libraries are not mentioned in source code

 - although I personally do not like the string handling routines

 - although I personally dislike it making some decisions where it should not


mikroC is a powerful compiler, and with its debugging utility you can watch what happens.


The STM32F4 documentation needs to be consulted, beyond my scope, within yours.

If I am in error, I can accept I am in error.  Not my task to remember 700 pages every MCU.

Also not my task to dig in and know every compiler.


mikro interrupt assistant provides only one UART3 interrupt in Assistant

 - I am uncertain if this is poor implementation of UART Library or if STM32 UART module hardware is advanced such that Tx interrupt is handled transparently by the UART module once byte is in register.


IF ONLY Rx interrupt, routine should be sufficient to read byte and increment counter.

  - without Data_Ready Conditional Branch inside interrupt as interrupt only triggers on Rx

IF this is not the case as there are other conditions where UART3 interrupt can trigger, then the

  UART3 Library is poorly implemented by only providing a single interrupt in assistant.


void interrupt() iv IVT_INT_USART3 ics ICS_AUTO {

  rx_array[i]=Uart3_Read();

   i++;

}


Conditional Logic should not be placed inside an interrupt.

You must check STM32F4 documentation on UART module interrupts.


Nextion Data Termination delimiter is "ÿÿÿ" or hex 0xFF 0xFF 0xFF

therefore, condition that nextion return data is received is NOT i = 6, but if

  (rx_buffer[i-2] = 0xFF) && (rx_buffer[i-1] = 0xFF) && (rx_buffer[i] = 0xFF)


Data Transmission timing

- you must read up on serial communication timings

30ms is a lot of time in terms of 115200 baud - assuming 115200 is stable.

Using None,8,1 consumes 10 bits, so 11520 bytes per second.

 - 30ms is timing of 3456 bits or 345.6 bytes worth of a delay you requested.


STM hardware buffer in UART modules will be approximately 3 words or 12 bytes max,

but if we check the STM32 documentation, the register may be used for both one byte at a time.

This means one outgoing byte in the register and up to 2 bytes waiting to be sent.


This again brings into question if the UART Library in mikro is handling everything for you or not.

I have no reason to trust that it would be as the code is unavailable to view its source.

But when your code is instructing MCU to send data you certainly are not testing if TX is ready.

mikro provides TX test of UART3_Tx_Idle ...

   - so does it need to be used to ensure TX empty before sending your byte?

You will need to test - and testing is better at low speed to better see the results

- the lowest Nextion can be instructed to go down to is 2400 (Nextion Instruction Set baud/bauds)

After you stabilize your communication routines ... then increase speed.

 - you don't start learning to drive in Lamborghini at 350km/h


As I stated there are many many things in an STM32F4 that you will have to check for.

And don't forget that mikro has provided some examples even if limited.


But toggling your interrupt off ... did that also kill your TX

And as soon as one byte is lost by your STM32F4, you may not reach i=6 in meaningful manner.


ST Questions ... ST Forum
mikroC Questions .. mikroe Forum
Nextion Questions .. Nextion Forum


Good News:
You are most certainly not the first to use STM with a Nextion

- there is excellent chance that someone blog or YouTube about.

- Google STM32 and Nextion and you may find projects useful to your learning.


I will probably give up nextion project . 

Because It's useless. I did not find the right help.


Everyone gives reason but no solution

I bought two products and I will throw them away

The Nextion Help is the easier part of the project.

I answer questions usually within 12 hours


But be fair when you analyze, to yourself be true.

Your trouble is not with your Nextion,

Your trouble is with your MCU you have chosen



You are right. But My project go fail

Just for curiosity, what kind of project were you attempting?

One day ago, I actually downloaded ST documents for STM32F407VET6

- this was so I could check my assumptions when I give you answers


There are 11 interrupts conditions handled by STM, 3 for TX and 8 for RX

So, I have trouble that the mikro only gave one Interrupt routine in Assistant.

This means more reading, and more reading to find answers.


Programming Manual for STM32F407 - 260 Pages of details

Reference Manual for STM32F407 - 1748 Pages of details

Indeed much reading for the MCU you have chosen,

- but why throw away your Nextion because of your MCU?

Do you also throw away your house because of your meal?


Two Nextion Projects I made free here in the Forum

- Yahtzee dice game and a Piano, work in Nextion - No MCU.

You can download, compile for your model an and put on your Nextion.

All the Nextion code is there, you can see how it is done

You can visit the thread and see explaination of code pieces

This can help you learn Nextion side of programming.


But seriously, a project usually will use many many disciplines.

Are you so expert in them all?  Do you admit to yourself when you are not?

I am not an expert in all areas, I too have to ask others for help.

- They expect that I try first myself many times before I ask them.


I have to ask what you intended to actually make with your first project?


Did you know that you can buy a different MCU that may be easier to program?

Whom ever bought your STM32F4 invested good money for a BIG MCU

- But a lesser MCU under $10 USD can be programmed too - with Arduino.

These too will work with the Nextion, and your project could go ahead.

Many Nextion users use an ATMega2560 - lots of code help


But for all of this, many projects will require yet another part because you

didn't know, and this too will delay your project.  When you need $2 level

converter of $0.30 resisters - do you again throw your project way?





Dec 7, 2016 I purchased an STM32F407VET6 board.

It will not arrive for at least another two weeks.

I do know that my mikroPascal libraries are suppose to be able to be usable in mikroC and mikroBASIC.  I am new to this chip and board, so maybe I figure some out, and maybe not.  Maybe if I figure it out I will create a Nextion Library for the mikro compilers.  But I would only do this for myself - because I want to.  In order for me to share, I have to know I am to give it to someone who is trying to do on their side too.  Otherwise, is this not a waste of time?


Take a breath for now.


What size Nextion device do you have?

Download the HMI file at the end of the Yahtzee thread

http://support.iteadstudio.com/support/discussions/topics/11000008359


Learn a bit about the Nextion side logic for now, Have some fun

Then after a bit of fun we go back to your project.


You never answered what happened when you tried 9600 N81 on UART?

UART3_Init_Advanced(9600, _UART_8_BIT_DATA, _UART_NOPARITY, _UART_ONE_STOPBIT, &_GPIO_MODULE_USART3_PD89);




Login or Signup to post a comment