2014-02-03 01:43 AM
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-learning2014-02-06 09:38 AM
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.
2014-02-06 09:47 AM
OK, thanks!
2014-02-10 05:13 AM
Hello,
Has anyone some code for parse NMEA data ($GPGGA sentence) from usart? thanks2014-02-10 06:06 AM
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
2014-02-10 07:22 AM
//****************************************************************************
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 help2014-02-10 10:05 AM
''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/
2014-02-10 10:24 AM
2014-02-11 03:04 AM
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 regards2014-02-11 04:13 AM
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.