PDA

View Full Version : Trouble reading GPS from "NEO-6" module



CuriousOne
- 14th July 2024, 19:42
Hello.
I'm trying to read time from the GPS module "Neo-6"
I asked AI to generate the code and here it is (with hardware config and DEFINEs by me):



;----[16F886 Hardware Configuration]--------------------------------------------
#CONFIG
cfg1 = _INTRC_OSC_NOCLKOUT ; INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN
cfg1&= _WDT_ON ; WDT enabled
cfg1&= _PWRTE_OFF ; PWRT disabled
cfg1&= _MCLRE_OFF ; RE3/MCLR pin function is digital input, MCLR internally tied to VDD
cfg1&= _CP_OFF ; Program memory code protection is disabled
cfg1&= _CPD_OFF ; Data memory code protection is disabled
cfg1&= _BOR_OFF ; BOR disabled
cfg1&= _IESO_ON ; Internal/External Switchover mode is enabled
cfg1&= _FCMEN_ON ; Fail-Safe Clock Monitor is enabled
cfg1&= _LVP_OFF ; RB3 pin has digital I/O, HV on MCLR must be used for programming
cfg1&= _DEBUG_OFF ; In-Circuit Debugger disabled, RB6/ICSPCLK and RB7/ICSPDAT are general purpose I/O pins
__CONFIG _CONFIG1, cfg1


cfg2 = _BOR40V ; Brown-out Reset set to 4.0V
cfg2&= _WRT_OFF ; Write protection off
__CONFIG _CONFIG2, cfg2


#ENDCONFIG


TRISA=%00000001 'SET A TO OUTPUT 1=input
TRISC=%00001000 'set C3 for gps
TRISB=%00011000 'set PortB to output
ANSELH=%00000000 ' ADC OFF B
ANSEL=%000000000 'configure PortA as digital except first 2
ADCON1=%10000000 'adc justify
OSCCON=%01110101 'SET FREQUENCY TO 8MHZ
WPUB=%00000000 'turn off Pullups
CM1CON0=0 'DISABLE COMPARATORS
CM2CON0=0 'SAME HERE
'CCP1CON=%01000000 ' configure pwm
'PSTRCON=%00010110 'disable C pwm


DEFINE OSC 8
DEFINE ADC_BITS 12
DEFINE ADC_CLOCK 5
DEFINE ADC_SAMPLEUS 5




'aska:
serout2 portc.5,84,[" test-"," ",10,13]
'pause 100
'goto aska


gps_data VAR BYTE[80] ' Buffer to store GPS data
gps_char VAR BYTE ' Character received from GPS
time_data VAR BYTE[6] ' Array to store the extracted time
i VAR BYTE ' Loop variable
start_found VAR BIT ' Flag to indicate start of time data


' Define the serial pins
GPS_RX var PORTC.2 ' RX pin for GPS (Adjust according to your setup)
GPS_TX var PORTC.5 ' TX pin for GPS (Adjust according to your setup)


' Initialize variables
start_found = 0
i = 0


main:
' Wait for data from GPS
SERIN2 GPS_RX, 84, [gps_char] ' 9600 baud rate with N, 8, 1 settings (84 represents the baud rate)
serout2 GPS_TX, 84, [gps_char,","] 'also added by me for debugging


' Store data in buffer
gps_data[i] = gps_char
i = i + 1


' Check if we have a complete line of data
IF gps_char = 10 THEN
' Look for the $GPRMC sentence
IF (gps_data[1] = "G") AND (gps_data[2] = "P") AND (gps_data[3] = "R") AND (gps_data[4] = "M") AND (gps_data[5] = "C") THEN
' Extract time from the sentence
start_found = 1
FOR i = 7 TO 12
time_data[i-7] = gps_data[i]
NEXT i
ENDIF


' Reset buffer
i = 0
ENDIF
'SEROUT2 GPS_TX, 84, ["Waiting...",10,13] 'added by myself for testing purposes
' Display time data
IF start_found = 1 THEN
SEROUT2 GPS_TX, 84, ["Time: ", time_data[0], time_data[1], ":", time_data[2], time_data[3], ":", time_data[4], time_data[5], 13, 10]
start_found = 0
ENDIF


GOTO main


It does not work, but I added this: serout2 GPS_TX, 84, [gps_char,","]
and it outputs series of chars and digits, and these digits do change, here's sample

,G,M,1,1,.,4,,,,,,,,,5,,,,*,
,N,A,8,3,9,,,,,4,
,$,G,,,0,2,7,,,,,0,,,,,,,6,
,P,A,,,,,,,,,


,P,A,,,,,,,,,,G,M,1,9,.,4,,,,,,,,,5,,,,*,
,N,A,8,4,9,,,,,4,
,$,G,,,2,0,7,,,,,0,,,,,,,6,

So what I'm doing wrong?
I tried to set GPS port speed to 4800 - it outputs garbage then.

Ioannis
- 14th July 2024, 20:38
First I would try Hserin and Hserout ONLY, because Serin and Serout are software commands and are slower. Besides they do not have any buffer, so I am pretty sure you loose characters from the data stream of the GPS miodule.

If the test passes then I would check the rest.

Ioannis

CuriousOne
- 14th July 2024, 21:16
Thanks.
I never used hardware serial port
according to the datasheet for 16F886, there are 4 pins dedicated to the MSSP moduie

RA5 - SS
RC3- SCK/SCL
RC4- SDI/SDA
RC5 - SDO

Which one should I use for serial GPS, as these seem to be for SPI/I2C ?

Ioannis
- 14th July 2024, 21:27
None of these.

We are talking about USART and not MSSP.

The pins of interest are RC7 as Usart Rx pin and RC6 as Usart Tx pin.

You have once to set the appropriate registers at the top of your program and start enjoy the speed and reliability of the serial port.



DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h '9600 baud rate, BRGH=1 @8MHz clock
DEFINE HSER_BAUD 9600
DEFINE HSER_SPBRG 25
DEFINE HSER_CLROERR 1


Ioannis

CuriousOne
- 14th July 2024, 21:47
I think that settings are incorrect, because
aska:
hserout ["Init:",10,13]
pause 200
goto aska

Outputs something not correct, like question marks.

DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h '9600 baud rate, BRGH=1 @8MHz clock
DEFINE HSER_BAUD 9600
DEFINE HSER_SPBRG 25
DEFINE HSER_CLROERR 1

these might need tuning?

Ioannis
- 14th July 2024, 21:57
The output is TTL logic. Meaning you have to use a RS-232 driver to use it with PC. Either a transistor or a MAX232 type chip.

Ioannis

CuriousOne
- 14th July 2024, 21:58
I'm using USB serial adapter with TTL logic, which works just fine with SEROUT2/SERIN2 statements.

CuriousOne
- 14th July 2024, 22:02
Fixed it
just tried all values for
DEFINE HSER_SPBRG 50
and 50 worked.

Now will try to read GPS :)

CuriousOne
- 14th July 2024, 22:07
But that does not work for GPS
reading junk again, and more weird junk :)

Ioannis
- 14th July 2024, 22:37
What is the output of GPS? TTL or RS232 level?

You have to use the appropriate. If the GPS has true (that is non inverting) TTL output then connect it directly to the PIC input. If it has a RS232 level then you may damage the PIC input and you have to use a converter from RS232 to TTL.

Ioannis

CuriousOne
- 15th July 2024, 06:05
https://www.addicore.com/products/neo-6m-gps-module-with-eeprom

I just read about 3.3V, will try it now...

CuriousOne
- 15th July 2024, 07:04
No change...

But it does output something like which starts with $GNGAO (changing numbers)

Ioannis
- 15th July 2024, 13:24
The module can tolerate up to 6V on Vdd but the Tx/Rx are 3.6 max. This can be a problem if your PIC is supplied at 5V.

The site you posted says:

" To use with a 5V logic device, such as an Arduino, we suggest level shifting the 5V TX signal using one of the following:
Two 1N4148 diodes in series between the TX pin on your 5V device and the RX pin on this GPS module (will drop voltage to ~3.6V)"

Page 8 of GPS datasheet
"1.8 Raw data
Raw data output is supported at an update rate of 5 Hz on the NEO-6T and NEO-6P. The UBX-RXM-RAW
message includes carrier phase with half-cycle ambiguity resolved, code phase and Doppler measurements,
which can be used in external applications that offer precision positioning, real-time kinematics (RTK) and
attitude sensing."

Note that the module can output 3 protocols, NMEA, UBX and RTCM. See 1.15 section for setting protocol. If you want NMEA make sure that you have configured it propelry, that is CFG_COM0 and CFG_COM1 pins at logic 1.

Also I would set CFG_GPS0 at logic 1 also for maximum performance and NO sleep.

Ioannis

CuriousOne
- 21st July 2024, 21:30
I connected it directly to the PC via USB<>TTL serial adapter and with own software, u-center, it works fine - locks satellites, displays position, displays time.
As I understand, I need to care for this line only:

$GNZDA,202437.000,21,07,2024,,*48

So I believe that issues are related with maybe voltage levels, I'll try to add some resistor dividers tomorrow and will check again.

CuriousOne
- 21st July 2024, 22:38
Fixed!

Issue was with AI error - it suggested GPRMC as sequence to wait, but in real life it is GNRMC.
Fixed it and everything works fine, even with software serial.