2nd hardware UART


+ Reply to Thread
Results 1 to 28 of 28

Hybrid View

  1. #1
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    169

    Default 2nd hardware UART

    Has anyone here used the 2nd hardware UART on a PIC processor before? Are there any tricks to it? I, for the life of me, can't get the 2nd one working at all. 1st UART works fine, but no joy with the 2nd. Tried both the suggested PBPs defines and doing it manually with register settings suggested in the datasheet. Processor is a PIC18F26K83. Says it's supposed to have 2 (the way I read it)???

    Thanks for any tips,

    Troy

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,642


    Did you find this post helpful? Yes | No

    Default Re: 2nd hardware UART

    Thanks for any tips,
    my tip
    it works just fine if you do it properly
    Warning I'm not a teacher

  3. #3
    Join Date
    Aug 2011
    Posts
    453


    Did you find this post helpful? Yes | No

    Default Re: 2nd hardware UART

    You might want to post what you've tried so we can give you some 'tips'

  4. #4
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    169


    Did you find this post helpful? Yes | No

    Default Re: 2nd hardware UART

    Quote Originally Posted by tumbleweed View Post
    You might want to post what you've tried so we can give you some 'tips'
    Code:
    OSCFRQ = %1000 '64Mhz
    
    Define OSC 64
    
    ' Set receive register to receiver enabled
    ' Set transmit register to transmitter enabled
    DEFINE HSER_RXREG PORTC
    DEFINE HSER_RXBIT 4
    DEFINE HSER_TXREG PORTC
    DEFINE HSER_TXBIT 5
    DEFINE HSER_BAUD 9600
    
    ' Set receive register to receiver enabled
    ' Set transmit register to transmitter enabled
    'DEFINE HSER2_RXREG PORTB
    'DEFINE HSER2_RXBIT 3
    'DEFINE HSER2_TXREG PORTB
    'DEFINE HSER2_TXBIT 0
    'DEFINE HSER2_BAUD 9600
    
    'This works
    hSerout ["Test",13,10]
    
    'This doesn't
    hSerout2 ["Test",13,10]

  5. #5
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    169


    Did you find this post helpful? Yes | No

    Default Re: 2nd hardware UART

    Apologies, here is the actual code:

    Code:
    OSCFRQ = %1000 '64Mhz
    
    Define OSC 64
    
    PRECISION  CON 8 SYSTEM  '8 byte = 64 bit precision
    INCLUDE "N-Bit_Math.pbp"
    
    DEFINE HSER2_RXREG PORTB
    DEFINE HSER2_RXBIT 3
    DEFINE HSER2_TXREG PORTB
    DEFINE HSER2_TXBIT 0
    DEFINE HSER2_BAUD 9600
    
    DEFINE HSER_RXREG PORTC
    DEFINE HSER_RXBIT 4
    DEFINE HSER_TXREG PORTC
    DEFINE HSER_TXBIT 5
    DEFINE HSER_BAUD 9600
     
    ANSELA = %00000000 'Everything Digital
    ANSELB = %00000000 'Everything Else Digital
    ANSELC = %00000000 'Everything Else Digital
    
    TRISB.0 = 0 
    TRISB.3 = 1 
    TRISC.4 = 1 
    TRISC.5 = 0 
    
    'works
    hSerout ["Test",13,10]
    
    'doesn't work
    hSerout2 ["Test",13,10]

  6. #6
    Join Date
    Nov 2005
    Posts
    35


    Did you find this post helpful? Yes | No

    Default Re: 2nd hardware UART

    I'm far from an expert in this space. And haven't used the second USART port on a PIC
    But maybe PMD5 register for UART2 isn't being set correctly by picbasic??

    bit 5 U2MD: Disable UART2 bit
    1 = UART2 module disabled
    0 = UART2 module enabled
    bit 4 U1MD: Disable UART1 bit
    1 = UART1 module disabled
    0 = UART1 module enabled

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,642


    Did you find this post helpful? Yes | No

    Default Re: 2nd hardware UART

    you don't appear to have set the portb pins used to digital [anselb =$f6]

    or not

    mcc sets the involved registers like this to match your settings

    TRISB = 0xFE;
    ANSELB = 0xF6;
    U2RXPPS = 0x0B; //RB3->UART2:RX2;
    RB0PPS = 0x16; //RB0->UART2:TX2;
    U2P1L = 0x00;
    U2P1H = 0x00;
    U2P2L = 0x00;
    U2P2H = 0x00;
    U2P3L = 0x00;
    U2P3H = 0x00;
    U2CON0 = 0xB0;
    U2CON1 = 0x80;
    U2CON2 = 0x00;
    U2BRGL = 0x82;
    U2BRGH = 0x06;
    U2FIFO = 0x00;
    U2UIR = 0x00;
    U2ERRIR = 0x00;
    U2ERRIE = 0x00;
    Last edited by richard; - 13th August 2024 at 01:05. Reason: oh you posted again when i reading the data sheet
    Warning I'm not a teacher

  8. #8
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    169


    Did you find this post helpful? Yes | No

    Default Re: 2nd hardware UART

    I'm guessing this is a reply to my 1st code post which I inadvertently cut the TRIS settings in my (hastily) attempt for reader friendly pruning, but I can assure you every port was set to digital all the time. What's more, the 2nd UART was originally configured to the same pins as the 1st. When my head was too sore from banging against that wall, I switched the 1st UART to those pins and voila, they worked.

    Troy

    Quote Originally Posted by richard View Post
    you don't appear to have set the portb pins used to digital [anselb =$f6]

    or not

    mcc sets the involved registers like this to match your settings

    TRISB = 0xFE;
    ANSELB = 0xF6;
    U2RXPPS = 0x0B; //RB3->UART2:RX2;
    RB0PPS = 0x16; //RB0->UART2:TX2;
    U2P1L = 0x00;
    U2P1H = 0x00;
    U2P2L = 0x00;
    U2P2H = 0x00;
    U2P3L = 0x00;
    U2P3H = 0x00;
    U2CON0 = 0xB0;
    U2CON1 = 0x80;
    U2CON2 = 0x00;
    U2BRGL = 0x82;
    U2BRGH = 0x06;
    U2FIFO = 0x00;
    U2UIR = 0x00;
    U2ERRIR = 0x00;
    U2ERRIE = 0x00;

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,642


    Did you find this post helpful? Yes | No

    Default Re: 2nd hardware UART

    mcc suggests different baud-gen figures that what you have used
    mcc
    U2BRGL = 0x82;
    U2BRGH = 0x06;
    Warning I'm not a teacher

  10. #10
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    169


    Did you find this post helpful? Yes | No

    Default Re: 2nd hardware UART

    Quote Originally Posted by richard View Post
    mcc suggests different baud-gen figures that what you have used
    mcc
    U2BRGL = 0x82;
    U2BRGH = 0x06;
    Yes Richard, I realise that *if* I was operating in 9600 baud, but I noted at the top of that register post I was setting everything to 115200 originally and that pruned snippet of the register setting code was copy-&-pasted from my original attempts at getting this to work. Apologies for not updating those values to make them consistent with the previous posts utilising PBP defines for the config. I did have my terminal receiver running on the correct baud for the settings irrespective.

    One thing I've noticed since is the Hserout2 statement is hanging/crashing my code.

    Sending a character to the U2TXB register directly *does* work - at least at 9600 baud.

    Troy

Similar Threads

  1. PID-filter routine (2nd try).
    By HenrikOlsson in forum Code Examples
    Replies: 131
    Last Post: - 3rd October 2018, 07:53
  2. Setup baudrate on hardware uart on 18F4520
    By Pedro Pinto in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 25th August 2010, 00:31
  3. crucial error in a 90% working hardware uart
    By mimmmis in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 23rd September 2008, 14:18
  4. Serial Port Complete 2nd Edition
    By Bruce in forum Serial
    Replies: 4
    Last Post: - 8th November 2007, 15:28
  5. 2nd Order Digital Filter for 24-bit
    By sefayil in forum mel PIC BASIC
    Replies: 0
    Last Post: - 2nd December 2005, 21:55

Members who have read this thread : 13

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