Shop OBEX P1 Docs P2 Docs Learn Events
GPS PMB 688 With Atmega 16/32 — Parallax Forums

GPS PMB 688 With Atmega 16/32

JeemonJeemon Posts: 2
edited 2012-03-04 10:41 in Robotics
hello all.
As a part of my project I have to interface parallax PMB 688 GPS receiver with atmega 32 the microcontroller that I am using..
I tried to retrieve NMEA sentences from it..but in my LCD (16*2) i am getting wrong information..
I have connected PMB 688 GPS
->its red colour wire to 5V
->its black colour wire to GND
->its yellow colour wire to RxD pin of Atmega 32..
Here is my code...
can anybody tel me what is wrong with it??please..



// Program to get latitude and longitude value from GPS modem and display it on LCD:


#define F_CPU 16000000UL

#include<avr/io.h>
#include<util/delay.h>

#define USART_BAUDRATE 4800
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)


#include "lcd.c"



void usart_init();
unsigned int usart_getch();

unsigned char value,i,lati_value[15],lati_dir, longi_value[15], longi_dir, alti[5] ;

int main(void)
{

InitLCD(LS_BLINK|LS_ULINE); //initialization of LCD
_delay_ms(50); // delay of 50 mili seconds
LCDWriteString("we at");
LCDCmd(0xC0);
usart_init(); // initialization of USART
while(1)
{
value=usart_getch();
if(value=='$')
{
value=usart_getch();
if(value=='G')
{
value=usart_getch();
if(value=='P')
{
value=usart_getch();
if(value=='G')
{
value=usart_getch();
if(value=='G')
{
value=usart_getch();
if(value=='A')
{
value=usart_getch();
if(value==',')
{
value=usart_getch();
while(value!=',')
{
value=usart_getch();
}
lati_value[0]=usart_getch();
value=lati_value[0];
for(i=1;value!=',';i++)
{
lati_value=usart_getch();
value=lati_value;
}
lati_dir=usart_getch();
value=usart_getch();
while(value!=',')
{
value=usart_getch();
}
longi_value[0]=usart_getch();
value=longi_value[0];
for(i=1;value!=',';i++)
{
longi_value=usart_getch();
value=longi_value;
}
longi_dir=usart_getch();
LCDCmd(0x01); //clear display
_delay_ms(1);
LCDCmd(0x80); //force cursor to begin on 1st line
_delay_ms(1000);
LCDWriteStringXY(0,0,"Lat:");
i=0;
while(lati_value!='\0')
{
LCDWriteInt(lati_value,1);
i++;
}
LCDWriteString("-");
LCDWriteInt(lati_dir,1);
LCDCmd(0xC0);
LCDWriteStringXY(0,1,"Lon:");
_delay_ms(1000);
i=0;
while(longi_value!='\0')
{
LCDWriteInt(longi_value,1);
i++;
}
LCDWriteString("-");
LCDWriteInt(longi_dir,1);
_delay_ms(1000);

}
}
}
}
}
}
}
}
}




void usart_init()
{
/* Enable receiver and transmitter */
UCSRB = (1<<RXEN)|(1<<TXEN);
/* Set frame format: 8data, 2stop bit */
UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);
//UCSRB |= (1<<RXCIE) | (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception circuitry
//UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes

UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register
}


unsigned int usart_getch()
{

while (!(UCSRA & (1 << RXC))); // Do nothing until data have been recieved and is ready to be read from UDR
return(UDR); // return the byte
}

Comments

  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-02-29 11:51
    Please repost using the code wrap (see the balloon icon in the editor). It's very hard to follow the logic of your program.

    In any case, have you first determined you're getting valid sentences by simply displaying the values piped to a debug window? That should be the first step.

    Be sure to wait for the GPS to go into satellite lock. The red LED will stop flashing.

    -- Gordon
  • JeemonJeemon Posts: 2
    edited 2012-03-01 03:30
    Thanks for your reply Sir ..
    After the GPS module's red LED stopped blinking only I tried to get the NMEA $GPGGA sentence..
    Microcontroller is not able to access any valid information from it..
    I think it is not at all receiving '$ also'...
    Regarding my code, I will try to give a brief explanation
    BAUD_PRESCALE will be having BAUD PRESCALE value and in void usart_init() it will be loaded to UBRR register as
    UBRRL = BAUD_PRESCALE;
    UBRRH = (BAUD_PRESCALE >> 8);
    I have
    Set frame format as 8data, 2stop bit..which is coded in function void usart_init().

    My code is based on polling method..
    function usart_getch() reads out the data from GPS module
    So continuously I will be checking for $GPGGA
    while(1)
    {
    value=usart_getch();
    if(value=='$')
    {
    value=usart_getch();
    if(value=='G')
    {
    value=usart_getch();
    if(value=='P')
    {
    value=usart_getch();
    if(value=='G')
    {
    value=usart_getch();
    if(value=='G')
    {
    value=usart_getch();
    if(value=='A')
    {
    value=usart_getch();
    if(value==',')
    {
    like this and saving only Latitude, Latitude direction, Longitude, Longitude direction in arrays lati_value[], lati_dir, longi_value[], longi_dir correspondingly..

    Please tel me what is wrong with this..

    Thanks..
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-03-04 09:53
    Please don't post any more code before you discover how to use the forum's code feature. You want to wrape [ code] and [ /code] tags around your code, so it's not mangled when you post.

    The docs provided by Parallax are a bit skimpy for this module, but you can look up other SiRFIII modules on the Web, including from the manufacturer, for more details on the serial comm. I cannot find any that say 2 stop bits is supported (docs I have say 0 and 1), so you should be sure you've set up the serial port correctly. Don't make any assumptions here, including whether the data is inverted or non-inverted.

    I had asked if you've tried to simply receive the data through a terminal or debug window. Use that technique to make sure you've got the serial communications working. If you get streams of sentences than you're ready to go on to the next piece.

    I understand how your program is supposed to work, but it's much better to take these one step at a time.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-03-04 10:41
    attachment.php?attachmentid=78421&d=1297987572
Sign In or Register to comment.