Read string from uart

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Read string from uart

1,926件の閲覧回数
kanimozhiraju
Contributor I

Hi @ kerry,
         with uart receive interrupt i try to read string and compare the string with constant string and process further.But i sent data from app and i received .I am not getting the data when i sent once i have to send 3 times to receive the printf statement .i will attach my code now

/* * File:  receiving data from app * Purpose:  Main * */

#include "common.h"#include "isr.h"

char data[10]="MEASR_TEMP;char testdata[10];char rec[10];uint8 s_flag=0;uint8 i=0;

void UART1_isr(void){  if (UART1_S1&UART_S1_RDRF_MASK)  {    while(i<10)    {    testdata[i] = UART1_D;    i++;    }   // printf("%c",testdata);  }   strncpy(rec,testdata,10);  if((strncmp(rec,data,10)==0))  {    uint8 s_flag=1;  }}

void main (void){   printf("kiosk implementation\n");   UART1_C2 |= UART_C2_RIE_MASK ;  // UART1_D=testdata;   enable_irq(47);   while(1)   {     if(s_flag==1)     {       printf("spo2");       printf("level:\n");     }   } }

ラベル(1)
0 件の賞賛
返信
4 返答(返信)

1,560件の閲覧回数
kanimozhiraju
Contributor I

kerryzhou

                      I have tried tat code.when i give data,uart isr is not at all getting activated.

0 件の賞賛
返信

1,560件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

Hi kanimozhi Raju,

   I just simply modify your code, give you the process method.

  Did your own code can enter receive uart isr before?


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛
返信

1,560件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

Hello kanimozhi Raju,

   Thank you for your cooperation.

   Your code is wrong, you can't write the UART1_isr like that.

  Actually, after you enable the receive interrupt, then when the mcu received one byte, it will enter in the UART1_isr one times, the next byte data  will caused the next ISR, you can't use the while() in the ISR, you must exit the interrupt handler to wait the next the byte coming.

I have modified your code like this:

#include "common.h"#include "isr.h"

char data[10]="MEASR_TEMP;
char testdata[10];
char rec[10];
uint8 s_flag=0;
volatile uint8 i=0;

void UART1_isr(void)
{  
  if (UART1_S1&UART_S1_RDRF_MASK)  
  {    
     testdata[i++] = UART1_D;
  }   
 
}

  void main (void)
  {   
    printf("kiosk implementation\n");   
    UART1_C2 |= UART_C2_RIE_MASK ;  
    // UART1_D=testdata;   
    enable_irq(47);   
    while(1)   
    {
      if(i>=10)
      {   
        strncpy(rec,testdata,10);
        printf("spo2");       
        printf("level:\n");   
        i=0;
        s_flag=1;
       }     
 
    }
}

Wish it helps you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛
返信

1,560件の閲覧回数
kanimozhiraju
Contributor I

  I have tried tat code.when i give data,uart isr is not at all getting activated.

0 件の賞賛
返信