Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need help with my GPS project and USART

Status
Not open for further replies.

rimip

Newbie level 6
Joined
Nov 7, 2010
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,396
Hello guys.
I am working on a project using the PIC16F690 that will capture/receive the NMEA strings coming out the GPS receiver and display it on the screen.

To test if my c program structure works, I am simply sending a string from another microcontroller and I am displaying it on the screen. So this part of my software WORKS. When I plug in my GPS, I see nothing on the screen.

I plugged my GPS to the computer and I see the NMEA data perfectly.

These are some important parts of my software, I don't know if I should post all, it's kinda long.

Code:
startLCD();				// Delay / Init. LCD / clear
i = 0;
rcflag = 0;
printflag=1;
ei();					//Enable Interrupts				

while (1)

{

ReturnHome(); // return screen to home position.

if ((recdata == '$')&(printflag==1)) // LOOK for the $ sign ("$")

	{
		rcflag = 1;
		printflag=0;
		i=0;				
	}


if ((rcflag == 1)&(newdataflag==0)) //store data

			{		
				newdataflag = 1;
				rcnum[i] = recdata;// STORE rx/ed data in rcnum array
				i++;
				printflag = 0;
			}
		

if (i>7) // DO THE FOLLOWING IF I HAVE ALL the characters wanted

			{
				RCIE = 0; //DISABLE INTERRUPTS
				rcflag = 0;
				i=0; //RESET BUFFER
                                // SEND THE CHARCTERS COLLECTED TO THE SCREEN
				SendInfo(rcnum[0]); 
				SendInfo(rcnum[1]);
				SendInfo(rcnum[2]);
				SendInfo(rcnum[3]);
				SendInfo(rcnum[4]);
				SendInfo(rcnum[5]);
				SendInfo(rcnum[6]);
				SendInfo(rcnum[7]);
				i=0;
				printflag = 1;
				RCIE = 1; //ENABLE INTERUPTS
			}

}//END WHILE
}//END MAIN PROGRAM

My interrupt routine is this:

Code:
void interrupt Usart_isr(void)
	{
	di();
	newdataflag = 0;
	recdata = RCREG;
	RCIF = 0;	
	ei();				
	}

The data I am sending: $GPSDATA
On the receiving end, if I find a $, I start collecting the characters. When I have all the characters I want, I display on the screen, and start looking for the next $ for the next set of data.
When I plug in my GPS, I should see something on the screen, because the GPS does send out "$".
 
Last edited:

what is the baud rate of GPS...... is it same as that in the programmed....

connect the board to hyperterminal and send the same data from terminal and see if it gets the data.... connect gps to terminal and see if you are getting the output...

use the same cable you used to test the controller with terminal and connect board to GPS and try again..........
 

Thank you for the reply.

I connected the output of the GPS to hyperterminal, I get the correct data. When I connect GPS to pic16f690, I see nothing on the LCD.

TO TEST if my program works, I connected another microcontroller sending serial data to my main microcontroller. That data is received and shows on LCD.

Everything (2 pic16f690 and gps) run at 4800, 8 bits, no parity, 1 stop bit.

edit: I think my USART works fine if I can receive data from the other pic and display that. I just don't know how to debug.
 

try to modify the program by removing the routine from ISR and write the program to wait till you get $ symbol in a normal way... Your ISR routine is creating problem...
 

I *think my interrupt routine works fine because it was able to receive data from the second pic MC; but still I modified the program to just look for the "$" and print it when it finds that. Once again, this worked when picking up data from my second PIC, but when I plugged in my GPS, nothing.

What I tried next gave me unexpected results.
I modified the program to just pick up the GPS data(NOT LOOKING FOR ANY specific digit), load the array, and print 30 characters it picked up with the serial ISR; and cycle that. I saw random characters cycling on the LCD.
My GPS has RSR232 TX and TTL TX, I conncted both.
On hyperterminal, I was seeing the correct NMEA data.
On my LCD I was seeing random charatcters, LOTS of letters. Letter "Q" most often.

I also modified my program to look for the letter "Q" instead of the "$". It worked, again with random character.

Why does terminal shows correct data, but not LCD...?
 

if you are receiving data but it appears to be random characters the most likely problem is you have the baud rate wrong.
check you baud rate divisors, i.e. what is the processor clock frequency and what baud rate do you require? look in the PIC data sheet to see how you calculate the divisors.
 

Thanks for the reply.

Indeed I did made a mistake for a crucial value in the baud rate generator.I feel so bad now... I am now able to receive and display some characters on the LCD that make more sense. But, it seems that it is skipping stuff.

Every time a "$" is located, I collect a few characters and display them on the screen. But, in a standard NMEA line, there is almost always the letter "G" after the $ sign, which I never see.
I also tested other letters, and it seems a lot of the stuff is just missing/skipped over. Any ideas why?

One another note, according to my program (posted in my first post), I can't disable and enable interrupts ( di() and ei() ) while printing the letters on the LCD. If I comment out the di and ei in my 3rd "if" statement, then it works...
It makes more sense to disable the interrupts while I am printing on the screen so I don't bothered with incoming data while I am busy printing and not ready for more.
 

yes that is the reason i told not to use interrupt as when you are printing on LCD if new data comes then your LCD routing is affected in my earlier post...

you should be very careful while using interrupt....
 

I was suspecting that as being the reason too...
The problem is, I don't really understand how to do this without the interrupts. I know how to look for just one character and print it...
If I try to look for one specific character, and collect , say 10, and print them, they turn out to be all the same.
Like you said, now I want to do this:

1-Wait until a "$" sign is detected.
2-If "$" detected, collect character from RCREG.

[Repeat 10 times]
3-Clear RCREG
4-Wait for new character
5-Collect character

6-Print all 10 characters on Screen
7- Go to step 1

Can you help me modify my code to do this.
What I accomplished before was, like I said, I detected "$" sign, and then stored that 10 times. Because the software is very quick and stores it 10 times (or more) until something new even comes.
 

So can anyone help me out please...
The problem I have is that I have tried a code but it fills the buffer with the same value and it doesn't update.
I need something that will wait for a new character and take a new character at a time. Wait and take something new comes.
When I have enough, I will display them all and reset the buffer.
 

the problem I found with GPS is it streams data at you faster than you can deal with, in particular if you are displaying it on an LCD which is a very slow device in computer terms. For initial testing I have the microcomputer connected to a PC with terminal emulator running at a faster baud rate than the GPS. As GPS data arrives I send it to the PC where it is displayed and I can scroll it to look at the NMEA information. When I know the GPS is operational I can search the input stream for particular NMEA sentence, e.g. $GPGGA.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top