cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F3 + GPS

grega
Associate II
Posted on February 03, 2014 at 10:43

Hello everyone,

I am the new one at programming stm32f3. I saw multiple examples here on the forum but I did not find what I want.

I have stm32f3 discovery board and ublox GPS connected to PD8 (Tx) and PD9 (Rx) pins. I want to read data from pins and show it on pc on terminal. I have connected stm32f3 discovery to PC via USB. For programming I use Keil uVision. Has anybody of you some code for this or can help me how to do that please?

Please help.

Best regards

Grega

#nmea #c-basics #parser #fsm #design #state-machine #c-learning
28 REPLIES 28
Posted on February 06, 2014 at 18:38

I'm kind of busy with my own work, send me some boards to play with, or come shovel my drive way, I'll see what I can do.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
grega
Associate II
Posted on February 06, 2014 at 18:47

OK, thanks!

grega
Associate II
Posted on February 10, 2014 at 14:13

Hello,

Has anyone some code for parse NMEA data ($GPGGA sentence) from usart?

thanks

Posted on February 10, 2014 at 15:06

NMEA Parser Design

''This article makes no assumption of the media that the NMEA data is acquired. The techniques here can be applied on received data from a higher abstraction layer. A simple example written in C++ demonstrates this parser design''

http://www.visualgps.net/whitepapers/nmeaparser/nmeaparserdesign.html

grega
Associate II
Posted on February 10, 2014 at 16:22

//****************************************************************************

void Parse_GPS( void )

{

uint8_t c;

c = USART_ReceiveData(USART3); // read character

if ( c == '$' ) ucCommas = 0; // start of NMEA sentence

if ( c == ',' ) ucCommas++; // count commas

if (( ucCommas == 2 ) ||

( ucCommas == 3 )) { // get latitude data (3rd comma)

Parse_Coord (&fLat_Temp, c);

}

if (( ucCommas == 4 ) ||

( ucCommas == 5 )) { // get longitude data (5th comma)

Parse_Coord (&fLon_Temp, c);

}

if (( ucCommas == 9 ) ||

( ucCommas == 10 )) { // get heading (9th comma)

if ( c == ',' ) {

uiGps_Heading = 0;

} else if ( c != '.' ) {

uiGps_Heading *= 10;

uiGps_Heading += (c - '0');

}

}

if (ucCommas == 14){ // end of NMEA sentence

ucCommas = 14;

uiGps_Heading /= 10;

fLat_Curr = fLat_Temp;

fLon_Curr = fLon_Temp;

}

}

//****************************************************************************

static void Parse_Coord( float * fCoord, uint8_t c )

{

switch (c) {

case '0' :

case '1' :

case '2' :

case '3' :

case '4' :

case '5' :

case '6' :

case '7' :

case '8' :

case '9' :

ulTempCoord = ulTempCoord * 10UL + (uint32_t)(c - '0');

break;

case '.' :

*fCoord = (float)(ulTempCoord % 100UL) / 60.0f; // decimal part

*fCoord += (float)(ulTempCoord / 100UL); // integer part

ulTempCoord = 0UL;

break;

case ',' :

*fCoord += (float)ulTempCoord / 600000.0f; // decimal part

ulTempCoord = 0UL;

break;

default :

ulTempCoord = 0UL;

break;

}

}

//****************************************************************************

Clive1, I added this code for parse gps data. I want to parse just $GPGGA sentence. I got 0 as result. I printed fLon_Curr and fLat_Curr. What did I wrong? Can you help me please...I really need help because I am an amateur at coding :(  Please help
Posted on February 10, 2014 at 19:05

''I really need help because I am an amateur at coding''

 

It doesn't help that you are trying to jump straight into coding  without first having a proper design  of your solution.

Study the article I just cited - it shows you how to go about designing a parser...

For 'C' learning resources, see:

http://blog.antronics.co.uk/2011/08/08/so-youre-thinking-of-starting-with-c/

chen
Associate II
Posted on February 10, 2014 at 19:24

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6dx&d=%2Fa%2F0X0000000bsL%2Fw8ZS_gc5YrspM9qAkiP.JU8zTpUdOw.eCzQHnrKUjew&asPdf=false
grega
Associate II
Posted on February 11, 2014 at 12:04

Hello,

I must do this but don't know how:

1. Declare a char array large enough to hold a single line.

 char d[200]={0};

2. As serial data comes in, stuff the data in the array and null-terminate it.  (I am not sure)

    for(int i=0; i < 199 ;i++)

            {

        d[i]=USART_ReceiveData(USART3);

    

            }

3. Use strncmp() to check if it has the proper header.

4. Use strtok() to go through each of the comma deliminated tokens and extract the data.

Please help me, how to do that. Please post me some example code.

Best regards
chen
Associate II
Posted on February 11, 2014 at 13:13

Hi

''1. Declare a char array large enough to hold a single line.

  char d[200]={0};''

There is no simple answer to this. You have to analyze the input that you expect to get and size the buffer accordingly. You are lucky, NEMA standard is well documented and it should be easy to work out what the max length should be.

''As serial data comes in, stuff the data in the array and null-terminate it.  (I am not sure)''

No, your data will not be null terminated if it is coming from a serial device. It is likely to be line terminated - ie <CarageReturn> or <CarageReturn> & <LineFeed> or <LineFeed> & <CarageReturn> or <LineFeed>

When your UART function reads the line in, the UART function must null terminate it.

Check the string copy functions in string.h - I think they should.

''3. Use strncmp() to check if it has the proper header.

4. Use strtok() to go through each of the comma deliminated tokens and extract the data.''

You can use strtok() to seperate the header first and then use strncmp() to check the header.

''3. Use strncmp() to check if it has the proper header. ''

Something like :

if ( 0 == strncmp(  inputString, ''Header'', strlen( ''Header'' ) ) )

''4. Use strtok() to go through each of the comma deliminated tokens and extract the data.''

You have my example above. The documentation from cplusplus.com should explain how to use it.