GPS Project: PIC18F26K22 or PIC18F46K22


Closed Thread
Results 1 to 40 of 69

Hybrid View

  1. #1
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Dear all,

    i did the following....

    Code:
    '*-----------------------------------------------------------------------------|
    '*                        |  --------------------- |                           |
    '*----------------------- | EUART 1 Configuration  | --------------------------|
    '*                        |  --------------------- |                           |
    '*-----------------------------------------------------------------------------|
            
            RCSTA = $90 ' Enable serial port & continuous receive
            TXSTA = $24 ' Enable transmit, BRGH = 1
            'CLROERR = 1 ' Clear overflow automatically
            SPBRG = 160 ' 38400 Baud @ 64MHz, -0,08%
            SPBRGH = 1
            BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
            
    '*-----------------------------------------------------------------------------|
    '*                        |  --------------------- |                           |
    '*----------------------- | EUART 2 Configuration  | --------------------------|
    '*                        |  --------------------- |                           |
    '*-----------------------------------------------------------------------------|
    
            RCSTA2 = $90 ' Enable serial port & continuous receive
            TXSTA2 = $24 ' Enable transmit, BRGH = 1
            'CLROERR2 1 ' Clear overflow automatically
            SPBRG2 = 130 ' 9600 Baud @ 64MHz, -0,02%
            SPBRGH2 = 6
            BAUDCON2.3 = 1         ' Enable 16 bit baudrate generator
            
    
    '------------------------------------------------------------------------------|
    '-----------sent a sentence to gps, this is not working at the moment----------|
    '------------------------------------------------------------------------------|
    ' When the GPS Module is POWERED ON, then the following sentenses are received. 
    
    '          $PMTK011,MTKGPS*08
    '          $PMTK010,001*2E
    '          $PMTK010,002*2D   
    
    pause 800 
    HSEROUT2 ["$PMTK251,38400*27",13,10]      ' 38400 boundrate, check MTK manual configuration
    pause 800
    
    SPBRG2 = 160 ' 38400 Baud @ 64MHz, -0,08%
    Pause 500
    
    HSEROUT2 ["$PMTK220,100*2F",13,10]        ' 100(millisecond)=0.1(sec)-->1/0.1= 10Hz
    pause 100
    It works the part of a baudrate change, when i send the command to the gps

    Code:
    HSEROUT2 ["$PMTK251,38400*27",13,10]      ' 38400 boundrate, check MTK manual configuration
    pause 800
    but i think the following it goes to GPS but for some reason is not set.

    Code:
    HSEROUT2 ["$PMTK220,100*2F",13,10]        ' 100(millisecond)=0.1(sec)-->1/0.1= 10Hz
    pause 100

  2. #2
    Join Date
    Aug 2011
    Posts
    415


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    When you switch the baudrate you have to set both SPBRG2 and SPBRGH2.

    Try:
    Code:
    SPBRG2 = 160 ' 38400 Baud @ 64MHz, -0,08%
    SPBRGH2 = 1
    Pause 500

  3. #3
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Quote Originally Posted by tumbleweed View Post
    When you switch the baudrate you have to set both SPBRG2 and SPBRGH2.

    Try:
    Code:
    SPBRG2 = 160 ' 38400 Baud @ 64MHz, -0,08%
    SPBRGH2 = 1
    Pause 500
    It worked!!! I will post later on what i have done up to now. Maybe i need to set up a small indication when those commands are set. So i know that program is working up to that stage.

    This is the code for changing the baudrate to GPS and the hz rate at 10Hz at the NMEA data.

    Code:
    '*-----------------------------------------------------------------------------|
    '*                        |  --------------------- |                           |
    '*----------------------- | EUART 1 Configuration  | --------------------------|
    '*                        |  --------------------- |                           |
    '*-----------------------------------------------------------------------------|
            
            RCSTA = $90 ' Enable serial port & continuous receive
            TXSTA = $24 ' Enable transmit, BRGH = 1
            'CLROERR = 1 ' Clear overflow automatically
            SPBRG = 160 ' 38400 Baud @ 64MHz, -0,08%
            SPBRGH = 1
            BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
            
    '*-----------------------------------------------------------------------------|
    '*                        |  --------------------- |                           |
    '*----------------------- | EUART 2 Configuration  | --------------------------|
    '*                        |  --------------------- |                           |
    '*-----------------------------------------------------------------------------|
    
            RCSTA2 = $90 ' Enable serial port & continuous receive
            TXSTA2 = $24 ' Enable transmit, BRGH = 1
            'CLROERR2 1 ' Clear overflow automatically
            SPBRG2 = 130 ' 9600 Baud @ 64MHz, -0,02%
            SPBRGH2 = 6
            BAUDCON2.3 = 1         ' Enable 16 bit baudrate generator
            
    
    '------------------------------------------------------------------------------|
    '-----------sent a sentence to gps, this is not working at the moment----------|
    '------------------------------------------------------------------------------|
    ' When the GPS Module is POWERED ON, then the following sentenses are received. 
    
    '          $PMTK011,MTKGPS*08
    '          $PMTK010,001*2E
    '          $PMTK010,002*2D   
    
    pause 800 
    HSEROUT2 ["$PMTK251,38400*27",13,10]      ' 38400 boundrate, check MTK manual configuration
    pause 800
    
    SPBRG2 = 160 ' 38400 Baud @ 64MHz, -0,08%
    SPBRGH2 = 1
    Pause 500
    
    HSEROUT2 ["$PMTK220,100*2F",13,10]        ' 100(millisecond)=0.1(sec)-->1/0.1= 10Hz
    pause 100

  4. #4
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Dear all,

    i need you help.

    After removing all the DEFINEs and use only the following

    Code:
    'RCSTA2 = $90 ' Enable serial port & continuous receive
    'TXSTA2 = $24 ' Enable transmit, BRGH = 1
    'DEFINE HSER_CLROERR2 1 ' Clear overflow automatically
    'SPBRG2 = 130 ' 9600 Baud @ 64MHz, -0,02%
    'SPBRGH2 = 6
    'BAUDCON2.3 = 1         ' Enable 16 bit baudrate generator
    and for changing the baudrate and the frequency for the Second Serial,

    Code:
    pause 800 
    HSEROUT2 ["$PMTK251,38400*27",13,10]      ' 38400 boundrate, check MTK manual configuration
    pause 800
    
    SPBRG2 = 160 ' 38400 Baud @ 64MHz, -0,08%
    SPBRGH2 = 1
    Pause 500
    
    ;HSEROUT2 ["$PMTK314,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0*29",13,10]
    HSEROUT2  ["$PMTK314,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28",13,10]
    pause 100
    
    HSEROUT2 ["$PMTK220,100*2F",13,10]        ' 100(millisecond)=0.1(sec)-->1/0.1= 10Hz
    pause 100
    I found out that on SERIAL TERMINAL on the computer of course i see the data coming from the GPS but unfortunately when i connect an LCD to PIC using the first Serial, the data cannot be displayed.

    It seems that when i use

    Code:
    HSERIN2[wait("$GPRMC")
    the data cannot be read from the GPS to the RX of the PIC.

    I tried to check if there is a problem with the LCD, but i can send text to the LCD.

    I tried to check and use only the DEFINEs with 9600 because the default for the GPS is 9600 and it worked.

    so when i do not use the defines, it looks like that RX port on the PIC doesnt work.

    Could you please help?

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,838


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    I don't know about other members of the forum, but I got confused.

    Best throw in both codes that work and don't work.

    Do they compile OK?

    Are you sure about your connections?

    Ioannis

  6. #6
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Ioanni,

    thanks for your reply.

    The problem is when i use the code to change on the fly as of the guys on the forum advice, without using the "DEFINE" word.

    So using the registers like in the following code:

    Code:
    'RCSTA2 = $90 ' Enable serial port & continuous receive
    'TXSTA2 = $24 ' Enable transmit, BRGH = 1
    'DEFINE HSER_CLROERR2 1 ' Clear overflow automatically
    'SPBRG2 = 130 ' 9600 Baud @ 64MHz, -0,02%
    'SPBRGH2 = 6
    'BAUDCON2.3 = 1         ' Enable 16 bit baudrate generator
    and later in order to change the baudrate i use the following:

    Code:
    pause 800 
    HSEROUT2 ["$PMTK251,38400*27",13,10]      ' 38400 boundrate, check MTK manual configuration
    pause 800
    
    SPBRG2 = 160 ' 38400 Baud @ 64MHz, -0,08%
    SPBRGH2 = 1
    Pause 500
    
    ;HSEROUT2 ["$PMTK314,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0*29",13,10]
    HSEROUT2  ["$PMTK314,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28",13,10]
    pause 100
    
    HSEROUT2 ["$PMTK220,100*2F",13,10]        ' 100(millisecond)=0.1(sec)-->1/0.1= 10Hz
    pause 100
    The GPS gets the command and set correctly the new configuration.

    So up to here we are fine. I checked this by using a Serial Terminal and i see that both Baudrate and frequency have changed.

    That means that TX is working well, for the first command to the GPS

    Code:
    HSEROUT2 ["$PMTK251,38400*27",13,10]      ' 38400 boundrate, check MTK manual configuration
    pause 800
    and changing on the fly the Baudrate the following command to GPS is working fine as well with the NEW baudrate.

    Code:
    HSEROUT2  ["$PMTK314,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28",13,10]
    pause 100
    
    HSEROUT2 ["$PMTK220,100*2F",13,10]        ' 100(millisecond)=0.1(sec)-->1/0.1= 10Hz
    pause 100
    [/CODE]

    Now what is the problem.

    I used a uLCD to send the VTG and RCM data to the display as i have done in the past using both SEROUT and HSEROUT2 command (for the HSEROUT2 i used the following code with the "DEFINE" and worked well)

    Code:
    'DEFINE HSER2_RCSTA 90h ' Enable serial port & continuous receive
            'DEFINE HSER2_TXSTA 24h ' Enable transmit, BRGH = 1
            'DEFINE HSER2_CLROERR 1 ' Clear overflow automatically
            'DEFINE HSER2_SPBRG 130 ' 9600 Baud @ 64MHz, -0,02%
            'SPBRGH2 = 6
            'BAUDCON2.3 = 1         ' Enable 16 bit baudrate generator
    Now using the registers without the "DEFINEs" the RX on the PIC seems that it doesnt work, something like it is closed or cannot read data from GPS.

    Forgot to mention that 2 hours now i have tried most of the different settings for the

    Code:
    BAUDCON2 = %xxxxxxxx
    without any luck.

  7. #7
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Compile is ok, the same circuit as when the code is working with the "DEFINE" code.

    Something is wrong with the new code that i change the baudrate on the fly.

    there is something going really wrong. Maybe i need to give more PAUSE time?

    I try that as well.

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,838


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Page 281 of the K22 PIC has all the settings of the BRGH, BRG16, SPBRGx in relation to the system Clock.

    Also, depending whether you have RS232 driver or not you have to set or reset the BAUDCONx bits 4 and 5.

    If you will use on both Rx and Tx pins a driver (like the MAX232) then these bits should be 0. If you connect directly to another TTL serial port then these bits should be 1.

    Ioannis

Similar Threads

  1. PIC18F46K22 config issue
    By LGabrielson in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th September 2012, 03:20
  2. Replies: 1
    Last Post: - 27th July 2008, 06:14
  3. Pic GPS project Demo
    By Art in forum GPS
    Replies: 0
    Last Post: - 28th October 2007, 03:05
  4. GPS project question
    By mjp130 in forum GPS
    Replies: 6
    Last Post: - 4th July 2007, 20:09
  5. gps project
    By chuckad in forum GPS
    Replies: 2
    Last Post: - 9th February 2007, 02:52

Members who have read this thread : 1

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