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 CCS Technical Support

GPS codes not working properly

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



Joined: 31 May 2012
Posts: 10

View user's profile Send private message

GPS codes not working properly
PostPosted: Mon Sep 29, 2014 8:16 am     Reply with quote

I have 18F4550 and Crius CN-06 GPS Module. I want to print coordinate of Gps position to LCD module. Firstly, I want to printf whatever comes from GPS to LCD. UNfournately, I could not get correct NMEA format. I am getting nonsense staff. I tried the my system inside and outside and different baudrates. Could you show me my fault where is? Regards
How many minute wait necessary to GPS lock to the satellites?
Codes;

Code:


      if(getch()=='$')
      {
       for(i=0;i<66;i++)
        {
        e=getch();
        GelenGps[i]=e;
        printf(lcd_putc,"%c",GelenGps[i]);
        delay_ms(10);
        }
       } 



Last edited by cengav4r on Mon Sep 29, 2014 9:17 am; edited 2 times in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Mon Sep 29, 2014 8:29 am     Reply with quote

Use the hardware UART.
Get rid of the delay.

You are using a software UART (forced by using the E1/E2 pins). This has no buffering. So one character arrives, and then you spend several hundred uSec writing this to the LCD (LCD's are _slow_), then pause for 10mSec. _Anything_ arriving in all this time is now lost. With no buffering, this is going to be the next ten characters+. You then start looking again, and at this point could even be 'mid character'. So from this point, 'garbage'....

Use the hardware UART pins.
Use a larger circular buffer (look at ex_sisr.c, and search here about this).
Then remember that even this larger buffer will overflow, unless the whole string is dealt with before the next one comes.
cengav4r



Joined: 31 May 2012
Posts: 10

View user's profile Send private message

PostPosted: Mon Sep 29, 2014 8:51 am     Reply with quote

Thank you for response,
Now I tried below code. I will try it at outside. It seems OK ;). Why it is not good E1-E2 pins in order to C6-C7. If I want to get two UART what should I do? Any more good suggesstion,appreciated.

Code:
if(getch()=='$')
      {
       for(i=0;i<66;i++)
        {
        e=getch();
        GelenGps[i]=e;
        }
        }
        delay_ms(100);
       for(i=0;i<66;i++)
       {
       printf(lcd_putc,"%c",GelenGps[i]);
       delay_ms(100);
       }   
      }
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Mon Sep 29, 2014 9:07 am     Reply with quote

Get a chip with two UART's.....

The software UART, is half duplex, and _requires_ that the code is sitting 'waiting' for data to arrive.

Chips like the 46J50, give another UART which is relocatable, and other extras like a second SPI also relocatable etc...
cengav4r



Joined: 31 May 2012
Posts: 10

View user's profile Send private message

PostPosted: Mon Sep 29, 2014 9:10 am     Reply with quote

I tried it at outside and wait approximately 5-10 min. I get nearly correct NMEA format with some errors (which means display show full character (1111 x 1111). How can I fix these errors? (I didn't change UART pins, I used E1-E2).Thank you for everything.
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Mon Sep 29, 2014 9:18 am     Reply with quote

You are still running out of time.

As I already pointed out the LCD is quite slow. Slow enough that you may occasionally not finish writing in time for the next character. Worse though, USB _will_ occasionally require interrupt servicing, and when this happens, you will get corrupted characters using the software UART.
cengav4r



Joined: 31 May 2012
Posts: 10

View user's profile Send private message

New Questions
PostPosted: Tue Sep 30, 2014 7:30 am     Reply with quote

My current problem is How can I get data which is coming from GPS. I want to take whatever (all data) comes and send to USB.

Code:

if(getch()=='$')
      {
       for(i=0;i<67;i++)
        {
        e=getch();
        GelenGps[i]=e;
        delay_us(5);
        }
        }
        delay_ms(100);
       for(i=0;i<67;i++)
       {
       usb_put_packet(UcNokta1,GelenGps[i] ,64, USB_DTS_TOGGLE); // Datayı Gönder..
       delay_ms(500);
       }   


1.How can I get lenght of data (which is coming from GPS).I mean What should I write for(i=0;i<67;i++) 67 to ??
2.What is the best way to send data (which is coming from GPS) to USB. Interrupt?, Rtos? other??

I am getting below lines from USB. (Indoor test)

Code:
? ?xD?T!` T?@?? ????5q v%0*??(??0L???5q v%0*??(??0L?@$
?R?5b,=GPRMGG@? ,V,,,,%0*??(??0L?@$
?R?5b,>GPRMPP@? ,V,,,,,,,0@??5q v%0*??(??0L?@$
?R?5b,?GPRMGG@? ,V,,,,??5q v%0*??(??0L?@$
?R?5b,@GPRMGG@? ,V,,,,?? ????5q v%0*??(??0L?@$
?R?5b,AGPRMAA@? ?xD?T!` T?@?? ????5q v%0*??(??0L?@$
?R?5??5q v%0*??(??0L?@$
?R?5b,GPGGG@?
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Sep 30, 2014 8:22 am     Reply with quote

cengav4r,

You have already been told the answer several times, but you aren't listening, or you don't like the answer. To *reliably* receive serial data from the GPS you are going to need to implement an interrupt driven serial data buffering scheme, preferably with a 'circular' receive buffer. Any other method is going to be sub-optimal, as you've already seen.

So, #1, use the internal hardware UART, and #2, implement an interrupt drive serial receive scheme using the int_rda interrupt. A great example of this is CCS example program 'ex_sisr.c'.

You don't need to know the total number of characters to receive. The NMEA string always starts with the '$', and always ends with the 'CR/LF', so use these unique characters to determine when each NMEA string begins and ends.

Again, this is a rehash of previous advice, so please take it and stop coming back here asking the same question over and over. Trust me, the answer will always be the same!

John
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