Trouble reading GPS from "NEO-6" module


+ Reply to Thread
Results 1 to 15 of 15
  1. #1
    Join Date
    Feb 2013
    Posts
    1,099

    Default Trouble reading GPS from "NEO-6" module

    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):

    Code:
    ;----[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.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,956


    Did you find this post helpful? Yes | No

    Default Re: Trouble reading GPS from "NEO-6" module

    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

  3. #3
    Join Date
    Feb 2013
    Posts
    1,099


    Did you find this post helpful? Yes | No

    Default Re: Trouble reading GPS from "NEO-6" module

    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 ?

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,956


    Did you find this post helpful? Yes | No

    Default Re: Trouble reading GPS from "NEO-6" module

    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.

    Code:
    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

  5. #5
    Join Date
    Feb 2013
    Posts
    1,099


    Did you find this post helpful? Yes | No

    Default Re: Trouble reading GPS from "NEO-6" module

    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?

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,956


    Did you find this post helpful? Yes | No

    Default Re: Trouble reading GPS from "NEO-6" module

    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

  7. #7
    Join Date
    Feb 2013
    Posts
    1,099


    Did you find this post helpful? Yes | No

    Default Re: Trouble reading GPS from "NEO-6" module

    I'm using USB serial adapter with TTL logic, which works just fine with SEROUT2/SERIN2 statements.

  8. #8
    Join Date
    Feb 2013
    Posts
    1,099


    Did you find this post helpful? Yes | No

    Default Re: Trouble reading GPS from "NEO-6" module

    Fixed it
    just tried all values for
    DEFINE HSER_SPBRG 50
    and 50 worked.

    Now will try to read GPS

  9. #9
    Join Date
    Feb 2013
    Posts
    1,099


    Did you find this post helpful? Yes | No

    Default Re: Trouble reading GPS from "NEO-6" module

    But that does not work for GPS
    reading junk again, and more weird junk

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,956


    Did you find this post helpful? Yes | No

    Default Re: Trouble reading GPS from "NEO-6" module

    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

  11. #11
    Join Date
    Feb 2013
    Posts
    1,099


    Did you find this post helpful? Yes | No

    Default Re: Trouble reading GPS from "NEO-6" module

    https://www.addicore.com/products/ne...le-with-eeprom

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

  12. #12
    Join Date
    Feb 2013
    Posts
    1,099


    Did you find this post helpful? Yes | No

    Default Re: Trouble reading GPS from "NEO-6" module

    No change...

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

  13. #13
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,956


    Did you find this post helpful? Yes | No

    Default Re: Trouble reading GPS from "NEO-6" module

    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

  14. #14
    Join Date
    Feb 2013
    Posts
    1,099


    Did you find this post helpful? Yes | No

    Default Re: Trouble reading GPS from "NEO-6" module

    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.

  15. #15
    Join Date
    Feb 2013
    Posts
    1,099


    Did you find this post helpful? Yes | No

    Default Re: Trouble reading GPS from "NEO-6" module

    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.

Similar Threads

  1. Replies: 17
    Last Post: - 13th July 2020, 15:20
  2. Replies: 0
    Last Post: - 14th November 2013, 03:32
  3. Replies: 3
    Last Post: - 15th October 2012, 08:06
  4. sending string to module GSM with character ""
    By volcane in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd May 2010, 02:26
  5. 16F88 - AD converter module always "ON"
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th September 2006, 12:11

Members who have read this thread : 12

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts