Announcement

Collapse
No announcement yet.

HSEROUT Woes with PIC18F67K40

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • HSEROUT Woes with PIC18F67K40

    Hello,

    I am having trouble trying to get the correct baud timing using HSEROUT on 18F67K40. I am using 16Mhz oscillator and am trying for 9600 baud using the following settings:

    RC1STA = %10010000
    TX1STA = %00100000
    SP1BRGH = 0
    SP1BRGL = 25
    BAUDCON1.3 = 0

    All that I am getting is jibber out.

    If I try the following on the same pin all is well:

    serout2 PORTC.6,84,["Com1",10,13]

    Any help greatly appreciated.

    Regards,

    Andy

  • #2
    Hi Andy,
    There's an example in the datasheet for 9600 baud at 16MHz oscillator frequency and they arrive at BRG=25 with 8bit baudrate generator - which as far as I can see is what you have in your code so I can't immediately see/say what's wrong. I did plug your requirments into PICMulticalc and it suggests the following (using 16bit baudrate generator). Try that for starters, if it works you can try figuring out why your original values doesn't.

    Code:
    RCSTA = $90   ' Enable serial port & continuous receive
    TXSTA = $24   ' Enable transmit, BRGH = 1
    SPBRG = 160   ' 9600 Baud @ 16MHz, -0,08%
    SPBRGH = 1
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    /Henrik.

    Comment


    • #3
      Hi Henrik,

      I have tried both settings and still no go. I also used PicMultiCalc by Mister E to create the Defines but it still doesn't work. I know the oscillator and hardware is good because all of my other settings work ok and I can use Serout at 9600 on the same physical pin and all is good.

      I even tried directly setting the registers using the naming conventions in the datasheet eg. RC1STA, TX1STA, SP1BRGH etc.

      I am still missing something...

      I will strip down my code and post it so that everyone can take a look and offer advice. I am on the brink of chucking in the towel on this one but I'll hang in there and try and resolve it. This device has a very unique feature set that is very useful to me. I'd like to overcome the issues if I can.

      Andy

      Comment


      • #4
        Here is the code:

        Code:
        #CONFIG
            __CONFIG _CONFIG1L, _FEXTOSC_HS_1L
            __CONFIG _CONFIG1H, _FCMEN_OFF_1H & _CLKOUTEN_OFF_1H
            __CONFIG _CONFIG2L, _PWRTE_ON_2L   
            __CONFIG _CONFIG2H, _XINST_OFF_2H
            __CONFIG _CONFIG3L, _WDTE_OFF_3L
            __CONFIG _CONFIG4H, _LVP_OFF_4H    
        
        #ENDCONFIG
        
        DEFINE OSC 16
        
            RC1STA = $90        '%10010000
            TX1STA = $24        '%00100000
            SP1BRGH = 1
            SP1BRGL = 160
            BAUD1CON.3 = 1     'BRG16: 16-bit Baud Rate Generator bit
        
        ' -- Inputs
        
        
        ' -- Outputs
        
        
        ' -- Variables
            'Bits
        
            'Bytes
        
            'Words
        
        ' -----------------------------------    
        
            TRISA = %11001110
            TRISB = %00000000
            TRISC = %10000010
            TRISD = %00101011
            TRISE = %00000110
            TRISF = %11111000
            TRISG = %10011101
            TRISH = %00000000
        
        
        main:
        
            'serout2 PORTC.6,84,["Com1",10,13]
            hserout ["ABCD",10,13]
            pause 100
            goto main

        Comment


        • #5
          I wonder if the problem has to do with the PPS feature. If the port was completely silent I would say that was probably the case but since you're apparently getting "something" out of it I'm not sure. If you look at the Pin Allocation table in the datasheet you'll find two comments related to the EUSART pins:
          2: All output signals shown in this row are PPS remappable. These signals may be mapped to output onto one of several PORTx pin options as described in Register 17-2

          3: This is a bidirectional signal. For normal module operation, the firmware should map this signal to the same pin in both the PPS input and PPS output registers.
          /Henrik.

          Comment


          • #6
            That is a good point. There are some notes about this series of parts in the PBP folder. I re-read them again and have added the PPS defines to the code. These are the same as the default settings, which, according to the info in that file, would be used if no defines were specified.

            The changes have been made and the amended code is below. Unfortunately there is no change to the outcome. I have checked the output again and there is no activity on the port with this code. It's been a long day..

            Code:
            #CONFIG
                __CONFIG _CONFIG1L, _FEXTOSC_HS_1L
                __CONFIG _CONFIG1H, _FCMEN_OFF_1H & _CLKOUTEN_OFF_1H
                __CONFIG _CONFIG2L, _PWRTE_ON_2L   
                __CONFIG _CONFIG2H, _XINST_OFF_2H
                __CONFIG _CONFIG3L, _WDTE_OFF_3L
                __CONFIG _CONFIG4H, _LVP_OFF_4H    
            
            #ENDCONFIG
            
            DEFINE OSC 16
            
            DEFINE HSER_RXREG PORTC
            DEFINE HSER_RXBIT 7
            DEFINE HSER_TXREG PORTC
            DEFINE HSER_TXBIT 6
            
                RC1STA = $90        '%10010000
                TX1STA = $24        '%00100000
                SP1BRGH = 1
                SP1BRGL = 160
                BAUD1CON.3 = 1     'BRG16: 16-bit Baud Rate Generator bit
            
            ' -- Inputs
            
            
            ' -- Outputs
            
            
            ' -- Variables
                'Bits
            
                'Bytes
            
                'Words
            
            ' -----------------------------------    
            
                TRISA = %11001110
                TRISB = %00000000
                TRISC = %10000010
                TRISD = %00101011
                TRISE = %00000110
                TRISF = %11111000
                TRISG = %10011101
                TRISH = %00000000
            
            
            main:
            
                'serout2 PORTC.6,84,["Com1",10,13]
                hserout ["ABCD",10,13]
                pause 100
                goto main

            Comment


            • #7
              default tx1 is portc.6

              sure its not the tx polarity ,it can bet set either way with baud1con.SCKP

              Comment


              • #8
                Hi Richard,

                I think I tried changing the polarity earlier today. I have made the changes and attached amended code below. Polarity must be true as there is a MAX232 type driver in the circuit. The is no change in the operation - still no output.

                Code:
                #CONFIG
                    __CONFIG _CONFIG1L, _FEXTOSC_HS_1L
                    __CONFIG _CONFIG1H, _FCMEN_OFF_1H & _CLKOUTEN_OFF_1H
                    __CONFIG _CONFIG2L, _PWRTE_ON_2L  
                    __CONFIG _CONFIG2H, _XINST_OFF_2H
                    __CONFIG _CONFIG3L, _WDTE_OFF_3L
                    __CONFIG _CONFIG4H, _LVP_OFF_4H    
                
                #ENDCONFIG
                
                DEFINE OSC 16
                
                DEFINE HSER_RXREG PORTC
                DEFINE HSER_RXBIT 7
                DEFINE HSER_TXREG PORTC
                DEFINE HSER_TXBIT 6
                
                    RC1STA = $90        '%10010000
                    TX1STA = $24        '%00100000
                    SP1BRGH = 1
                    SP1BRGL = 160
                    BAUD1CON.3 = 1     'BRG16: 16-bit Baud Rate Generator bit
                    BAUD1CON.4 = 0     'SCKP: Synchronous Clock Polarity Select bit
                                       '1 = Idle state for transmit (TX) is a low level (transmit data inverted)
                                       '0 = Idle state for transmit (TX) is a high level (transmit data is non-inverted)
                
                ' -- Inputs
                
                
                ' -- Outputs
                
                
                ' -- Variables
                    'Bits
                
                    'Bytes
                
                    'Words
                
                ' -----------------------------------    
                
                    TRISA = %11001110
                    TRISB = %00000000
                    TRISC = %10000010
                    TRISD = %00101011
                    TRISE = %00000110
                    TRISF = %11111000
                    TRISG = %10011101
                    TRISH = %00000000
                
                
                main:
                
                    'serout2 PORTC.6,84,["Com1",10,13]
                    hserout ["ABCD",10,13]
                    pause 100
                    goto main

                Comment


                • #9
                  try
                  TRISC = %11000010
                  some chips insist on letting the eusart set the pin to an output and want the tris bit left set

                  Comment


                  • #10
                    Hi Richard,

                    Ok - changed to TRISC = %11000010 and now there is activity on the port, however it is a jibber of random characters.

                    Amended code below.

                    Code:
                    #CONFIG
                        __CONFIG _CONFIG1L, _FEXTOSC_HS_1L
                        __CONFIG _CONFIG1H, _FCMEN_OFF_1H & _CLKOUTEN_OFF_1H
                        __CONFIG _CONFIG2L, _PWRTE_ON_2L   
                        __CONFIG _CONFIG2H, _XINST_OFF_2H
                        __CONFIG _CONFIG3L, _WDTE_OFF_3L
                        __CONFIG _CONFIG4H, _LVP_OFF_4H    
                    
                    #ENDCONFIG
                    
                    DEFINE OSC 16
                    
                    DEFINE HSER_RXREG PORTC
                    DEFINE HSER_RXBIT 7
                    DEFINE HSER_TXREG PORTC
                    DEFINE HSER_TXBIT 6
                    
                        RC1STA = $90        '%10010000
                        TX1STA = $24        '%00100000
                        SP1BRGH = 1
                        SP1BRGL = 160
                        BAUD1CON.3 = 1     'BRG16: 16-bit Baud Rate Generator bit
                        BAUD1CON.4 = 0     'SCKP: Synchronous Clock Polarity Select bit
                                           '1 = Idle state for transmit (TX) is a low level (transmit data inverted)
                                           '0 = Idle state for transmit (TX) is a high level (transmit data is non-inverted)
                    
                    ' -- Inputs
                    
                    
                    ' -- Outputs
                    
                    
                    ' -- Variables
                        'Bits
                    
                        'Bytes
                    
                        'Words
                    
                    ' -----------------------------------    
                    
                        TRISA = %11001110
                        TRISB = %00000000
                        TRISC = %11000010
                        TRISD = %00101011
                        TRISE = %00000110
                        TRISF = %11111000
                        TRISG = %10011101
                        TRISH = %00000000
                    
                    
                    main:
                    
                        'serout2 PORTC.6,84,["Com1",10,13]
                        hserout ["ABCD",10,13]
                        pause 100
                        goto main

                    Comment


                    • #11
                      tx polarity now ?

                      Comment


                      • #12
                        Changed BAUD1CON.4 = 0 to BAUD1CON.4 = 1 and still jibber

                        Comment


                        • #13
                          when you use a partial config like this

                          Code:
                          #CONFIG
                              __CONFIG _CONFIG1L, _FEXTOSC_HS_1L
                              __CONFIG _CONFIG1H, _FCMEN_OFF_1H & _CLKOUTEN_OFF_1H
                              __CONFIG _CONFIG2L, _PWRTE_ON_2L  
                              __CONFIG _CONFIG2H, _XINST_OFF_2H
                              __CONFIG _CONFIG3L, _WDTE_OFF_3L
                              __CONFIG _CONFIG4H, _LVP_OFF_4H   
                          
                          #ENDCONFIG
                          all the unmentioned settings revert to erased blank chip values, not pbp defaults as you may expect
                          maybe one of these is upsetting the show.
                          refer to your device include files to check if anything else is required .
                          [I don't have 3.1 yet so I can't check this]

                          other than that I have nothing, osc seems correct, eusart settings look correct , tris ok
                          there is no analog for that pin
                          time to retire {hurt}

                          Comment


                          • #14
                            I'll keep playing and see if I can make any headway.

                            I'm always willing to learn - is there a better suggestion for setting the config bits?

                            Comment


                            • #15
                              not really, meconfig is not being maintained . the inc file should be pretty clear about whats there and what the pbp defa's are
                              its in the pbp**/device_reference folder

                              Comment

                              Working...
                              X