[AVR] GPS interfacing c code, help is appreciated

Status
Not open for further replies.

cjj20

Newbie level 4
Joined
Jan 9, 2018
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
119
Hi can anyone help me in getting this code right?


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include <stdio.h>
 
#include <avr/io.h>
#include <util/delay.h>
#define LCD_DATA PORTC;
#define F_CPU 12000000UL
#define ctrl PORTB;
#define USART_BAUDRATE 4800
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
#define rs PB0; //register select
#define rw PB1; // LCD read/Write
#define en PB2; // enable print
 
void lcd_init();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void delay(int);
void drawstring(unsigned char *stri);
unsigned int receiveserial();
void uart_init();
void checkgpgga();
 
 
 
unsigned char send[90];
unsigned char send2[90];
unsigned char data;
unsigned char lat[15];
unsigned char long[15];
unsigned char lati;
unsigned char longi;
 
int main()
{
   DDRC=0xff;        //output
   DDRB=0x07;
   lcd_init();
   delay(50);
   uart_init();
   
   while(1){
       
       receiveserial();
       checkgpgga();
       
   }
 
    return 0;
}
 
void uart_init()
{
    UBRRL = BAUD_PRESCALE; 
    UBRRH = (BAUD_PRESCALE >> 8); 
    
    UCSRB |= (1<<RXCIE) | (1 << RXEN) | (1 << TXEN);   
    UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); 
    
    
}
 
void lcdcmd(unsigned char n)
{
    LCD_DATA=n;
   
    ctrl =(0<<rs)|(0<<rw)|(1<<en); 
    delay(1);
    ctrl =(0<<rs)|(0<<rw)|(0<<en); 
    return;
}
 
void lcddata(unsigned char n)
{
    LCD_DATA=n;
    ctrl = (1<<rs)|(0<<rw)|(1<<en); 
    
    delay(1);
    ctrl = (1<<rs)|(0<<rw)|(0<<en); 
    return;
}
 
void lcd_init()
{
    lcdcmd(0x38); //2 line matrix
    delay(50);
    lcdcmd(0x01); //clear lcd
    delay(50);
    lcdcmd(0x0E); // cursor start
    delay(50);
    lcdcmd(0x80); //cursor begins at line 1
    delay(50);
    return;
}
 
unsigned int receiveserial()
{
 
    while(!(UCSRA) & (1<<RXC));
    return UDR;
}
 
void drawstring(unsigned char *stri)
{
    unsigned char stri;
    int j;
    while(stri[j]!='\0')
    {
        lcddata(stri[j]);
        j++;
    }
    return;
}
void checkgpgga()
{
    int i;
    int j;
    data=receiveserial();
    if(data=='$')
    {
        data=receiveserial();
        if(data=='G')
        {
            data=receiveserial()
            if(data=='P')
            {
                data=receiveserial();
                if(data=='G')
                {
                    data=receiveserial();
                    if(data=='G')
                    {
                        data=receiveserial();
                        if(data=='A')
                        {
                            data-receiveserial();
                            if(data==',')
                            {
                                data=receiveserial();
                                while(data!=',')
                                {
                                    data=receiveserial();
                                }
                                while(data!=',')
                                {
                                    data=receiveserial();
                                }
                                lat[0]=receiveserial();
                                data=lat[0];
                                for(i=0;data!=',';i++)
                                {
                                    lat[i]=receiveserial();
                                    data=lat[i];
                                }
                                lati=receiveserial();
                                data=receiveserial();
                                while(data!=',')
                                    {
                                        data=receiveserial();
                                    }
                                    long[0]=receiveserial();
                                    data=long[0];
                                    for(i=1;data!=',';i++)
                                    {
                                        long[i]=receiveserial();
                                        data=long[i];
                                    }
                                    longi=receiveserial();
                                    lcdcmd(0x01);
                                    delay(1);
                                    lcdcmd(0x80);
                                    delay(1000);
                                    i=0;
                                    while(lat[i]!='\0')
                                    {
                                        lcddata(lat[j]);
                                        j++;
                                    }
                                    lcddata(lati);
                                    lcdcmd(0xC0);
                                    delay(1000);
                                    i=0;
                                    while(long[i]!='\0')
                                    {
                                        lcddata(long[i]);
                                        i++;
                                    }
                                    lcddata(longi);
                                    delay(1000);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
 
 
 
 
 
void delay(unsigned int times)
{
    unsigned int i;
    unsigned int j;
    for(i=0;i<times;i++)
    for(j=0;j<1275;j++);
}

 

Did you really compile this code? Line 135 looks very odd (using the '-' operator instead of the '=' assignment ). Anyway, the use of delay in the execution chain of a GPS parsing routine the right choice to make it not work.

- - - Updated - - -

When I worked with GPS decoding, I made the simulation of the module just by inserting NMEA sentences obtained on the Web adding to a text file. I would expect to see you doing the same. In case I used Proteus to run the firmware in debug mode, and Realterm to emulate the module. Note that the Serial terminal should be configured so that to add a delay between each sent byte, otherwise data will be lost.
 

I would certainly not use a delay function of the type you have - as soon as the compiler applies any sort of optimisation then that whole function is likely to be reduced to a single NOP: if that!
What is actually going wrong with your code? What have you done to try to debug it?
Susan
 


Nothing is being printed out on the LCD screen. I made some corrects and debugged it so now there are no errors in debugging it. I attempted to send a char to the receiver in the AVR simulator IDE but nothing was printed on the LCD screen.
 


I made some corrections, debugged and compiled. No errors in debugging now. However nothing is displayed on the screen even when a char is sent to to be read by usart.

New code below:

Code:
#include <stdio.h>

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#define LCD_DATA PORTC;
//#define F_CPU 12000000UL
#define ctrl PORTB;
#define USART_BAUDRATE 4800
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
#define rs PB0; //register select
#define rw PB1; // LCD read/Write
#define en PB2; // enable print

void lcd_init(void);
void lcdcmd(unsigned char);
void lcddata(unsigned char);

void drawstring(unsigned char *stri);
unsigned int receiveserial(void);
void uart_init(void);
void checkgpgga(void);



unsigned char send[90];
unsigned char send2[90];
unsigned char data;
unsigned char lat[15];
unsigned char longt[15];
unsigned char lati;
unsigned char longi;

int main(void)
{
	DDRC=0xff;        //output
	DDRB=0x07;
	lcd_init();
	_delay_ms(50);
	uart_init();
	
	while(1){
		
		receiveserial();
		checkgpgga();
		
	}

	return 0;
}

void uart_init(void)
{
	UBRRL = BAUD_PRESCALE;
	UBRRH = (BAUD_PRESCALE >> 8);
	
	UCSRB |= (1<<RXCIE) | (1 << RXEN) | (1 << TXEN);
	UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
	
	
}

void lcdcmd(unsigned char n)
{
	PORTC=n;
	/*ctrl=(0<<rs)|(0<<rw)|(1<<en);
	delay(1);
	ctrl=(0<<rs)|(0<<rw)|(0<<en);
	return;
	*/
	PORTB&=~(0<<PB0);  // RS sets 0

	PORTB&=~(0<<PB1);  // RW sets 0

	PORTB|=(1<<PB2);   // make enable from high to low

	_delay_ms(1);

	PORTB&=~(0<<PB2);
	_delay_ms(2);
	return;
}

void lcddata(unsigned char m)
{
	PORTC=m;
	/*ctrl=(1<<rs)|(0<<rw)|(1<<en);
	delay(1);
	ctrl=(1<<rs)|(0<<rw)|(0<<en);
	*/
	

	PORTB|=(1<<PB0);    // RS sets 1

	PORTB&=~(0<<PB1);   // RW sets 0

	PORTB|=(1<<PB2);    // make enable from high to low

	_delay_ms(1);

	PORTB&=~(0<<PB2);
	_delay_ms(2);
	return;
}

void lcd_init(void)
{
	lcdcmd(0x38); //2 line matrix
	_delay_ms(1);
	lcdcmd(0x01); //clear lcd
	_delay_ms(1);
	lcdcmd(0x0E); // cursor start
	_delay_ms(1);
	lcdcmd(0x80); //cursor begins at line 1
	_delay_ms(1);
	return;
}

unsigned int receiveserial()
{
	
	while((UCSRA&(1<<RXC))==0){
		
	
	return (UDR);
	}
	
}

void drawstring(unsigned char *stri)
{
	//unsigned char *stri;
	int j;
	while(stri[j]!='\0')
	{
		lcddata(stri[j]);
		j++;
	}
	return;
}
void checkgpgga(void)
{
	int i;
	int j;
	data=receiveserial();
	if(data=='$')
	{
		data=receiveserial();
		if(data=='G')
		{
			data=receiveserial();
			if(data=='P')
			{
				data=receiveserial();
				if(data=='G')
				{
					data=receiveserial();
					if(data=='G')
					{
						data=receiveserial();
						if(data=='A')
						{
							data-receiveserial();
							if(data==',')
							{
								data=receiveserial();
								while(data!=',')
								{
									data=receiveserial();
								}
								while(data!=',')
								{
									data=receiveserial();
								}
								lat[0]=receiveserial();
								data=lat[0];
								for(i=0;data!=',';i++)
								{
									lat[i]=receiveserial();
									data=lat[i];
								}
								lati=receiveserial();
								data=receiveserial();
								while(data!=',')
								{
									data=receiveserial();
								}
								longt[0]=receiveserial();
								data=longt[0];
								for(i=1;data!=',';i++)
								{
									longt[i]=receiveserial();
									data=longt[i];
								}
								longi=receiveserial();
								lcdcmd(0x01);
								_delay_ms(1);
								lcdcmd(0x80);
								_delay_ms(1000);
								i=0;
								while(lat[i]!='\0')
								{
									lcddata(lat[j]);
									j++;
								}
								lcddata(lati);
								lcdcmd(0xC0);
								_delay_ms(1000);
								i=0;
								while(longt[i]!='\0')
								{
									lcddata(longt[i]);
									i++;
								}
								lcddata(longi);
								_delay_ms(1000);
							}
						}
					}
				}
			}
		}
	}
}






int delay()
{
	unsigned int times;
	unsigned int i;
	unsigned int j;
	for(i=0;i<times;i++)
	for(j=0;j<1275;j++);
}
 

It is your job to determine by simulations, at which part of the code the problem lies; some candidates to inspect are longt[], lat[].
 

What is the LCD? For the common 16x2, 16x4 (and similar combination) LCDs with an HD44780 chip in them, the timing of the initialisation is critical as is getting the initialisation sequence correct. In particular, there must be at least 100mSec after power-on and a 4.1mSec pause after the first command is sent. THis is why I called out your 'delay' function in my earlier post 0 if you don;t get the delays right then the LCD initialisation can fail (silently) and cause all sors of grief.
As a first test, are you getting anything on the LCD display - even lit rectangles where each character should be? Turn up the contract setting until you see these rectangles and then back it off a little so they just disappear. That way you know that you will be able to see any character that is actually sent to the initialised display.
I would also suggest that you strip away much of your code and just get the LCD display to work first - then add in all the rest.
I would suggest that you look at better ways to parse the incoming command characters (as in the checkgpgga() function). For example, why not use a buffer to receive all incoming characters, check for the string terminator (I think it is '\r\n' or '\n') and then parse the received characters from the buffer. Especially with the call to the 'receiveserial()' in your main loop which will throw away a character before you try to re-sync to the start of the next data string, you might have issues in this part of your code.
Susan
 
Last edited:

Hi cjj20,

As Aussie Susan said, First chect LCD working code then display the received char on LCD. Or vice-versa. i.e. leave the LCD. Confirm that you receive the data from GPS and store it in to buffer. If you receive data successful, then check LCD and combine both.

pmk
 

I don't use AVR but looking at the code it would seem use of the 'strtok' command would simplify it by reading the whole GPS data and parsing it afterwards. Trying to receive, check and display simultaneously is a prime candidate for dropping characters.

Brian.
 

It is your job to determine by simulations, at which part of the code the problem lies; some candidates to inspect are longt[], lat[].

Yes I do think checkgpgga is a problem, however the code receiveserial seems to be not receiving the data.

I want to use a 16x2 lcd. I think the main issue is that the receiveserial function is not receiving the gps data. However still getting used to the various software but from what im seeing receiveserial will read a string but just not the gps data.

I will try that as it does indeed make a lot of sense. My receiveserial refuses to read the gps so i think maybe the software im using may be a culprit as well.
 

My receiveserial refuses to read the gps so i think maybe the software im using may be a culprit as well.

It suggests wrong configuration of UART peripheral. Anyway, are you saying that there is NOTHING comming from serial, or data received do not matches expected values ?

- - - Updated - - -

Did you note that in your original code, F_CPU = 12MHz but at the revised version in post #5 it became commented ? What is the oscillator crystal you are using ?
 

I don't know about AVR. If datasheet available, I can try assist. You can try this method.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
 
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
 
#define F_CPU 12000000UL
 
#define USART_BAUDRATE 4800
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
 
char data;
 
void uart_init(void)
{
    UBRRL = BAUD_PRESCALE;
    UBRRH = (BAUD_PRESCALE >> 8);
    
    UCSRB |= (1<<RXCIE) | (1 << RXEN) | (1 << TXEN);
    UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
    
}
 
unsigned int receiveserial()
{
    
    while((UCSRA&(1<<RXC))==0){
        
    return (UDR);
    }
    
}
void checkgpgga(void)
{
    
    data=receiveserial();
    if(data != ' ')
    {
     printf(""); // set debug point here
    }
}
 
void main(){
    
    // 1. disable all interrupts, watchdog
    // 2. Set Clock frequency
    
    // 3. Check TX & RX pin set as Inputs
    // 4. Off all analog, ADCON pins
 
    DDRC=0xff;        //output
 
    // 5.  0xff == output ????? check
    
    DDRB=0x07;
    
    // Check PORTB settings
        
    uart_init();
        
    while (1){
        checkgpgga();
    }
}

 

I don't know about AVR. If datasheet available, I can try assist. You can try this method.

None of the codes, either yours or the OP, will not work. First of all, the weird printf() function that you added as an intended Debug just adds an unnecessary delay which blinds polling data from UART. The OP in other hand have been warned about some problems on his code (eg delay), but have not given any indication that understood or considered the tip.

Another issue is that none of the above codes make use of interrupt feature, which is strongly recommended whenever dealing with GPS sentences, which can reach about 75 bytes per second. Interrupt therefore becomes almost mandatory, particularly when using not too simple devices, such as the LCD, which you have removed in your code (?!).
 


I have been editing the code to reflect the ISR feature. I commented out the F_CPU because it gave me an error that this was already defined. I am working on changing the delays used. I do believe that I need an efficient gps parser.

Code so far:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#include <stdio.h>
 
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#define LCD_DATA PORTC
//#define F_CPU 12000000UL
#ifndef __OPTIMIZE__
# warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
#endif
 
#define ctrl PORTB
#define USART_BAUDRATE 4800
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
#define rs PB0//register select
#define rw PB1// LCD read/Write
#define en PB2// enable print
 
void lcd_init(void);
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void uart_transmit (unsigned char data);
void drawstring(unsigned char *stri);
unsigned int receiveserial(void);
void uart_init(void);
void checkgpgga(void);
 
 
 
unsigned char send[90];
unsigned char send2[90];
unsigned char data;
unsigned char lat[15];
unsigned char longt[15];
unsigned char lati;
unsigned char longi;
 
int main(void)
{
    DDRC=0xff;        //output
    DDRB=0x07;
    lcd_init();
    _delay_ms(50);
 
    
  // unsigned char l;
    uart_init();
    
    UCSRB|=(1<<RXCIE);   //enable ucsrb interrupt
    sei();// enable global interrupt
    
//  unsigned char strit[]="Hey there";
//  drawstring(strit);
    while(1){
    
    
    
    
    
 
    
        checkgpgga();
        
    }
 
    return 0;
}
 
void uart_init(void)
{
    UBRRL = BAUD_PRESCALE;
    UBRRH = (BAUD_PRESCALE >> 8);
    
    UCSRB |= (1<<RXCIE) | (1 << RXEN) | (1 << TXEN);
    UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
    
    return;
}
 
void lcdcmd(unsigned char n)
{
    PORTC=n;
    /*ctrl=(0<<rs)|(0<<rw)|(1<<en);
    delay(1);
    ctrl=(0<<rs)|(0<<rw)|(0<<en);
    return;
    */
    PORTB&=~(0<<PB0);  // RS sets 0
 
    PORTB&=~(0<<PB1);  // RW sets 0
 
    PORTB|=(1<<PB2);   // make enable from high to low
 
    _delay_ms(1);
 
    PORTB&=~(0<<PB2);
    _delay_ms(50);
    return;
}
 
void lcddata(unsigned char m)
{
    PORTC=m;
    /*ctrl=(1<<rs)|(0<<rw)|(1<<en);
    delay(1);
    ctrl=(1<<rs)|(0<<rw)|(0<<en);
    */
    
 
    PORTB|=(1<<PB0);    // RS sets 1
 
    PORTB&=~(0<<PB1);   // RW sets 0
 
    PORTB|=(1<<PB2);    // make enable from high to low
 
    _delay_ms(1);
 
    PORTB&=~(0<<PB2);
    _delay_ms(50);
    return;
}
 
void lcd_init(void)
{
    lcdcmd(0x38); //2 line matrix
    _delay_ms(1);
    lcdcmd(0x01); //clear lcd
    _delay_ms(1);
    lcdcmd(0x0E); // cursor start
    _delay_ms(1);
    lcdcmd(0x80); //cursor begins at line 1
    _delay_ms(1);
    return;
}
 
unsigned int receiveserial()
{
    
 
    while((UCSRA&(1<<RXC))==0);
        
    
    return (UDR);
    
    
}
 
 // function to send data
void uart_transmit (unsigned char data)
{
    while (!( UCSRA & (1<<UDRE)));// wait while register is free
    UDR = data;
                                   // load data in the register
}
 
void drawstring(unsigned char *stri)
{
    //unsigned char *stri;
    int j;
    while(stri[j]!='\0')
    {
        lcddata(stri[j]);
        j++;
    }
    return;
}
void checkgpgga(void)
{
    int i;
    int j;
//  data=receiveserial();
    if(data=='$')
    {
        
        if(data=='G')
        {
            
            if(data=='P')
            {
                
                if(data=='G')
                {
                    
                    if(data=='G')
                    {
                        
                        if(data=='A')
                        {
                            
                            if(data==',')
                            {
                                
                                while(data!=',')
                                {
                                    data=receiveserial();
                                }
                                while(data!=',')
                                {
                                    data=receiveserial();
                                }
                            lat[0]=receiveserial();
                                data=lat[0];
                        for(i=0;data!=',';i++)
                                {
                            lat[i]=receiveserial();
                                    data=lat[i];
                                }
                                lati=receiveserial();
                                data=receiveserial();
                                while(data!=',')
                                {
                                    data=receiveserial();
                                }
                            longt[0]=receiveserial();
                                data=longt[0];
                            for(i=1;data!=',';i++)
                                {
                            longt[i]=receiveserial();
                                    data=longt[i];
                                }
                            longi=receiveserial();
                                lcdcmd(0x01);
                                _delay_ms(1);
                                lcdcmd(0x80);
                                _delay_ms(1);
                                i=0;
                                while(lat[i]!='\0')
                                {
                                    lcddata(lat[j]);
                                    j++;
                                }
                                lcddata(lati);
                                lcdcmd(0xC0);
                                _delay_ms(1);
                                i=0;
                                while(longt[i]!='\0')
                                {
                                lcddata(longt[i]);
                                    i++;
                                }
                                lcddata(longi);
                                _delay_ms(1);
                                UCSRB|=(1<<RXCIE);
                            }
                        }
                    }
                }
            }
        }
    }
    return;
}
 
 
 
ISR(USART_RXC_vect)
{  unsigned char data;
    data=UDR; // or PORTC=UDR;
    UDR=data;
    
}

 

Try solving one problem at a time or you will confuse yourself further.
Susan

True but I think the main issue is that I need a gps parser similar to this in my code:

HTML:
if (mstrcmp(tmp_words[0], "$GPGGA") == 0) {
	// Check GPS Fix: 0=no fix, 1=GPS fix, 2=Dif. GPS fix
	if (tmp_words[6][0] == '0') { 
		// clear data
		res_fLatitude = 0;
		res_fLongitude = 0;
		m_bFlagDataReady = false;
		return;
	}			
	// parse time
	res_nUTCHour = digit2dec(tmp_words[1][0]) * 10 + digit2dec(tmp_words[1][1]);
	res_nUTCMin = digit2dec(tmp_words[1][2]) * 10 + digit2dec(tmp_words[1][3]);
	res_nUTCSec = digit2dec(tmp_words[1][4]) * 10 + digit2dec(tmp_words[1][5]);
	// parse latitude and longitude in NMEA format
	res_fLatitude = string2float(tmp_words[2]);
	res_fLongitude = string2float(tmp_words[4]);
	// get decimal format
	if (tmp_words[3][0] == 'S') res_fLatitude  *= -1.0;
	if (tmp_words[5][0] == 'W') res_fLongitude *= -1.0;
	float degrees = trunc(res_fLatitude / 100.0f);
	float minutes = res_fLatitude - (degrees * 100.0f);
	res_fLatitude = degrees + minutes / 60.0f;
	degrees = trunc(res_fLongitude / 100.0f);
	minutes = res_fLongitude - (degrees * 100.0f);
	res_fLongitude = degrees + minutes / 60.0f;
 
	// parse number of satellites
	res_nSatellitesUsed = (int)string2float(tmp_words[7]);
 
	// parse altitude
	res_fAltitude = string2float(tmp_words[9]);
 
	// data ready
	m_bFlagDataReady = true;
}
 

None of the codes, either yours or the OP, will not work
I have written code only for debugging purpose to confirm that his Uart working correctly. If you dump him with huge codes, like LCD, interrupts, ring buffer, etc, he will be confused a lot & difficult to find the cause of error. I have given the code for just one char from GPS. If he receives the data correctly, then he can easily confirm that his Uart works fine and GPS module also works well and move on to LCD code. Then he can add anything he wants for further developments.

pmk

- - - Updated - - -

True but I think the main issue is that I need a gps parser similar to this in my code:

Don't concentrate on parsing the data as of now. Otherwise, not only confuse yourself and also others and difficult to accomplish your task. What you need as of now. First, confirm that your Uart works and receives data from GPS correctly. This should be the prime task of you. Then check LCD code. If both are working well, then add interrupt (if you prefer and strongly recommended) to your code. Then use Ring buffer.

pmk
 


Alright I will try that. I hope I can figure it out soon.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…