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 CCS Technical Support

SMS send problems
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jjacob



Joined: 08 Mar 2008
Posts: 54
Location: PORTUGAL (PORTO)

View user's profile Send private message

SMS send problems
PostPosted: Sat Aug 23, 2008 4:01 am     Reply with quote

Hi,

i'm having a strange problem while sending SMS using PIC18F452.
I've searched in the FORUM but i couldn't find out my problem.

I know that for sending SMS it's just :

Code:
printf("AT+CMGF=1);   //text mode
printf("AT+CMGS="+yyyyy"); //where +yyyyy is the destination number
putc(13);
printf("SMS text message....");
putc(26);


The strange thing is if i connect my circuit, with the above code, to Hyperterminal, i see all the text flowing.

If i connect to my modem (Siemmens TC35 or MC35i) nothing happens.
Not even the CMGF is changed. Before i connect the circuit, i force the value of CMGF to 0 (AT+CMGF=0) on the modem with Hyperterminal. In my code i force to 1, but nothing happens!!!

I also tested the connections, and i have PIN3(Tx) of DB9 to PIN8(R2in) of MAX232 and then to PIN26(Rx) of 18F452. For Rx i have PIN2(Rx) of DB9 to PIN7(T2out) of MAX232 and the to PIN25(Tx) of 18F452.

Is there any thing else that i must do ?? Or what am i doing wrong ?

Thank you...
Jacob
RayJones



Joined: 20 Aug 2008
Posts: 30
Location: Melbourne, Australia

View user's profile Send private message Visit poster's website

PostPosted: Sat Aug 23, 2008 4:11 am     Reply with quote

If you have done a copy paste onto the forum, you have several issues with quotes in your printf's.

First line is missing the closing quote, and will most likely include the printf as text to print.

The second line needs to have the number delimited using \"+yyyy\"

Finally, a \r or \n at the end of each string will make sure the modem accepts the AT command.

ie

Code:
printf("AT+CMGF=1\r");   //text mode
printf("AT+CMGS=\"+yyyyy\"\r"); //where +yyyyy is the destination number
putc(13);
printf("SMS text message....\r");
putc(26);


A disclaimer - I don't know the hayes commands you are using, but generally they would be the same rules on any modem.

Cheers, Ray
RayJones



Joined: 20 Aug 2008
Posts: 30
Location: Melbourne, Australia

View user's profile Send private message Visit poster's website

PostPosted: Sat Aug 23, 2008 4:20 am     Reply with quote

BTW, you can lose the puts(13).

That is identical to the printf("\r").
ie
\r is a Carriage Return = decimal 13 (^M)

\n is a Line Feed = decimal 10 (^J)
jjacob



Joined: 08 Mar 2008
Posts: 54
Location: PORTUGAL (PORTO)

View user's profile Send private message

PostPosted: Sat Aug 23, 2008 5:42 am     Reply with quote

Thank you Ray for your quick answer...

The quotes, it was a BAD copy/paste SORRY...
I follow your advice about the printf.
I compiled the code and loaded to PIC.

Still don't' work Sad

I've reduced the code (main()) to :

Code:
printf("AT+CMGF=1\r");


I force 'AT+CMGF=0' in Hyperterminal.
I power on the PIC.
I connect the Modem to my PC and query the modem about CMGF (AT+CMGF?) and returns 0 !!!

Sad Sad

With this 'complex' code, i think it should work...
Any suggestion ?? Anything ...

Thanks
Jacob
jjacob



Joined: 08 Mar 2008
Posts: 54
Location: PORTUGAL (PORTO)

View user's profile Send private message

PostPosted: Sat Aug 23, 2008 12:19 pm     Reply with quote

My PIC is a 18F452, the clock is 20MHz and Baud Rate is 9600. Is this a problem ? Must i low the clock to 4MHz ? The PIC is to quick for the modem ?
But they are with the same baud rate ...

I really can't find out an explanation for this simple code don't work.

Thank you ...
Jacob
RayJones



Joined: 20 Aug 2008
Posts: 30
Location: Melbourne, Australia

View user's profile Send private message Visit poster's website

PostPosted: Sat Aug 23, 2008 5:08 pm     Reply with quote

Hello Jacob,

My next best suggestions are:

1/ connect your PIC project so it's serial port communicates with the PC running Hyperterminal (ugggh Evil or Very Mad ) via a NULL MODEM CONNECTION.
If your PIC talks to the PC without the NULL MODEM, that is the answer, you must cross the Tx/Rx lines from the PIC!

2/ if you can scrounge or borrow an oscilloscope and monitor the serial data lines you will see if the serial data is coming from the PIC to start with.

3/ Do you have a RS232 driver of some form between the PIC and modem, eg a MAX232 device?
The most important important thing this does is to invert the signals, the voltages are somewhat secondary, but ideally you do also want the bipolar signalling.

4/ try a delay between the AT commands, perhaps the modem is not happy if you slam commands in too quick before waiting for the OK's back....

I've done far too much serial traffic coding in the past, and it still can trap me these days. #1 problem always being the cross up of Tx/Rx data.

If you can find a better terminal program than Hyperterminal to run on the PC you will find life is much better. I've used ZOC for a long time, particualrly because it also lets you do telnet over sockets as well as the serial port business.
There are also others equally more useful than Hyperterminal, which is simply a terrible program to deal with, it tries too hard to hide the low level serial port setup. You want full control when developing. Very Happy

Cheers, Ray
jjacob



Joined: 08 Mar 2008
Posts: 54
Location: PORTUGAL (PORTO)

View user's profile Send private message

PostPosted: Sat Aug 23, 2008 7:03 pm     Reply with quote

Thank you Ray ...

It's really strange this serial communication Very Happy

I will follow your advices... and as soon as i have some news i will write to the forum.

Thank you once again again for your help.
Jacob
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Sun Aug 24, 2008 7:44 pm     Reply with quote

Hi

your mobile phone work at baud rate 9600?

in my case I use samsung sgh2400 and I use this code for send sms:

Quote:

#use rs232(baud=19200, parity=N, xmit=PIN_C4, rcv=PIN_C5, bits=8, stream=tlmport)

fprintf(tlmport,"at\r");
delay_ms(500);
fprintf(tlmport,"at+cmgf=1\r");
delay_ms(500);
fprintf(tlmport,"at+cmgs=\"yyyyyyyyy\"\r");
delay_ms(500);
fprintf(tlmport,"text for send");
delay_ms(500);
fprintf(tlmport,"%c",0x1A);



and all work fine.

Attention I don't have max232, I only use one bc557 on TX line of mobile phone for up voltage for 5V TTL.

best regards
johanpret



Joined: 23 Oct 2006
Posts: 33
Location: South Africa

View user's profile Send private message Visit poster's website

PostPosted: Mon Aug 25, 2008 1:21 am     Reply with quote

When using a terminal there is a natural delay between the commands. If you issue the commands like u did then they fail. You need to wait for the response from the modem after the command was issued. You can either look at the received data from the modem and trigger the sending of the next command after receiving the response from the previous command or you can do it by using the delay between issueing commands like filjos indicated.

Hope it clear the issue.

Johan
_________________
Johan Pretorius
jjacob



Joined: 08 Mar 2008
Posts: 54
Location: PORTUGAL (PORTO)

View user's profile Send private message

PostPosted: Tue Aug 26, 2008 5:35 am     Reply with quote

Hi,

thank you all for your attention Very Happy

Ray, everything in your list was checked (even the new terminal... i'm using ZOC now!!).

filjoa, my modem is working 9600 and i've tested your code (changed to 9600) and didn't work.

Johan, i've tried to put delays ... but didn't work.

THIS IS VERY STRANGE.

MORE STRANGE is this :

Code:
#use rs232(stream=tlm, baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8, stop=1)
fprintf(tlm,"AT+CMGF=1\r");
delay_ms(500);
fprintf(tlm,"xx");


The above code, is as simple as it is. This is my main().

The output in 'ZOC' or in 'Hyperterminal' is :
Quote:
AT+CMGF=1

But the cursor stands below the A. Where is the 'xxx' that i want to print ?

So i test this code :
Code:

#use rs232(stream=tlm, baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8, stop=1)
fprintf(tlm,"AT+CMGF=1\r");
delay_ms(500);
fprintf(tlm,"xx");
fprintf(tlm,"yy");


Now the output is :
Quote:
xx+CMGF=1


So, my system prints the 'AT+CMGF=1' then execute the '\r' (CR) and then writes the 'xx' and leaves the cursor below '+'.
Once again, where is the 'yy' that i send it to write ?

Why it doesn't write to serial port the last line ? Is because is the last line of code ? ??? My program is just the lines above and then ends...

Any sugestion ?
Thank you for your attention.
Jacob
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Tue Aug 26, 2008 12:25 pm     Reply with quote

Hi

you can write there what commands you write on terminal for send an SMS?

when I put "fprintf(tlm,"AT+CMGF=1\r");" is for mobile phone send sms in text mode.

regards
jjacob



Joined: 08 Mar 2008
Posts: 54
Location: PORTUGAL (PORTO)

View user's profile Send private message

PostPosted: Tue Aug 26, 2008 12:36 pm     Reply with quote

OK.

That was just a test to the PIC.
But it didn'change the status of '+CMGF' (to send SMS in text mode) and my question is : Why the last line of my code wasn't executed ?

I would like to understand this...
Can anybody explain that ?

Thank you
Jacob
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 26, 2008 12:45 pm     Reply with quote

Quote:

Why it doesn't write to serial port the last line ? Is because is the last line of code ? My program is just the lines above and then ends.

You are only posting code fragments. If you posted a complete test
program, I suspect that it would look like this:
Code:
#include <18F452.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(stream=tlm, baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8, stop=1)

void main()
{
fprintf(tlm,"AT+CMGF=1\r");
delay_ms(500);
fprintf(tlm,"xx");
fprintf(tlm,"yy");
}

The reason why this program fails to print the last two characters is
because you are letting it fall off the end of main().

Compile the program. Look at the .LST file. What do you see at the
end of the file?
Quote:
.................... fprintf(tlm,"yy");
009C: MOVLW 79
009E: BTFSS PIR1.TXIF
00A0: BRA 009E
00A2: MOVWF TXREG
00A4: MOVLW 79
00A6: BTFSS PIR1.TXIF
00A8: BRA 00A6
00AA: MOVWF TXREG
....................
.................... }
00AC: SLEEP

The compiler inserts a SLEEP instruction at the end of main().
The hardware UART will be in the process of sending the last two
characters when it hits the SLEEP instruction. At that point, the PIC's
oscillator is shut down. The UART doesn't have an internal clock
anymore. It can't send the last two characters.

The solution is to prevent it from hitting the SLEEP instruction by
putting a continuous loop at the end of main(), as shown below.
Quote:
void main()
{
fprintf(tlm,"AT+CMGF=1\r");
delay_ms(500);
fprintf(tlm,"xx");
fprintf(tlm,"yy");

while(1);
}

Do this in all your programs.
jjacob



Joined: 08 Mar 2008
Posts: 54
Location: PORTUGAL (PORTO)

View user's profile Send private message

PostPosted: Tue Aug 26, 2008 3:46 pm     Reply with quote

Thank you PCM programmer.

My code was exactly as you suspected Smile

Your explanation was perfect. Now i understand why my code was not working.

Thank you and thank you for your advice about writing code.
Jacob
jjacob



Joined: 08 Mar 2008
Posts: 54
Location: PORTUGAL (PORTO)

View user's profile Send private message

PostPosted: Tue Aug 26, 2008 4:22 pm     Reply with quote

Thank you all.

Now i can send SMS using PIC Very Happy
After i few adjusts in software it's working.

The only thing that i really changed in the code was the last line for sending SMS :

Code:
printf("%04Ld%c", data[i+12], 0x1A);


where 'data[i+12]' is an array with the data that i want to send. It's inside a 'for' cycle.
If i print like this :

Code:
printf("%04Ld", data[i+12]);
printf("%c",0x1A);


It wouldn't work.

I suspect that 'printf' sends some extra code. The last thing that can me send to the modem is ^Z. If a CR or any 'strange' ascii code is send before ^Z, the SMS will not be send.

Jacob
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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