Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

2nd line content extract SIM900A

Status
Not open for further replies.

saramah

Member level 3
Member level 3
Joined
Apr 25, 2018
Messages
64
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
689
hi,
I am using sim900a GSM MODEM and PIC 16F877A in XC8 at 20MHZ external.

I receiving the content in the following function from ,

Code:
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,


Code:
+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 //
Code:
if(strnicmp(content,"xxx123",6)==0)
for further action


Thanks in advance.

tnx
 

Hi,

search through the text and find the "linefeed" chracter

Klaus
 

Will you check below for,
LCD is displying upto

Code:
        Lcd_Set_Cursor(1,1);
        Lcd_Print_String("Waiting For SMS.....   ");
        
        while(SIM900_waitResponse() != SIM900_NEWSMS);//wait till new SMS is come
        
        Lcd_Set_Cursor(1,1);
        Lcd_Print_String("NEW SMS ARRIVED !!!.");
        __delay_ms(1000);


Till above all are going correctly. To read 1st index, what i HAVE written,


SIM900_print("AT+CMGR=1\r\n");
Lcd_Clear();
Lcd_Set_Cursor(1,1);
Lcd_Print_String("Reading SMS..... "); // lcd correctly showing this also.
__delay_ms(1000);

Now for 2 nd line to read the sms content, what i have written,


unsigned char abc;
unsigned char msg1 [90];
unsigned char *temp;

msg1[abc]=_SIM900_getch();
abc++;
read_text(msg1);
if(strnicmp(temp,"abc",3)== 0) // If content sent from mobile (content like "abc" ) is matched, then enter below loop,


{
SIM900_print("ATDxxxxxxxxxx;\r\n"); //Here we are placing a call to number XXXXXXXXXX
Lcd_Clear();
Lcd_Set_Cursor(1,1);
Lcd_Print_String("Placing Call....");
__delay_ms(1500);


}

here read_text function is defining as below....

void read_text( unsigned char *msg)
{


temp=msg;

do
msg++;
while(*msg!='\n');
msg++;

do
*temp++=*msg++;
while(*msg!='\r'); // reaching at end of message


}

will u please suggect why it is entering under //if(strnicmp(temp,"abc",3)== 0) and not callind //ATDXXXXXXX.

Pl suggect.
tnx

- - - Updated - - -

correction!! 3rd last line,,

will u please suggect why it is NOT entering under //if(strnicmp(temp,"abc",3)== 0) and not calling //ATDXXXXXXX.

will u please suggect why it is entering under //if(strnicmp(temp,"abc",3)== 0) and not callind //ATDXXXXXXX.

tnx
 

will u plaese precisely specify once
tnx
 

But now expecting to extract 2nd line only (ie, sms content) of the reply of the command "AT+CMGR=1"

By enabling Echo (e.g ATE1), you can take all incoming characters after AT+CMGR=1 echoed strings and split them according to your logic.
 

COULD U please specify that the problems for above mentioned code. why not working.
 

SIM900A content extract into ARRAY and process its

HI,
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....



Code:
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
 

Re: SIM900A content extract into ARRAY and process its

Apart from your coding style, doing the job in a straight line without splitting the program into functional parts, it should be clear that the above code will run once, and then will be trapped at the last instruction:

Code:
while(1);
 

yes, but i must have get the call once before trapped in while(1).
so why not getting call..
is there need to be changed??
 

Only you have the means to debug your own program.
Do the job step by step and then check at which command things do not happens as expected.
Use any LED or the LCD as an indicator that some part of the code was (not) reached.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top