Avr UART and GPS LS20031

Well, l i am trying to receive data from my LS0031 GPS module via UART communication using an avr ATtiny2313.

My thought is to receive data from the gps and sent it as it is, to an LCD HD44780 to watch them, as a first step. The problem i came across with is that i receive data and i see characters at the LCD but it isn’t NMEA code. I can not see any ascii code like a $ start bit , or GPGGA or a whole sentense like $GPGGA,053740.000,2503.6319,N,12136.0099,E,1,08,1.1,63.8,M,15.2,M,0000*64. What i see is different characters with ascii code like 0xA9 translated to chinesse chars or somethink like this, and sometimes i watch ascii like 0x43 which is real chars and seems like a part of NMEA code. Note that the chars i see at the LCD depends on the gps transmit. If i stop the transmit unplugging the transmits gps cable the chars i see at the lcd stops too.

I concluded that the problem is at the frames and how the avr translate and receive the transfered bytes.

I have checked the UART initialization thousands of times and i can’t find any mistake.

I’ll write below what i did with the avr and if anyone see something wrong or something helpfull please reply and help me.

Here we are:

MCU:ATtiny2313

External Oscillator for stable frequency at 4mhz

GPS works at default settings: 9600 bps, 8 data bits, no parity, 1 stop bits (default) as manual writes.

So the settings i set at the initialization is:

UCSRB: Set RXEN to enable Receiver

UCSRC: Set UCSZ0:1 for 8 data bits no parity and 1 stop bit.

UBRR=25 for a baud rate of 9600 with 0.2% error as Attiny2313 manual says.

The Source Code.

.NOLIST ; Don't list the following in the list file
.INCLUDE "tn2313def.inc" ; Import of the file
.LIST ; Switch list on again


.equ	RS=5
.equ	RW=6
.equ	 E=4

.def	temp1= r16
.def	temp2= r17

.cseg
.org	0
rjmp	RESET

rjmp	RESET
rjmp	RESET

RESET:
	;Init Stack Pointer
	ldi	temp1, low(RAMEND)
	out	spl, temp1

	;Configure Pins
	ldi temp1,0xFF
	out DDRB, temp1

	ldi	temp1,0x71
	out	DDRD, temp1

	;Wait fot LCD to boot
	rcall	wait_LCD

	;Configure LCD
	rcall	init_LCD
	
	;Configure USART
	rcall	init_USART

	;Main program
	main:
        ;Here I receive a data byte and i send it to LCD
		rcall	receive_USART
		rcall	write_LCD
        ;And a small delay here to have time to see the char at the lcd
		rcall	delay

	rjmp	main


	;!--------------------------------USART--------------------------------!

	;***********************************************
	;************** Initialize USART ***************
	;***********************************************
	init_USART:

		;Set Baud Rate 9600
		ldi temp1,0
		ldi	temp2,25
		
		out	UBRRH,temp1
		out	UBRRL,temp2

		;Enable Receive
		ldi	temp1,(1<<RXEN) 
		out	UCSRB,temp1

		;8-bit, no parity, 1 stop bit
		ldi	r16,(3<<UCSZ0)
		out	UCSRC,temp1

	ret
	;***********************************************
	;************** Receive Dt USART ***************
	;***********************************************
	receive_USART:

		;Wait for data to be received
		sbis	UCSRA,RXC
		rjmp	receive_USART

		;Get and return received data from buffer

		in	temp1,UDR

	ret


	;!---------------------------------LCD---------------------------------!

	;***********************************************
	;**************** Initialize LCD ***************
	;***********************************************
	init_LCD:
		;LCD Configuration
		ldi	temp1,0b00111000	;8-bit, 2-lines, 5x8 dots
		rcall	command_LCD

		ldi	temp1,0b00001111	;Display on, show Cursor, blink
		rcall	command_LCD

		ldi	temp1,0b00000110	;cursor increament,No display shift 
		rcall	command_LCD

		ldi	temp1,0x01	;Return Home
		rcall	command_LCD
	ret

	;***********************************************
	;*************** Commands to LCD ***************
	;***********************************************
	command_LCD:
		sbi	PORTD,E		;Set E

		cbi	PORTD,RW	;clear RW bit for writing
		cbi	PORTD,RS	;clear RS bit for commands

		out	PORTB,temp1
		
		cbi	PORTD,E

		rcall	wait_LCD
	ret


	;***********************************************
	;***************** Write to LCD ****************
	;***********************************************
	write_LCD:
		sbi	PORTD,E		;Set E

		cbi	PORTD,RW	;Clear RW bit for writing
		sbi	PORTD,RS	;Set RS bit for data

		out PORTB,temp1	;Put data to data bus

		cbi	PORTD,E

		rcall	wait_LCD
	ret


	;***********************************************
	;***************** Wait for LCD ****************
	;***********************************************
	wait_LCD:
	

		sbi	PORTD,RW	;turn in read mode busy flag
		cbi	PORTD,RS

		ldi	temp1,0x00	;turn PortB input
		out	DDRB,r16
		
		sbi	PORTD,E 	;take E high	
		nop
		in	temp2,PINB	;get address and busy flag

		cbi	PORTD,E

		ldi	temp1,0xFF	;turn PortB output again
		out	DDRB,r16
		
		cbi	PORTD,RW

		sbrc temp2,7
		rjmp wait_LCD

		sbi	PORTD,E

	ret
	
	;***********************************************
	;****************** Delay Loop *****************
	;***********************************************
	delay:

		; ============================= 
		;    delay loop generator 
		;     7000000 cycles:
		; ----------------------------- 
		; delaying 6999996 cycles:
		          ldi  R20, $76
		WGLOOP0:  ldi  R21, $75
		WGLOOP1:  ldi  R22, $A8
		WGLOOP2:  dec  R22
		          brne WGLOOP2
		          dec  R21
		          brne WGLOOP1
		          dec  R20
		          brne WGLOOP0
		; ----------------------------- 
		; delaying 3 cycles:
		          ldi  R20, $01
		WGLOOP3:  dec  R20
		          brne WGLOOP3
		; ----------------------------- 
		; delaying 1 cycle:
		          nop
		; ============================= 

	
	ret

PS. Sorry for my English it isn’t my native language and it takes me some time to explain you my problem in english.

I want to beleive that i made you understand my problem and somebody will help me.

Sounds like problems with baudrate. My LS0031-module was not using 9600 baud by default (as indicated in the datasheet). If I’m not mistaken I think it was set to 38400. Also note that if you change baud-rate, it will “stick” for several days as the settings are battery backed-up.

I had connected the LS20031 gps to pc via an usb to uart converter and for monitoring i used gpsfox and minigps where in both i had choosen 9600 baudrate and it worked fine.

Yiha!

After a lot lot lot lot lot of debugging i found the mistake! The mistake was that i had connected the gps module to a different power supply than the avr, in resault the avr had separate GND than the gps. The avr reads the gps signal in compare the avr’s GND and not the gps GND. So, i had 2 different GNDs, 2 different reference points!. Now i connected the two GNDs each other and it works fine!

Now the problem that i came across with is how i can read the incomingdata? I tried to read data from uart and write them to LCD but it takes too long that i lost almost the whole packet, until the chars are written to the LCD! The only char i managed to write to the lcd was $GP. I also tried to read from UART and push the char imidiate to Stack and then pop it for writing to LCD and it warked.

I also decreased the baud rate to 4800 but nothing really changed.

Is there a more common way to read data from UART?

thanks.