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)

Sorry Ali, I missed you were responding to Gokhan

Thanks Patrick i will try it and i will write here again. 

Dear Ali 

 I tried your codes and i changed my Mhz but i doesnt work. I wrote comment to your github project and i wrote my communication adress which is mahmutgokhan@hotmail.com . 

You must rearrange your code for your projects.  C does nothing for mine.

So the code you presented appears to properly setup a UART3 with rx Interrupt enabled.

The RX interrupt will receive up to 20 bytes and put them into your non existent rx_array

The sendCommand function will accept a char array up to 19 chars + null termination

 and push this across your TX terminating with the required 3 byte Nextion 0xFF 0xFF 0xFF.




You must use interrupt for reading nextion command.


I send example code you should arrange my code for your project

 

  void sendCommand(char cmd[20])
 {
    int x=0;


  while(cmd[x] != '\0')
  {
     UART3_Write(cmd[x]);
      x++;
   }
    //UART3_Write_Text(cmd);
    UART3_Write(0xFF);
    UART3_Write(0xFF);
    UART3_Write(0xFF);
    x=0;

 }

 


read 


 

void main()
{
  UART3_Init_Advanced(9600, _UART_8_BIT_DATA, _UART_NOPARITY, _UART_ONE_STOPBIT,
    &_GPIO_MODULE_USART3_PD89);
    Delay_ms(200);
    EnableInterrupts(); // enable core interrupts
    USART3_CR1bits.RXNEIE = 1; // enable uart rx interrupt
    NVIC_IntEnable(IVT_INT_USART3); // enable interrupt vector
    Delay_ms(30);


}


void interrupt_usart3() iv IVT_INT_USART3 ics ICS_AUTO
{

  //Gelmesini beklediğim bilgi
  //0x65 0x00 0x01 0x00 0xFF 0xFF 0xFF
  //0X65+Page ID+Component ID+TouchEvent+End
  
   
  if(UART3_Data_Ready()&& i<=20) // If data is received
  {
    rx_array[i]=Uart3_Read();  //nextion response value
    i++;
  }
  

}

 



example project


https://github.com/alidurmus/nextion_stm32f4_mikroc/blob/master/examples/number/mikroc/nexnumber/nexnumber.c


I must respectfully decline in sending my projects.

My hardware is STM32F407VG Discovery

rar
(71.9 KB)

can you send your project?

1. create new mikroc project

select correct device and

   device clock 140 Mhz


click "next"

click "next"

select "include All"

select "Finish"


select menu "Project" and "Project Edit"



select right menu "Load Scheme"


select "STM32F407VG_PLL_Int_Osc_16MHz_to_140MHz.cfgsch"


after select "ok"

Gokhan


The bytes you are sending in the first for loop

   equates to a partial assignment t2.txt=  But equals what?

   - This must be minimally a complete assignment and data terminated

   - This surely will not have any purpose as is.


The bytes you are sending in the second for loop

   equates to a Nextion Return Code for a Touch release event

   specifically a return of the component with .id 1 on page 0 was released.

   - This is more an example if what Nextion sends back after .id 1 is released

      but only if Send Component ID was checked in that components touch release event.

   - Sending this back to the Nextion will have no purpose - it is not a Nextion Instruction.


These you loop to continuously send every 5 seconds until you kill the power.


If this is not your intention, then you must instruct the F407 MCU to do as you intend

For the SSTM32F407 there is much reading for you to do

 ST - Reference Manual, Programming Manual

 mikroe - for MikroC Pro for ARM

 ?? - General understanding of programming language, mikro or other.

 Nextion - Instruction Set, Quick Start Guide, Examples.


With the code Above, I will assume that the F407 will do exactly as instructed

But it looks to have no purpose or reason to do so in such a way.


Check with logic analyzer - it most likely IS sending requested 14 chars

then waiting 5 seconds and repeating.


But if those 14 chars are destined for Nextion, they are meaningless.

Sorry for deleting your last comment - the board must be run in English


Hi, 

 I can't write(uart) data to nextion with Stm32f407. I can read but i can't read. I don't know why. This is my code. It's so easy but i can't write anything.     

char uart[8]={0x71,0x5f,0x00,0x00,0x00,0xff,0xff,0xff};
char uart1[7]={0x65,0x00,0x01,0x00,0xff,0xff,0xff};   //butona basılınca gelen değer.
char txt1[7]={0x6e,0x30,0x2e,0x76,0x61,0x6c,0x3d};   //n0.val=
char txt0[7]={0x74,0x32,0x2e,0x74,0x78,0x74,0x3d};   //t2.txt=
int i;
void main() {
UART1_Init_Advanced(9600,_UART_8_BIT_DATA, _UART_NOPARITY, _UART_ONE_STOPBIT, &_GPIO_MODULE_USART1_PB67); // UART1 PB6(TX) ve PB7[RX] pinleri için 9600 baudrate ayarında başlatıldı.
while(1) {
   for(i=0;i<7;i++)
      UART1_Write(txt0[i]);
  for(i=1;i<7;i++) 
      UART1_Write(uart1[i]);

      delay_ms(5000);

}}

    and this is my nextion file. 

HMI
(235 KB)

I work on stm32f4 and nextion number example 


I share this link


https://github.com/alidurmus/nextion_stm32f4_mikroc




Login or Signup to post a comment