Retrieving UART data on LCD using PIC16F877A

Home Forums Microcontrollers PIC Microcontroller Retrieving UART data on LCD using PIC16F877A

Tagged: , ,

Viewing 14 posts - 16 through 29 (of 29 total)
  • Author
    Posts
  • #11060
    sandeep
    Participant

    Hi sir,

    my doubt is, will the +cmti response comes under the gsm echo feature? becoz, as i could read the message and display it on lcd using the AT+CMGR=1, why cant we do it replacing the CMGR with CNMI and wait for the +CMTI response to be displayed on the lcd, as in both the cases, the RCIF plays the main role.

     

     

    #11064
    sandeep
    Participant

    Hi sir,

    As i tried, code entering the loop only if the RCIF flag is raised,with below code, the code enters the loop, and the data from rcreg is transfered to an array(checked using led blinking),but as i tried to test the +CMTI format to check for the new messages,like in the  second part of code.but as soon as it receives a message the +cmti response must be send to the controller, i.e RCREG, but it is not happening.suggestions pls.

    I am not sure, whether the +CMTI response is sent to controller or not. and my other doubt is whether the +CMTI response comes under the ECHO feature, because i have disabled the echo feature, will it be a reason for this??

    while(!RCIF)
    {
      RB2=1;                     //LED, which keeps blinking, loop working good.
      delay(2000);
      RB2=0;
      delay(2000);
    
      for(i=0;i<10;i++)
      {
        x[i]=RCREG;
      }
    
      if(x[0]=='+'|| x[1]=='+'||x[2]=='+'||x[3]=='+')     //+CMTI: "SM",1
      {
        RB1=1;                                 // testing this like x[0]!='+', then it works, so array is working good.
        delay(2000);
        RB1=0;
        delay(2000);
      }
      else continue;
    }
    
    #11069
    Ligo George
    Keymaster

    Not, ECHO mode..

    You should turn on NEW Message Indications by using correct settings

    • AT+CMGF=1 – Text Mode
    • AT+CNMI=2,0,0,0,0
    #11086
    sandeep
    Participant

    Hi sir,

    code is concerned, i m trying to debug the code from the basics, the basic code is as shown below, I tried it with the led’s, like,
    if the format is correct then RB1 to blink or else RB3 to blink, but it is not happening.suggestions pls.

    void main()
    {
      //unsigned char data;
      TRISC = 0xC0;
      TRISB = 0x00;
      TRISD = 0x00;
      PORTC = 0x00;
      PORTD = 0x00;
      PORTB = 0x00;
    
      UART_Init();
      Lcd4_Init();
      delay(500);
      GIE = 1;
      PEIE = 1;
      char i,c;
      int j,k,l;
    
      delay(6000); //delay provided for the gsm to get signal stable.
    
      RCREG = 0;
      UART_Write_Text("AT+CMGF=1");
      UART_Write(0x0D);
      UART_Write(0x0A);
    
      UART_Write_Text("AT+CNMI=2,0,0,0,0"); // as suggested by u sir, but as per datasheet, it might be 2,1,0,0,0
      UART_Write(0x0D); // it remains same even after changing to AT+CNMI=2,1,0,0,0
      UART_Write(0x0A);
    
      while(RCIF) // checking data ready
      {
        for(i=0;i<=64;i++)
        {
          x[i]=UART_Read();
        }
    
        if(x[2]=='+'&& x[3]=='C')
        {
          RB1 = 1;
          lcd4_delayms(1000);
          RB1 = 0;
        }
        else if(x[2]!='+'&&x[3]!='C')
        {
          RB3 = 1; 
          lcd4_delayms(1000);
          RB3 = 0;
          RCREG=0;
        }
        continue;
      }
      i=0;
      x[i]=0;
    
      RCREG=0;
    
      delay(1000);
    }
    
    #11095
    Ligo George
    Keymaster

    You should check whether the data is ready or not… every time before calling UART_Read().

    #11477
    Guderz90
    Participant

    Hi, l am sending messages with a PIC but the AT commands are being included in the received text.

    A screenshot of the message has been attached.

    Thank you in advance.

    #11479
    Ligo George
    Keymaster

    Please post the code or AT command used to send this sms.

    #11497
    Guderz90
    Participant

    ok, here is the code:

    UART1_Write_Text("AT");
    UART1_Write(0X0D);
    Delay_ms(1000);
    UART1_Write_Text("ATE0");
    UART1_Write(0X0D);
    Delay_ms(1000);
    UART1_Write_Text("AT+CMGF=1");
    UART1_Write(0X0D);
    Delay_ms(1000);
    UART1_Write_Text("AT+CMGS=\"0772166326\"");
    UART1_Write(0X0D);
    UART1_Write_Text("Patient has fallen, provide assistance");
    UART1_Write(0X1A);
    UART1_Write(0X0D);
    Delay_ms(4000);
    
    #11499
    Ligo George
    Keymaster

    I can’t find any problems in the above code.

    What about the entire code ? Is it too lengthy ?

    Make sure that free RAM is above 30% otherwise it may cause such issues.

    #11506
    Guderz90
    Participant

    Thanks

    My RAM usage is 30% (70% is free). I used this copy2Ram method to reduce my RAM usage. Maybe it might be one of the causes.

    Below is the method I used and how the code would look like:

    const char UART_txt1[] = "AT";
    const char UART_txt2[] = "AT+CMGF=1";
    const char UART_txt3[] = "AT+CMGS=\"0772166326\"";
    const char UART_txt4[] = "Patient has fallen, provide assistance";
    
    //..................................................................................................................
    
    char * CopyConst2Ram(char * dest, const char * src)
    {
      char * d ;
      d = dest;
      for(;*dest++ = *src++;);
      return d;
    }
    //..................................................................................................................
    
    UART1_Write_Text(CopyConst2Ram(msg, UART_txt1));
    UART1_Write(0X0D);
    Delay_ms(1000);
    UART1_Write_Text(CopyConst2Ram(msg, UART_txt9));
    UART1_Write(0X0D);
    Delay_ms(1000);
    UART1_Write_Text(CopyConst2Ram(msg, UART_txt2));
    UART1_Write(0X0D);
    Delay_ms(1000);
    UART1_Write_Text(CopyConst2Ram(msg, UART_txt3));
    UART1_Write(0X0D);
    UART1_Write_Text(CopyConst2Ram(msg, UART_txt5));
    UART1_Write(0X1A);
    UART1_Write(0X0D);
    Delay_ms(4000);
    
    #11512
    Ligo George
    Keymaster

    Sorry I don’t understand your CopyConst2Ram(). You can use the following function for that.

    char* CopyConst2RAM(const char* ctxt)
    {
      static char temp[20];
      char i;
      for(i =0; temp[i] = ctxt[i]; i++);
      return txt;
    }
    
    #11515
    Guderz90
    Participant

    ok thanks. But would that be the cause for the problem?

    #11527
    Ligo George
    Keymaster

    Sorry, I can’t find any other problems.

    #11529
    Guderz90
    Participant

    ok, thanks very much

     

Viewing 14 posts - 16 through 29 (of 29 total)
  • You must be logged in to reply to this topic.
>