View previous topic :: View next topic |
Author |
Message |
madtoilet
Joined: 02 Apr 2008 Posts: 36
|
receiving data serially using the pic18f452 |
Posted: Wed Apr 02, 2008 3:50 pm |
|
|
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
|
|
Posted: Wed Apr 02, 2008 9:38 pm |
|
|
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
|
|
Posted: Thu Apr 03, 2008 10:01 am |
|
|
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
|
|
Posted: Thu Apr 03, 2008 1:25 pm |
|
|
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
|
|
Posted: Thu Apr 03, 2008 4:07 pm |
|
|
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
|
|
Posted: Thu Apr 03, 2008 4:36 pm |
|
|
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
|
|
Posted: Thu Apr 03, 2008 5:29 pm |
|
|
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
|
|
Posted: Fri Apr 04, 2008 4:09 pm |
|
|
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
|
|
Posted: Fri Apr 04, 2008 5:27 pm |
|
|
i've revamped the code and i have it working now. |
|
|
|