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.

[SOLVED] GPS interface with LPC2148 please help .

Status
Not open for further replies.

pawan kumar

Member level 4
Member level 4
Joined
Jan 31, 2012
Messages
73
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,298
Location
Chennai
Activity points
1,894
Greetings,

I am a newbie and this is my first post in edaboard.

I am trying to receive data from GPS module to LPC2148 through UART 1 and send the same to PC-hyperterminal through UART0. both take place at 9600 baud. Please see through my code.The hyperterminal is blank. I know I am wrong, unable to find out where. help me out.

Or if i am making any other mistake in the very fundamental approach of receiving data, please guide me. I have tested each function individually.
Code:
#include<lpc214x.h>
void inituart1()						  //initializes both UARTS at 9600 baud
{
U1LCR=0x83;
U1DLL=0x61;
U1DLM=0x00;
U1LCR=0x03;
U0LCR=0x83;
U0DLL=0x61;
U0DLM=0x00;
U0LCR=0x03;
}

void send(unsigned char a)							//sends a byte through U0
{
U0THR=a;
while(U0LSR!=0x60);
}
void senduart1(unsigned char a)						  //sends a byte through U1
{
U1THR=a;
while(U1LSR!=0x60);
}
unsigned char recuart1()										// recieves a byte from U1
{
unsigned char p;
while ((U1LSR&0x01)!=1);
p=U1RBR;
return p;
}
unsigned char rec()											// recieves a byte from U0
{
unsigned char p;
while ((U0LSR&0x01)!=1);
p=U0RBR;
return p;
}
int main()
{

PINSEL0=0x00050005;								   //initialized U0 and U1 as UART and not GPIO
PINSEL1 = 0x00000000;
PINSEL2 = 0x00000000;
inituart1();
while(1)
{

send(recuart1());


}
}

Thanks in advance

Pawan
 

Hello!

Before going any further, you say that hyper terminal is blank. Did you try to test
sending bytes to hyperterminal? I mean, not bytes from the GPS, but bytes that you
know are readable.
In your main, try:
uint8 i = 'A';

Code:
	while(1) {
		send(i);
		i++;
		if(i == 'Z'+1) {
			i = 'A';
			send(0x0D);
			send(0x0A);
		}
	}

Once this works, try to get a byte from your GPS.

Now supposing this has been tested, there might be a timing problem.
What your GPS does is this: it sends buffers to UART every second (for most common
types). As the GPS itself has no means to control whether there is a receiver connected
to it, it simply sends its bytes blindly. Now in your loop (in the main program), you call
2 functions (you call send and recuart1). Each time you call a function, the processor
pushes and pops data to / from the stack, and this takes time. So you receive one byte,
you send it, but you may have missed the following byte (depending on your processor frequency).

What I would do is defining a buffer (I made this earlier, and 512 bytes is enough).
And you write 2 functions like this:
GPSReceiveBuffer (receives one set of data and returns when there is a long enough
blank, between 2 buffers)
SendToSerial (send the buffer you just got to serial port).

Now last comment, I cannot really diagnose what happens. If you miss bytes, then you should
anyway get bytes sent to terminal (with missing bytes, but anyway you should get something.
Are you sure that your GPS is configured at 9600?

Dora.
 

Hello Dora,

Thanks for the reply. I have followed the same approach as you have said. Initially, I had transmitted a single byte 'A' to hyperterminal. It worked. then, I transmitted a string continuously. Then received a character from keyboard and displayed the same.only after all this, I ventured towards the GPS module.

I have found a new problem : to put more test to the UART, I programmed another LPC2148 board to transmit 'A' continuously(and checked with hyperterminal),receive this into UART1 of my old LPC2148 board and then transmit the same to hyperterminal (I replaced the GPS module with a controller sending A continuously). even this did not work.I used two variants here: 1) connect Txd,Rxd and Ground of the two controllers appropriately, 2)using MAX232 on both sides and the reliable serial cable. No result.

And yeah, even I have wondered of that delay Issue. You gave me an idea. but initially, I would be happy even if I see some garbage value in the hyperterminal.

Awaiting your reply,

Pawan
 

This is completely strange for me...serial communication of hyperterminal+microcontroller works but microcontroller+microcontroller never works :( I feel exhausted of ideas.


has anyone encountered a similar issue? please help me. . .
 

Connect the GPS to the computer directly through MAX232 and see if the GPS is actually working. You may have problems with the power supply of the GPS or you've swapped the TxD and RxD pins.
 

OK, try the following steps:
1- What kind of GPS are you using? Some GPS modules may have UART signal levels different than their supply voltage. For instance, the GPS EM406A has a 5V supply however, the UART levels are 2.8V so, check the datasheet of your GPS for the UART levels.
2- Check your controller's "Input High" minimum value.
3- Try to just forward whatever you are getting from the GPS to the hyperterminal. By this, you will check if the controller receives the data correctly.
4- Try to use a lower BaudRate.

Hope these help.
 
I am using MediaTek MTK MT3318 based GPS module.
This is the product link. **broken link removed**
I will try it out and get back as soon as I get something. :)
 

Hello!

Of course you need to test the GPS outdoors.

I don't think it's the problem right now. All the modules I have used output strings
even indoors. Series of empty NMEA strings, full of commas with nothing between
but anyway it outputs something.

Kumar, do you have an oscilloscope?
One good way to start would be to trace the signal from the GPS module.
Verify that you have some input at the CPU RX, verify that the bit rate corresponds
to your CPU setting, verify that the level is within the specs, verify that the polarity
and parity settings are fine, etc...

Dora.
 

I have tested the module Indoors(hyperterm). it gives all the strings with more of commas as dora says.

Unfortunately, am not that rich to own a scope myself :) but since the signals are clear with the hyperterm, it eliminates the suspect over G.P.S module. I doubt my method of receiving data or LCD interface delay commands.

Once I get some clarity, i ll let you know friends. btw, thanks for actively helping me throughout .

Pawan
 

Hello!

For your info, there is a small portable oscilloscope on the market. It looks like
a Sony Portable Playstation and has a similar resolution.
It costs about 100 USD. Of course, its sampling frequency is probably very low
so you cannot see quick transients but if you want to debug a serial port, that's more
than enough. There are also 2 channels devices for about 150 USD (price here in
Japan. I think you can find them cheaper on the net).

Dora.
 

that's really cheap.. I used to think a scope was never less than 600USD..this is news bro! but my project constraints now : I promised to show 50%completion of my final year project by 10th feb..I am not able to communicate any peripheral with ARM. it does with PC.I would ve been happier if it did not work with P.C either.I feel like having a choke throat after crossing half the river......
 

that's really cheap.. I used to think a scope was never less than 600USD..this is news bro! but my project constraints now : I promised to show 50%completion of my final year project by 10th feb..I am not able to communicate any peripheral with ARM. it does with PC.I would ve been happier if it did not work with P.C either.I feel like having a choke throat after crossing half the river......

Dont feel depressed. You will finish it.

Let me list out some points, You might have done /know already but check again.

1.If the modem is working with hyperterminal then the voltage levels should be high and not suitable for micro directly. You should use max232 circuit.

2. You should flip the connections of microcontroller side max232 while connecting to modem.

3. Did you tried to receive data from hyperterminal?

come up with the results i'll try to guide you
 
That gives me energy... Thanks nandhu :)

I ve analysed the problem let me report the results: I have two LPC2148 dev. boards . I programmed one board to transmit 'A' continuously through UART0 I checked this through the hyperterm. I programmed another LPC

board to receive the character in UART1 and transmit the same through UART0 . I connected this to hyperterm. It is Blank.

to summarize my results, I can communicate (tx and rx) my microcontroller with P.C , when I try to communicate between 2 controllers, the same code fails......

pls see through my code :

Code:
#include<lpc214x.h>
void init()				//initializes  both UARTS @9600,8bit, no pairity,1 stopbit
{
U0LCR=0x83;
U0DLL=0x61;
U0DLM=0x00;
U0LCR=0x03;
U1LCR=0x83;
U1DLL=0x61;
U1DLM=0x00;
U1LCR=0x03;
}
void senduart0(unsigned char a)		  //sends a byte through UART0
{
U0THR=a;
while(U0LSR!=0x60);
}
unsigned char recuart1()			 //recieves a byte from UART1
{
unsigned char p;
while ((U1LSR&0x01)!=1);
p=U1RBR;
return p;
}
int main()
{

unsigned char p;
PINSEL0=0x00050005;
PINSEL1 = 0x00000000;
PINSEL2 = 0x00000000;
init();
while(1)
{
 p=recuart1();					   //receive something in UART1
 senduart0(p);				      //send the same to UART0 
}
}

and regarding GPS, when I connect it with hyperterm(through max232), it works perfectly..

I ve used max 232 in every UART interface and checked.

nandri,

Pawan
 

You should pay attention to what nandhu015 said in his second point:

2. You should flip the connections of microcontroller side max232 while connecting to modem

In order to connect a microcontroller to a microcontroller via RS232, you will need a null modem cable where the thr RX pin of one end of the cable is connected to the TX pin of the other end of the cable, and vice versa. In a regular serial cable, the connections are straight thru. This is because a PC is a DTE in RS232 terminology, and a microcontroller or any peripheral is a DCE. When you connect a DCE to a DCE, you need to swap RX and TX on the cable.

r.b.
 
Have you tried flipping tx and rx which rberek explained?

Does your board have a lcd, if so try to write the data received through the uart in lcd.
 
@aberek and @nandhu,

Thanks a lot pals!!! it finally worked partly :). I am now able to communicate between 2 LPC boards successfully. I had done this test earlier,but mismatched the null modem config.Now,

I connected the TXD pin of one board directly to RXD pin of another and common Ground. THEN, I could see the golden letters in the hyperterm!! LCD , as usual had delay, so hyperterm was reliable.


I had made a null modem myself , after a lot of fingerburns. then, I found that one board has a MAX232 and another has a MAX202.I have not even googled out for max 202 . I felt like am delaying in replying you.


Friends, I ll do it as carefully as possible. You have helped me a lot. I ll complete the interface asap and keep you posted. Please help me in all other stages of my project too. :) :) also, thanks to Dora

Thanks a lot!!

Pawan
 
It works completely..... no probs with the codes. I had swapped Txd and Rxd in the UART1 port. got it right bros.

Thank you.
 
Hi pawan

I am using LPC2148 for integrating Ecompass. I am getting the Ecompass sensor data output accurately in LPC2148 LCD display.(Ecompass is from nex robotics using LSM303DLHC IC).

I have two queries after getting the output :

1. How to read the data Ecompass data from LPC2148 and store it in a hyper terminal
2. Do I need two USB to Serial converter to complete the reading ( I have only one converter. Is it possible to manage with one)

Can you please help me out as I am in the last stage of the project.

Thanks in Advance
Panneer selvam
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top