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.

Why is this code not working ???

Status
Not open for further replies.

motofreek

Junior Member level 2
Joined
Dec 12, 2009
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,450
Hi, I doing a PIC to GSM project to send SMS. I'm ok up to the point where the GSM phone is expecting CTRL-Z to terminate the PDU but its not working. Here's my code...

printf("AT+CMGS=20\n\r");// this is working
delay_ms(1000);
puts("~~~~pdu~~~"); // this is working
delay_ms(1000);
printf("%d",26); //I'm trying to get CTRL-Z here....this is NOT WORKING !!!

I've also tried putc(26) and putc(0x1A) but I cant get it to send CTRL-Z. Doesn't work!
I know the hex value for CTRL-Z is "1A"...
 

The correct printf format for a character is of course %c rather than %d, but putc should work as well, so there's possibly a different problem.

Basically, you should wait for a the ">" modem answer after sending the CMGS command.
 

Yes, the modem gives me the ">" . I then wait 1 second to send pdu. I see exactly what's happening because I monitor it on the Serial Monitor Window in CCS. But when it's time for the put(26) to go through, nothing happens and the message isn't sent.

Added after 3 minutes:

Also I used "%d" in an effort to send the Decimal value of "1A" which is = 26.
 

Show the real data, that you are sending, not placeholders like "~~~~pdu~~~" or %d formatted strings. If you doing everything correct, it's supposed to work.
 

void main() {
delay_ms(2000);
printf("AT+CMGS=20\n\r");// this is working
delay_ms(3000);
printf("07918186860820F411000791744201F10000AA09C82293F96C281A0A"); // this is working
delay_ms(2000);
putc(26);// I'm trying to get CTRL-Z here....this is NOT WORKING !!!
}

Added after 49 minutes:

I think the problem lies in the printf statement containing the pdu. That line ends in "0A" which is an LF. The modem however, probably doesn't expect this...It expects "1A" which is ctrl+z. I need to get rid of that 0A
 

motofreek said:
printf("AT+CMGS=20\n\r");// this is working

I think the problem lies in the printf statement containing the pdu. That line ends in "0A" which is an LF. The modem however, probably doesn't expect this...It expects "1A" which is ctrl+z. I need to get rid of that 0A

Try the following:
printf("AT+CMGS=28\n\r");// this is working

Most modems check this number (should be your resulting message lenght in octects).

You do not need to care for the OA in your message as this is an ASCII code and not a control code.

I hope this solves your problem.

best regards
 

Most modems check this number (should be your resulting message lenght in octects).
28 isn't correct, <length> given with CMGS in PDU mode is the message length in octets without the SC address field also included in <pdu>

The SC address field consists of a length code of 07 and 7 octets, so above given length of 20 is correct.

P.S.: What do you exactly mean with "not working", there should be an error message.
 

[To FvM] thanks for showing interest.

When I say not working, I mean after the printf line containing the pdu is executed the cursor just remains there and nothing happens. Eventually, when the modem doesn't recieve the ctrl+z it's looking for, an "ERROR" comes up (just the word ERROR). I know it's coming up because the modem isn't seeing the termination signal, ctrl+z.

Even when I look back at the hex code in the serial monitor window of ccs I don't see "1A" even though the last line of my c program is putc(26).

Added after 2 minutes:

I was wondering if there's something wrong with using putc(26) ? Is there something else I can use ?
 

Is there anything else I can try instead of putc(26) ?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top