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

How to get ASCII character from serial line...

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



Joined: 08 Jan 2013
Posts: 14

View user's profile Send private message

How to get ASCII character from serial line...
PostPosted: Mon Apr 18, 2016 5:27 am     Reply with quote

Hi, I start to learn ccs c nowadays and I have a question about getting characters from serial line (rs 232)...

As an example"
this is the sentence which sending with serial line:

$GPGGA,092750.000,5321.6802,N,00630.3372,W,1,8,1.03,61.7,M,55.2,M,,*76


The numbers in the sentence are always changing of course...

baud rate is:9600 bps

I want to get the numbers; example "092750.000" or "00630.3372" and display them on LCD screen.

Could you show me a way...

thanks
temtronic



Joined: 01 Jul 2010
Posts: 9164
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Apr 18, 2016 5:57 am     Reply with quote

Easy way is to use the 'search' feature and scan the 'code library' for 'GPS code' or similar wording. there is complete programs in there....


Jay
ezflyr



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

View user's profile Send private message

PostPosted: Mon Apr 18, 2016 7:14 am     Reply with quote

Hi,

It's a two-part problem - (1) receiving the data reliably, and (2) parcing the data to extract the individual data values contained in the NMEA message.

For the first part, I recommend you look at the CCS example program 'ex_sisr.c'. This is an example of an interrupt driven circular receive buffering scheme, which will be essential for reliable message reception. Get this done first, and make it 100% before moving on to the 2nd part.
_________________
John

If it's worth doing, it's worth doing in real hardware!
Ttelmah



Joined: 11 Mar 2010
Posts: 19348

View user's profile Send private message

PostPosted: Mon Apr 18, 2016 7:43 am     Reply with quote

Lets go a step further.

Temtronic is right that there is code out there to extract the values, but this is generally designed to actually 'read' the numbers and you don't really need this.
Ezflyr is also right that buffering is vital.

However you then need to think for a moment. You don't actually have to extract the numbers. Look at how you 'know' that the first number is 92750.000?.

What you do if look at a 'line' of data. You 'know' that it is a line of data, since it begins with $GPGGA. Then you go to the first ',' and read the characters that follow, and this is the first value you want to display. You know the number has ended, when you see the character ',' again. Two more commas along, and then you see the next number you want.

So keep it simple. Use the serial buffer code as Ezflyr suggests.
Then have your code look for the '$' character. When it sees this you 'know' you are at the start of a line. Then just count commas till you get to the bit you want, and when you reach the required number of commas, start sending the received characters to your display. Stop when you see a comma again.
The number of commas you have already seen tells you which particular value you are at, and this can also then tell you 'where' you want the number to be put on your display.
You only need to display the characters from one comma to the next. If you want a little more elegance you can suppress the leading zeros.
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