Problems with a Program to send a text message from PIC16 using GSM module

Status
Not open for further replies.

archanak2511

New Member
The program is intended to send "Hello" as an SMS to the specified number. Burnt the program into the PIC and set up the circuit using MAX232 and SIM300 gsm module. Did not get any message. Am pretty much sure that the hardware part is ok. I think the mistake ought to be with the program. I'm using PIC16F877A and Hi tech C compiler. I'm not very sure of the CONFIG bits and the #use line in the program. Please help me out by suggesting any possible corrections.


Code:
#include<htc.h>
#define _XTAL_FREQ 20000000
__CONFIG(0x37F2);
#use rs232 (baud = 9600, xmit=PIN_B0,rcv=PIN_B1,stream=GSM)


void transmit(unsigned char data);     
void transmitn(unsigned int numb); 

main()
{
TRISC=0b10000000;
SPBRG = 0x81;	 //Baud=9600 at 20 MHz
TXSTA = 0x24;	 
RCSTA = 0x90;


transmit("A");
transmit("T");
transmit("+");
transmit("C");
transmit("M");
transmit("G");
transmit("F");
transmit("=");
transmit("\"");

transmitn("9");
transmitn("8");
transmitn("4");
transmitn("6");
transmitn("0");
transmitn("5");
transmitn("1");
transmitn("2");
transmitn("5");
transmitn("6");
transmit("\"");
transmit("\n");
transmit("\r");

transmit("h");
transmit("e");
transmit("l");
transmit("l");
transmit("o");
transmit(0x1a);
}


void transmit(unsigned char data)
{
while(!TXIF);
TXREG = data;
}

void transmitn(unsigned int numb)
{
while(!TXIF);
TXREG = numb;
}
 
What pic pins are you using for Txd and Rxd?? I think that the line
Code:
#use rs232 (baud = 9600, xmit=PIN_B0,rcv=PIN_B1,stream=GSM)

is messing you up...

In C you put characters in single quotes ie.. transmit('A'); If you put it in double quotes.. C will append the string with a 0.

There is a serial example in C in my tutorials... The link in my signature.. tutorial 7_7..

There doesn't seem to be ANY difference between transmit() and transmitn()...
 


I figured out and corrected the mistake of using double quotes instead of single quotes and got rid of transmitn(). I've pasted my corrected code below. Still did not receive any text message. Pin 25 is being used for transmission and pin 26 for reception. I even tried omitting the #use line but it didn't help either.

Code:
#include<htc.h>
#define _XTAL_FREQ 20000000
__CONFIG(0x37F2);
#use rs232 (baud = 9600, xmit=PIN_B0,rcv=PIN_B1,stream=GSM)


void transmit(unsigned char data);      //for transmitting ascii characters

{
TRISC=0b10000000;
SPBRG = 0x81;	 //Baud=9600 at 20 MHz
TXSTA = 0x24;	 
RCSTA = 0x90;


transmit('A');
transmit('T');
transmit('+');
transmit('C');
transmit('M');
transmit('G');
transmit('F');
transmit('=');
transmit('\"');

transmit('9');
transmit('8');
transmit('4');
transmit('6');
transmit('0');
transmit('5');
transmit('1');
transmit('2');
transmit('5');
transmit('6');
transmit('\"');

transmit('\r');

transmit('h');
transmit('e');
transmit('l');
transmit('l');
transmit('o');
transmit(0x1a);
}


void transmit(unsigned char data)
{
while(!TXIF);
TXREG = data;
}
 
I think that you need to send
AT+CMGF=1
to get the GSM module into text mode.

Then you need to send
AT+CMGS=”+nnnnnnnnnnnn” (where nnnnnnnn is the number you want it sent to)

and when the GSM module replies with
>
you can send the message followed by a return.

I would suggest that you connect a terminal emulator to the module, so that you can type the commands by hand to check that they work. It is a good idea to have a test setup that allows the terminal emulator to see what the processor sends to the GSM module, and what the GSM module sends to the processor. That makes it much easier to see what is actually happening.
 

I included the AT+CMGF=1 command and corrected the AT+CMGS="phone number" command. I checked the output from the PIC using the software Docklight. The AT commands are being displayed on the terminal window perfectly which must mean the PIC is doing its part. But upon connecting with GSM through MAX232 there is no message received on the phone. Is there any way to check if the gsm module is actually receiving and responding to the commands sent by the pic?
 
I don't quite understand your setup. A diagram might help. Here are a few suggestions in no particular order.

You don't want a MAX232 to connect a PIC to the GSM module as both use the same voltage levels.

The output of the PIC should go to the RXD input of the GSM module. As that is an input, it shouldn't affect any voltages on it so you should be able to see the commands being sent from the PIC when the GSM module is connected.

If you put a 1 kΩ resistor between the PIC and the GSM module, you should get the same signal at both ends of the resistor. If not you have got two outputs fighting.

If you get the PIC to send once a second:-
OK[LF][CR]
(where [LF] is the line feed character and [CR] is carriage return)
then the GSM module will reply with

OK

Keep the baud rate low, say 4800 or 9600, at least to start with.

Some GSM modules are very fussy about how precise the timing of the serial data is.
 

So no need for MAX232? I'm using a SIM300 Gsm module. Actually I'm unsure if its a GSM module or modem. Read in a couple of forums that they're not the same. In my SIM300 unit, I can see a MAX232 IC at the in the PCB. How can I tell if mine is a module or modem? Does that change whether MAX232 is needed or not?
 
If there is a MAX232 in the device you are using, you might well need another in your application to convert the voltage back.

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