Content of the 2nd line extract sim900a

Submitted by saj on

hi,
I am using sim900a GSM MODEM and PIC 16F877A in XC8 at 20MHZ external.

I receiving the content in the following function from ,

char _SIM900_getch()   
{
    if(OERR) // check for Error 
    {
        CREN = 0; //If error -> Reset 
        CREN = 1; //If error -> Reset 
    }
    
    while(!RCIF);  // hold the program till RX buffer is free
    
    return RCREG; //receive the value and send it to main function
}

All the command are working correctly..But now expecting to extract 2nd line only (ie, sms content) of the reply of the command "AT+CMGR=1", and which is as reply,

"

+CMGR: "REC UNREAD" ,"+919844444444","10/10/14,14:29:33+04"
xxx123 (SMS CONTENT HERE IN THIS 2ND LINE)

Ok

"

My question is how do i jump to 2nd line and extract content of only SMS, to get compare with the function like //

if(strnicmp(content,"xxx123",6)==0)

for my further action.

Thanks in advance.

tnx

Since the content of the message willalways be in the 2nd line. You can simply use a for loop to read all the data from the Serial buffer and look for "/n" (ACSII value 13) when you receive this it means the message has reached 2nd line.

From there you can store whatever your read as a string and then use string compare just like you have done.

Hope this helps!!

  Joined May 19, 2015      213
Tuesday at 03:45 PM

hi

Tnx for your reply..

I am trying to get call when "AT" command responded with "OK" but the code below not entering into "placing call".
I do not understand what i am getting wrong....

 

 


char gsm_response[20];
//----------------------------------------------------------------------------------------

void _SIM900_print(unsigned const char *ptr) {
    while (*ptr != 0) {
        _SIM900_putch(*ptr++);                                              
    }
}

//--------------------------------------------------------------------------------------------------

//**Function to send one byte of data to UART**//
void _SIM900_putch(char bt)  
{
    while(!TXIF);  // hold the program till TX buffer is free
    TXREG = bt; //Load the transmitter buffer with the received value
}


//--------------------------------------------------------------------------------------------------

//**Function to get one byte of date from UART**//
char _SIM900_getch()   
{
    if(OERR) // check for Error 
    {
        CREN = 0; //If error -> Reset 
        CREN = 1; //If error -> Reset 
    }
    
    while(!RCIF);  // hold the program till RX buffer is free
    
    return RCREG; //receive the value and send it to main function
}

//-------------------------------------------------------------------------------------------------------
void gsm_read_line(char *buffer)
{
   unsigned char rec_data;
   
   // Read the data until Line Feed character is received.
   do {
      rec_data = _SIM900_getch();
      *buffer++ = rec_data;
   } while (rec_data != '\0');   
}   
 
//------------------------------------------------------------------------------------------------------------



void main(void)
{   
  
    //I/O Declarations//
    TRISD = 0x00;  //LCD pins on port D as output
   
       
    Lcd_Start();   //Initialize LCD 
    Initialize_SIM900();//lets get our Serial ready for action               
 
    
    Lcd_Set_Cursor(1,1);
    Lcd_Print_String("WELCOME");
    
    
 
/*Check if the SIM900 communication is successful*/
   
    _SIM900_print("AT\r\n");
    __delay_ms(1500);    

// Read the response.
    
    gsm_read_line(gsm_response);
   
// We should receive "OK" from the GSM modem.  // If we don't, display "Error".

    if (memcmp("OK", gsm_response, 2) != 0)
    {
      Lcd_Clear();
      Lcd_Set_Cursor(1,1);
      Lcd_Print_String("'AT' Error!!!");
      while(1);
    } 
    else if (memcmp("OK", gsm_response, 2)==0) // checking whether received string is OK and if OK then dial to ph no.  
                            {  
                                _SIM900_print("ATD0123456789;\r\n");  //Here we are placing a call to number 93643XXXXX
                                __delay_ms(1500); 
                                Lcd_Set_Cursor(2,1);
                                Lcd_Print_String("Placing Call....");
                                __delay_ms(1500);
                            }
     
   
while(1);    

}//main

 

 

Will you please point out my mistake please...
tnx

  Joined September 28, 2018      26
Friday at 01:20 AM