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

I need help with my thesis project

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



Joined: 23 Dec 2009
Posts: 6

View user's profile Send private message

I need help with my thesis project
PostPosted: Thu Sep 02, 2010 9:41 am     Reply with quote

Hi all, my name is Kostas and I'm facing a problem with my thesis and I need help about solving it.

Well the problem that I'm facing has to do with the communication of a pic microcontroller ( 16f628 ) and a gsm modem (Siemens T35i terminal). I can't send or receive commands between those two devices.

For example, I'm trying to send the "AT" command to the modem with a program that I wrote for the microcontroller. The whole idea for the program is to send this command and to receive and read the "OK" response and if it is the right response, light up a led or for everything else, light up another.

The program was made with CCS compiler:

Code:
#include <16F628.h>
#include <string.h>
#fuses XT,NOWDT,PUT,NOBROWNOUT,NOMCLR,NOLVP,INTRC_IO
#use delay(clock=4000000)
#byte PORTB = 0x06
#byte PORTA = 0x05

#use rs232(baud=9600,xmit=PIN_B2,rcv=PIN_B1)

unsigned char cmd_at[]="AT";
unsigned char answer[2];
unsigned char aok[]="OK";
int i;
int p;
void main(void) {

   set_tris_a(0x00); //Set PortA as OUTput

   delay_ms(7000);

   for (i=0; i<sizeof(cmd_at); i++){

      putc(cmd_at[i]);

   }
   putc(13);

   delay_ms(100);
   gets(answer);
   p=strcmp(answer, aok);

   if (p=0){

      output_high(PIN_A0);
      delay_ms(5000);

   }
   else{

      output_high(PIN_A1);
      delay_ms(5000);

   }

}


here is the circuit:

http://i.imagehost.org/view/0115/circuit

What I do wrong, and I can't get the result that I want?
please help me because I run out of ideas!

thanks in advance.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 02, 2010 11:22 am     Reply with quote

There are many threads in the archives about this. Use the forum's
search page to find them:
http://www.ccsinfo.com/forum/search.php
Search for these terms:
Quote:
modem command*

Set it to: Search for all terms


Also, this whole huge construct can be replaced with one printf:
Quote:

unsigned char cmd_at[]="AT";

for (i=0; i<sizeof(cmd_at); i++){

putc(cmd_at[i]);

}
putc(13);
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Thu Sep 02, 2010 1:19 pm     Reply with quote

I have already coded this before....

I posted my code on the code library under: Receiving txt messages

http://www.ccsinfo.com/forum/viewtopic.php?t=42527

It should get you going.

Hope that helps.

g.
_________________
CCS PCM 5.078 & CCS PCH 5.093
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

re
PostPosted: Fri Sep 03, 2010 2:29 am     Reply with quote

The delays look large, though I don't think that's your problem, but having large delay values will prevent the pic from doing other job.

thanks
a
ckielstra



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

View user's profile Send private message

Re: re
PostPosted: Fri Sep 03, 2010 4:38 am     Reply with quote

arunb wrote:
The delays look large, ...
Yes, that's what I thought too. Especially here:
Code:
   putc(13);

   delay_ms(100);
   gets(answer);
There should be no delay between sending the newline character and waiting for the response. Most likely the 100ms is too long and the whole response is missed.

As said earlier in this thread; this kind of project has been done many times before. Have a look at these older threads.
koirnaos



Joined: 23 Dec 2009
Posts: 6

View user's profile Send private message

PostPosted: Sat Sep 04, 2010 3:18 am     Reply with quote

Thank you all for the answers. They helped me a lot!

PCM programmer: I changed the piece of code that you indicated with a printf and it works fine!

Gabriel: Thanks for the code. It helped to correct some mistakes I made.

Arunb, ckielstra: I didn't know that 100ms is too large delay.
I used this value because the instructions indicate that the modem after sending a command has a 100ms delay before the response is send. (I did that to avoid reading wrong data). I will check how the program works without the delay and I will post the results.

Ricalyn03: Thanks for the suggestion. I'll look at the structure of my code, maybe there is another problem that I didn't noticed.


kostas
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Sat Sep 04, 2010 7:11 am     Reply with quote

your welcome...


Just as a suggestion you could just sent all the set up commands
without checking for their replys.

Basically what I wind up doing in my next versions of the posted code is just checking for the "OK" of the AT command... if the check is passed... I just send a burst of commands.... and then repeat the same initial test.

This ensures that my comunication with my cell is working before I send and after I send set up commands.... if your burst of commands is correct( as in commpatible commands and correct spelling and format) then you should not have any issues thus making response checking useless....and only needing to test that communications with the cell are indeed working.

This simplifies your set up code to basically a bunch of printf().

Also... send a command and store anything the cell responds in big array and later check the array.... as oposed to checking for a string as it comes char by char..... its simple... but doing it on the fly would probably be more efficient.
_________________
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