CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problem in sending SMS using SIM300 and PIC18F452

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
amit78



Joined: 17 Jul 2009
Posts: 21
Location: Kolkata, India

View user's profile Send private message

Problem in sending SMS using SIM300 and PIC18F452
PostPosted: Mon Jun 04, 2012 8:14 am     Reply with quote

Hi all

I am trying to connect a GSM Modem (SIM300) to send SMS using PIC18F452.
1. While I am connecting SIM 300 module with PC HyperTrm its working file with the At commands. Using AT+CMGS, I can send SMS too.
2. Now while I wrote the following code using the PIC18F452, nothing is happening.
Code:

#include <18F452.h>
#FUSES HS, NOWDT, NOPUT, NOPROTECT, NODEBUG, BROWNOUT, NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8, stream=GSM, ERRORS)

#include <stdio.h>

void main()
{
    char s = 26; //0x1A;
    char b = 34;

    fprintf(GSM, "AT\r");
    delay_ms(900);
    fprintf(GSM, "ATE0\r");
    delay_ms(900);
    fprintf(GSM, "AT+CMGF=1\r");
    delay_ms(900);
    fprintf(GSM, "AT+CMGS=%c9674170493%c\r", b, b);
    delay_ms(3000);
    fprintf(GSM, "hello FROM mcu%c", s);
    while(1)
    {
        delay_ms(1000);
    }
}



I have connected both with a RS232 cross cable. Note: only three pins are used: Pin 5(GND), Pin2(Rx) and Pin3(Tx).


3. Interesting thing is, while connecting this PIC board with my PC HyperTerm with 9600 baud, I am getting the strings in the Hypertrm. So I hope the Serial connection is OK.

4. I am using the following connection:
PIC->Max232-> || Max232->SIM300


Any Suggestion?
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Jun 04, 2012 8:34 am     Reply with quote

Make sure to disable Flow control on the Module when using 3 wires.

What is this
Code:
Char b = 34;

Try this better
Code:
Char b = 0x22;
its clearer Hex 0x22 = "
(i know its the same... IMO i thing its better to keep things in hex)

try swapping your tx/rx lines between your MAX 232 chips...
Sound dumb but who is who ( DTE / DCE ) sometimes gets confusing.
Swapping the lines usually gets rid of my problems.


Before trying to go directly to sending an SMS... code a small programm that detects if when you send AT you get OK back...
then move on.

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
amit78



Joined: 17 Jul 2009
Posts: 21
Location: Kolkata, India

View user's profile Send private message

PostPosted: Mon Jun 04, 2012 11:25 pm     Reply with quote

Very Happy Very Happy Very Happy

Yes Gabriel, you were right. Just swapping the rx/tx solves the problem. But I am not convinced. Because now it is a straight cable, not cross cable.

[PIC=>MAX232] Rx----> Rx [MAX232=>SIM300]
[PIC=>MAX232] Tx----> Tx [MAX232=>SIM300]


Any way I am getting the SMS.

Surely I will maintain the norms to write things in hex. So, from now I will use:
Code:

Char b = 0x22;


Thanks dude.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Jun 05, 2012 2:02 am     Reply with quote

amit78 wrote:
Yes Gabriel, you were right. Just swapping the rx/tx solves the problem. But I am not convinced. Because now it is a straight cable, not cross cable.

[PIC=>MAX232] Rx----> Rx [MAX232=>SIM300]
[PIC=>MAX232] Tx----> Tx [MAX232=>SIM300]
In the RS232 standard two types of devices are devined: DTE and DCE. DTE is short for Data Terminal Equipment; a device that converts user information into signals or reconverts received signals. Examples are computer, printer or terminal.
DCE stands for Data Communications Equipment and is the device sitting in between the DTE and the physical communication wire, i.e. your modem.

The DCE and the DTE are always connected with a straight cable. If you want to connect to DTE devices together this requires crossing the receive and transmit wires, a so called null modem or crossover cable.

Now your confusion comes from the standard definitions that say the signals are named from a DTE point of view. The Tx output on the DTE (computer) is connected to the Tx input on the DCE (modem). The name of the signal is the same on both sides, but what is an output on one side is connected to the same named input on the other side.

More info: http://www.bb-elec.com/bb-elec/literature/tech/faq_rs232_connections_work.pdf
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Jun 05, 2012 2:17 am     Reply with quote

amit78 wrote:
Surely I will maintain the norms to write things in hex. So, from now I will use:
Code:

Char b = 0x22;
Using hex, decimal, binary or ASCII is a matter of personal preference. I myself like to write ASCII when I want to define a specific character.
Code:
char b= 'a';

But to avoid confusion I probably wouldn't write
Code:
a = '"';
and use instead:
Code:
a = 0x22;
And when specifying the I/O bits in a TRIS register I use binary:
Code:
TRIS_A = 0b00110011;


Just use the notation that best fits the job. But what I don't like is your construct:
Code:
char s = 26; //0x1A;
If you have to add comments to explain the hex-value then you are doing something wrong and should have coded the hex value immediately:
Code:
char s = 0x1A;
amit78



Joined: 17 Jul 2009
Posts: 21
Location: Kolkata, India

View user's profile Send private message

PostPosted: Tue Jun 05, 2012 6:26 am     Reply with quote

Thanks Ckielstra for your valuable comment. I will surely keep these in my mind.

Amit
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Jun 05, 2012 7:00 am     Reply with quote

Hi All,

Everyone seems to be missing an important point with this discussion. When you send the CMGS command, you need to enclose the phone number inside of quotation marks. You can do that right inside your fprintf statement directly by preceding the quotation marks with an escape character '\'. Do it like this, and get rid the the silly way you are doing it now.

Code:

fprintf(GSM, "AT+CMGS=\"5085551212\"\r");


John
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Tue Jun 05, 2012 8:01 am     Reply with quote

@ezflyr: Right on! . . . indeed that was the key issue
_________________
CCS PCM 5.078 & CCS PCH 5.093
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group