[PIC] Unable to read SMS and turn on device

Status
Not open for further replies.

ericparggah

Newbie level 5
Joined
Oct 18, 2008
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,352
Hello All,
I am working on a GSM based device control system based on the PIC16F876 and a SIM900 module from Rhydozlabs. The compiler i am using is the FED WIZ-C version 17.02.
I need to be able to control 4 devices but in the meant time just trying to make sure one works before i tackle the rest. The problem is that I want to turn on port RB4 using the command: TV ON with the code as shown below:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void UserLoop()
{   
    if(RxFlag)
    {
        ReadGsmLine(&GsmResponse);
        if(memcmp("+CMTI: \"SM\",", &GsmResponse, 12) == 0)
        {
            ReadSmsCommand[8] = GsmResponse[12];
            DeleteSmsCommand[8] = GsmResponse[12];
            SendGsmCommand(&ReadSmsCommand);
            Wait(1000);
            ReadGsmLine(&GsmResponse); //Read modem response
            ReadGsmLine(&ControlInstruction); // Read Instruction
            ReadGsmLine(&GsmResponse); //Read modem response
            ReadGsmLine(&GsmResponse); //Read modem response OK
            
                        if(memcmp("TV ON", &ControlInstruction, 5) == 0) // ------(Remove)
            {
                Device_A = ON;
            }
            SendGsmCommand(&DeleteSmsCommand);
                        Wait(1000);
            ReadGsmLine(&GsmResponse);//Read OK
        }
    }
}



When I comment out the line:


Code C - [expand]
1
if(memcmp("TV ON", &ControlInstruction, 5) == 0) // ------(Remove)



then the Device_A turns on. Without commenting out that line then it doesn't turn on. I need to use that line to test the various command strings for the four different devices.

Any help will be most appreciated.

Thanks in advance.
 
Last edited by a moderator:

You'll want to check which answers are actually received from the modem and why the comparison fails. This can be either done by operating the PIC16 under an in-circuit debugger or by sniffing the serial interface between processor and modem with dual channel RS232 interface and a suitable tool, e.g. docklight.
 

I have already done that with tools like proteus and Hterm. I see the communication between the uC and the modem. However there are some blank spaces in the responses from the modem and I don't know how to handle such responses. Any help will be very much appreciated.
Thanks a lot FvM for the swift reply to my problem.
 

In other words, you are stumbling upon wrong assumptions about the format of the modem response.

I presume that the SMS content itself is transmitted correctly. The problem is about the format of the "ReadSMS" (AT+CMGR) response. The correct solution is decode the response according to the at commands specification. At places where a variable number of blanks or other format variations can occur, you should be prepared for it. Instead of expecting the answer at a fixed string position, decode the delimiters.
 

Hi,
These are the read and send functions that I am using:

Code C - [expand]
1
2
3
4
5
6
7
8
9
void ReadGsmLine (char *Buffer)
{
   unsigned char receivedData;
   do
   {
       receivedData = WaitRx ();// WaitRx() for serial 
       *Buffer++ = receivedData;
   }while (receivedData != '\n');
}

 
Last edited by a moderator:

Hi,
These are the read and send functions that I am using:

This is the USART read function that i am using:


Code C - [expand]
1
2
3
4
5
6
7
8
9
void ReadGsmLine (char *Buffer)
{
   unsigned char receivedData;
   do
   {
       receivedData = WaitRx ();// WaitRx() for serial 
       *Buffer++ = receivedData;
   }while (receivedData != '\n');
}



When I used the Hterms to sniff the responses from the GSM modem, I then noticed that all the responses are sandwiched by the <CR><LF><Response><CR><LF> delimiters. I really need help on decoding the delimiters.
Any help please will be very much appreciated.
Thanks in advance.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…