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

receiving data serially using the pic18f452

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



Joined: 02 Apr 2008
Posts: 36

View user's profile Send private message

receiving data serially using the pic18f452
PostPosted: Wed Apr 02, 2008 3:50 pm     Reply with quote

I'm currently trying to use my pic to communicate with a gps and gsm module. I have to use serial communication to do this. I understand that i should use the following code to set the baud rate and such

Code:

#use rs232(baud=9600, bits=8, parity=N, stop=1, ERRORS, xmit=PIN_C6, rcv=PIN_C7)


I'm still not very familiar with this so any help will be appreciated. Is there anything else that i should add/know?
Guest_7068
Guest







PostPosted: Wed Apr 02, 2008 9:38 pm     Reply with quote

That should be good enough. The UART on most PIC chips is fairly uncomplicated. See the help topic for #use rs232 for more information.
grasspuddle



Joined: 15 Jun 2006
Posts: 66

View user's profile Send private message

PostPosted: Thu Apr 03, 2008 10:01 am     Reply with quote

does the module need any handshaking? usually RTS or another pin needs to be set high/low or nothing will happen.

is a computer module? if it needs more than a 5volt logic you'll have to look into an interface chip like the max232 (which is used for pic to computer communication)
madtoilet



Joined: 02 Apr 2008
Posts: 36

View user's profile Send private message

PostPosted: Thu Apr 03, 2008 1:25 pm     Reply with quote

i'm using a GPS module. We've gotten the level translation down. I'm not sure if it requires a handshake. This could be part of the issue that i'm running into actually because my Rx and Tx ports are remaining high throughout the whole process
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Apr 03, 2008 4:07 pm     Reply with quote

Usually it isn't necesary any handshaking to receive a GPS data, some modules require
RTS to ground if no handshake is used. Also, to configure and initiate a data connection,
you must use AT modem type commands, for example to GET an ACQUIRED POSITION, you should request it using AT$GPSACP
It should be in the spec of your GPS module.


Humberto
madtoilet



Joined: 02 Apr 2008
Posts: 36

View user's profile Send private message

PostPosted: Thu Apr 03, 2008 4:36 pm     Reply with quote

we have the GPS module configured to transmit the right data. However, our pic is giving me a high signal from the Rx pin. The gps is transmitting the data to the Rx pin but the high that my Rx pin is giving out seems to be blocking out the gps.

Is there a way to stop the pin from doing that?
madtoilet



Joined: 02 Apr 2008
Posts: 36

View user's profile Send private message

PostPosted: Thu Apr 03, 2008 5:29 pm     Reply with quote

i've solved the problem with the pins giving a high logic all the time. It was a simple error on my behalf.

However, this is what i'm using to receive my gps string and to pick out what i need from it

Code:
void get_string(void) { //andrew is the master

  char c;
   int i=0;
   int count=0;
   unsigned char temp[68];
   unsigned char cmp[] = "$GPRMC"; //this is the beginning of the part of the message that i want


 while (c !='\n') //at the end of the message it gives me a <CR>
 {
 c=getc();
 c = temp[i++];

 }

 temp[i-1] = '\0';

 if (strstr(temp, cmp) == temp) {  //compare the message with $GPRMC and then save it if it contains it
   //we have our string, save it
strcpy(rmc, temp);
out_lcd_string(rmc); //display the message

}

}
madtoilet



Joined: 02 Apr 2008
Posts: 36

View user's profile Send private message

PostPosted: Fri Apr 04, 2008 4:09 pm     Reply with quote

Code:


#fuses HS,NOWDT,NOPROTECT, NOLVP
#use delay(clock=40mhz)
#use rs232(baud=4800, bits=8, parity=N, stop=1, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

void get_string(void) {

  char c;
   int i=0;
   int count=0;
   unsigned char temp[68];
   unsigned char cmp[] = "$GPRMC"; //this is the beginning of the part of the message that i want


 while (c !='\n') //at the end of the message it gives me a <CR>
 {
 c=getc();
 temp[i] = c;
i++;

 }

 temp[i-1] = '\0';

 if (strstr(temp, cmp) == temp) {  //compare the message with $GPRMC and then save it if it contains it
   //we have our string, save it
strcpy(rmc, temp);
out_lcd_string(rmc); //display the message

}

}


some basic corrections. However my program still locks up when it starts this function. The out_lcd_string() works correctly for the rest of the program.

i'm using the pic 18F452
madtoilet



Joined: 02 Apr 2008
Posts: 36

View user's profile Send private message

PostPosted: Fri Apr 04, 2008 5:27 pm     Reply with quote

i've revamped the code and i have it working now.
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