GPS Project: PIC18F26K22 or PIC18F46K22


Closed Thread
Results 1 to 40 of 69

Hybrid View

  1. #1
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Dear all,

    i have a question it maybe answered in lots of different threads.
    http://www.picbasic.co.uk/forum/showthread.php?t=10389

    http://www.picbasic.co.uk/forum/showthread.php?t=10265

    QUESTION: Can i have different baudrates on the 2 EUARTs? How could i change baudrate during start up in one of the EUART port?

    Have in mind that i use both of the EUARTs. One for the Display and one for the GPS.

    The GPS has a firmware with the following configuration:

    Baudrate: 9600 default
    Refresh rate: 1hz

    On the code i have configured the EUART for 38400, because i set the GPS externally with serial terminal at 38400. But GPS keeps the configs only if a backup battery is presented.

    So i came up with this problem.

    I need to send the following command first to SET the BAURATE at 38400, but with the EUART at 9600, because at that stage the GPS communicate only at 9600.

    Code:
    HSEROUT2 ["$PMTK251,38400*27",13,10]      ' 38400 boundrate, check MTK manual configuration.
    Then GPS as i tested i connected successfully, at 38400, but the following command cannot be sent before i change on the fly the EUART at 38400.

    Code:
    HSEROUT2 ["$PMTK220,100*2F",13,10]        ' 100(millisecond)=0.1(sec)-->1/0.1= 10Hz
    From the links above, i checked the way you are setting the new baudrate, and tried to do it as well but didnt really worked.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Yes, you can have different baudrate(s) on different UARTs and yes you can change it at any time you want. But, as the posts in the other thread says, to change it you can't use PBPs DEFINE HSER_BAUD because that's a compile time directive and not a runtime command.

    If you want to set or change the baudrate at runtime you need to set or change the registers manually. BAUDCON, SPBRG, SPBRGH most of the time. And remember that the register names are different for the second UART - BAUDCON2, SPBRG2 etc.

    Without seeing your code we can't say why what you did didn't work.

  3. #3
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Quote Originally Posted by HenrikOlsson View Post
    Yes, you can have different baudrate(s) on different UARTs and yes you can change it at any time you want. But, as the posts in the other thread says, to change it you can't use PBPs DEFINE HSER_BAUD because that's a compile time directive and not a runtime command.

    If you want to set or change the baudrate at runtime you need to set or change the registers manually. BAUDCON, SPBRG, SPBRGH most of the time. And remember that the register names are different for the second UART - BAUDCON2, SPBRG2 etc.

    Without seeing your code we can't say why what you did didn't work.
    Hi Henrik,

    i did have the DEFINEs on the code like this.

    Code:
    '*-----------------------------------------------------------------------------|
    '*                        |  --------------------- |                           |
    '*----------------------- | EUART 1 Configuration  | --------------------------|
    '*                        |  --------------------- |                           |
    '*-----------------------------------------------------------------------------|
    
            DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
            DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
            DEFINE HSER_CLROERR 1 ' Clear overflow automatically
            DEFINE HSER_SPBRG 160 ' 38400 Baud @ 64MHz, -0,08%
            SPBRGH = 1
            BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    
            
    
    
    
            
    '*-----------------------------------------------------------------------------|
    '*                        |  --------------------- |                           |
    '*----------------------- | EUART 2 Configuration  | --------------------------|
    '*                        |  --------------------- |                           |
    '*-----------------------------------------------------------------------------|
    
            '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 160 ' 38400 Baud @ 64MHz, -0,08%
            'SPBRGH2 = 1
            'BAUDCON2.3 = 1         ' Enable 16 bit baudrate generator
    
            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
            
    
    '------------------------------------------------------------------------------|
    '-----------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 500
    RCSTA2 = $90 ' Enable serial port & continuous receive
    TXSTA2 = $24 ' Enable transmit, BRGH = 1
    SPBRG2 = 160 ' 38400 Baud @ 64MHz, -0,08%
    HSEROUT2 ["$PMTK220,100*2F",13,10]        ' 100(millisecond)=0.1(sec)-->1/0.1= 10Hz
    On the first stage that i send the following command, to change the baudrate for the GPS, it works because both PIC and GPS are at the same rate.

    Code:
    B]HSEROUT2[/B] ["$PMTK251,38400*27",13,10]      ' 38400 boundrate, check MTK manual configuration
    then i guess with the following code that i change the rate on the PIC's port.

    Code:
    RCSTA2 = $90 ' Enable serial port & continuous receive
    TXSTA2 = $24 ' Enable transmit, BRGH = 1
    SPBRG2 = 160 ' 38400 Baud @ 64MHz, -0,08%
    then send the command which seems that it doesnt work.

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

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,705


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    if you are using the 16 bit baudrate generator
    BAUDCON2.3 = 1 ' Enable 16 bit baudrate generator


    then the baud rate is set using SPBRGHx and SPBRGx



    setting
    Code:
    SPBRG2 = 160 ' 38400 Baud @ 64MHz, -0,08%
    is only half the job
    Warning I'm not a teacher

  5. #5
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Quote Originally Posted by richard View Post
    if you are using the 16 bit baudrate generator
    BAUDCON2.3 = 1 ' Enable 16 bit baudrate generator


    then the baud rate is set using SPBRGHx and SPBRGx



    setting
    Code:
    SPBRG2 = 160 ' 38400 Baud @ 64MHz, -0,08%
    is only half the job
    I will check the code later today based on your given directions. thanks a lot.

    I might need to check and wait for the GPS responds and PIC port response. I will try to set a code, and if i need again your help i will keep you posted.

  6. #6
    Join Date
    Oct 2010
    Posts
    413


    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

  7. #7
    Join Date
    Aug 2011
    Posts
    460


    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

Similar Threads

  1. PIC18F46K22 config issue
    By LGabrielson in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th September 2012, 04:20
  2. Replies: 1
    Last Post: - 27th July 2008, 07:14
  3. Pic GPS project Demo
    By Art in forum GPS
    Replies: 0
    Last Post: - 28th October 2007, 04:05
  4. GPS project question
    By mjp130 in forum GPS
    Replies: 6
    Last Post: - 4th July 2007, 21:09
  5. gps project
    By chuckad in forum GPS
    Replies: 2
    Last Post: - 9th February 2007, 03: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