Serial Baudrate 115200


Closed Thread
Results 1 to 36 of 36

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Serial Baudrate 115200 using HSEROUT - how to?

    I'm having difficulties making my PIC's HSEROUT working at all. I need to get 115200bps.

    I can reach 38400bps with the SEROUT2 command without any trouble.

    For 115200bps, I go with HSEROUT. I use the MCS Serial Communicator and the PIC has a 20MHz crystal.

    SEROUT2 is okay, HSEROUT is not working at all (not even @1200bps).

    I've been trying to make it work for hours and hours, redoing the cabling (see picture) different ways as suggested in other threads, modifying the code also many times but no success until now. I just always get garbage on the serial terminal's screen.
    Code:
    ' SEROUT2
      
    ' PIC 16F690 Fuses
    @ __Config _FCMEN_OFF &_IESO_OFF &_BOR_OFF &_CPD_OFF &_CP_OFF &_MCLRE_OFF &_PWRTE_OFF &_WDT_OFF &_HS_OSC
     
    OPTION_REG = 000000 'PORT A&B Pull-Ups (look WPUA & WPUB)
    ADCON0     = 000000 'A/D Module
    ANSEL      = 000000 'Select analog inputs Channels 0 to 7
    ANSELH     = 000000 'Select analog inputs Channels 8 to 11
    INTCON     = 000000 'INTERRUPT Control
    'WPUA       = 000000 'Select PORTA weak pull-ups
    'IOCA       = 000000 'Interrupt On Change selection
    CM1CON0    = 000000 'Comparator1 Module
    CM2CON0    = 000000 'Comparator2 Module
    TRISA      = 000000 'Set Input/Output (0 to 5)
    PORTA      = 000000 'Ports High/Low (0 to 5)
    TRISB      = 000000 'Set Input/Output (4 to 7)
    PORTB      = 000000 'Ports High/Low (4 to 7)
    TRISC      = 000000 'Set Input/Output (0 to 7)
    PORTC      = 000000 'Ports High/Low (0 to 7)
     
    '-------------------------------------------------------------------------------
    ' DEFINEs
    DEFINE OSC 20
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
     
    '-------------------------------------------------------------------------------
    LED1    VAR PORTA.2
    Counter VAR WORD
    Counter = 0
     
    TEST:
      TOGGLE LED1
      'serout2 PORTB.7,16416,[dec counter,13,10]'19200 DIN with MAX232
      SEROUT2 PORTB.7,16390,[DEC Counter,13,10]'38400 DIN with MAX232
      PAUSE 500
      Counter = Counter + 1
      GOTO TEST
      
      END
    Code:
    ' HSEROUT
      
    ' PIC 16F690 Fuses
    @ __Config _FCMEN_OFF &_IESO_OFF &_BOR_OFF &_CPD_OFF &_CP_OFF &_MCLRE_OFF &_PWRTE_OFF &_WDT_OFF &_HS_OSC
     
    OPTION_REG = 000000 'PORT A&B Pull-Ups (look WPUA & WPUB)
    ADCON0     = 000000 'A/D Module
    ANSEL      = 000000 'Select analog inputs Channels 0 to 7
    ANSELH     = 000000 'Select analog inputs Channels 8 to 11
    INTCON     = 000000 'INTERRUPT Control
    'WPUA       = 000000 'Select PORTA weak pull-ups
    'IOCA       = 000000 'Interrupt On Change selection
    CM1CON0    = 000000 'Comparator1 Module
    CM2CON0    = 000000 'Comparator2 Module
    TRISA      = 000000 'Set Input/Output (0 to 5)
    PORTA      = 000000 'Ports High/Low (0 to 5)
    TRISB      = 000000 'Set Input/Output (4 to 7)
    PORTB      = 000000 'Ports High/Low (4 to 7)
    TRISC      = 000000 'Set Input/Output (0 to 7)
    PORTC      = 000000 'Ports High/Low (0 to 7)
     
    '-------------------------------------------------------------------------------
    ' DEFINEs
    DEFINE OSC 20
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_BAUD 19200
    'DEFINE HSER_SPBRG 64
    DEFINE HSER_CLOERR 1
     
    '-------------------------------------------------------------------------------
    LED1    VAR PORTA.2
    Counter VAR WORD
    Counter = 0
     
    TEST:
      TOGGLE LED1
      HSEROUT [DEC Counter,13,10]
      PAUSE 500
      Counter = Counter + 1
      GOTO TEST
      
      END  

    There's a MAX232 close to the PIC making me think the lines are as short as possible. But is it enough on the hw side?
    Name:  SerialCom.jpg
Views: 2012
Size:  65.6 KB
    Last edited by flotulopex; - 16th October 2011 at 14:56.
    Roger

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: Serial Baudrate 115200 using HSEROUT - how to?

    Try changing

    DEFINE
    HSER_TXSTA 24h to

    DEFINE HSER_TXSTA 20h
    Charles Linquist

  3. #3
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Re: Serial Baudrate 115200 using HSEROUT - how to?

    I tried this already: no success.

    Still looks like this:

    Name:  SerialCom1.jpg
Views: 1873
Size:  35.4 KB
    Roger

  4. #4
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: Serial Baudrate 115200 using HSEROUT - how to?

    I was referring to you trying to run 19200. That was what your code above referenced.

    If you want to run 115K baud -

    From Mr. E's Multi-Calc:

    RCSTA1 = $90 ' Enable serial port & continuous receive
    TXSTA1 = $24 ' Enable transmit, BRGH = 1
    SPBRG1 = 42 ' 115200 Baud @ 20MHz, 0.94%
    SPBRGH1 = 0
    BAUDCON1.3 = 1 ' Enable 16 bit baudrate generator

    Some of these might change if you are using a 16F part.

    You may have to remove the "1" after the register names if you are not using PBP 3
    Charles Linquist

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Serial Baudrate 115200 using HSEROUT - how to?

    if serout2 was inverted, HSER is not inverted. 16416 in table shows inverted.
    Last edited by amgen; - 16th October 2011 at 19:40.

  6. #6
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default Re: Serial Baudrate 115200 using HSEROUT - how to?

    Is there any way to set the DEBUG baud rate at runtime?

  7. #7
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Re: Serial Baudrate 115200 using HSEROUT - how to?

    Quote Originally Posted by amgen
    if serout2 was inverted, HSER is not inverted. 16416 in table shows inverted.
    Sorry, I don't understand what you want me to do?! I don't have any problems with SEROUT2 at this time.


    Quote Originally Posted by Charles Linquis
    I was referring to you trying to run 19200...
    I did try this at all available baudrates; never worked. Before you ask, yes, I tried with another PIC

    I do use a PIC16F690 and modified the code with your suggestion as it is herunder:
    Code:
    ' HSEROUT
    
    ' PIC 16F690 Fuses
    @ __Config _FCMEN_OFF &_IESO_OFF &_BOR_OFF &_CPD_OFF &_CP_OFF &_MCLRE_OFF &_PWRTE_OFF &_WDT_OFF &_HS_OSC
    
    OPTION_REG = %10000000 'PORT A&B Pull-Ups (look WPUA & WPUB)
    ADCON0     = %00000000 'A/D Module
    ANSEL      = %00000000 'Select analog inputs Channels 0 to 7
    ANSELH     = %00000000 'Select analog inputs Channels 8 to 11
    INTCON     = %00000000 'INTERRUPT Control
    'WPUA       = %00000000 'Select PORTA weak pull-ups
    'IOCA       = %00000000 'Interrupt On Change selection
    CM1CON0    = %00000000 'Comparator1 Module
    CM2CON0    = %00000000 'Comparator2 Module
    TRISA      = %00000000 'Set Input/Output (0 to 5)
    PORTA      = %00000000 'Ports High/Low (0 to 5)
    TRISB      = %00000000 'Set Input/Output (4 to 7)
    PORTB      = %00000000 'Ports High/Low (4 to 7)
    TRISC      = %00000000 'Set Input/Output (0 to 7)
    PORTC      = %00000000 'Ports High/Low (0 to 7)
    
    '-------------------------------------------------------------------------------
    ' DEFINEs
    DEFINE OSC 20
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $24 ' Enable transmit, BRGH = 1
    SPBRG = 42 ' 115200 Baud @ 20MHz, 0.94%
    BAUDCTL.3 = 1 'for PIC16F690 - BAUDCON1.3 = 1 ' Enable 16 bit baudrate generator 
    
    '-------------------------------------------------------------------------------
    LED1    var PORTA.2
    Counter var word
    Counter = 0
    
    TEST:
      Toggle led1
      HSEROUT [dec counter,13,10]
      pause 500
      Counter = counter + 1
      goto test
      
      end
    As said, I tried also the lowest selectable baudrate 300bps; even so, I can't see any "good" data in the terminal.
    Roger

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Serial Baudrate 115200

    back to basic Roger... check your ANSEL(h) settings.. you're sending something on a analog configured pin.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #9
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Thumbs up Serial Baudrate 115200 using HSEROUT - how to?

    Quote Originally Posted by amgen View Post
    if serout2 was inverted, HSER is not inverted.
    Why didn't you SHOUT IT OUT LOUD!!??

    You're absolutely right: the signal has to be inverted in the way I'm using it. I added a transistor to invert the signal going to the MAX232 chip and guess what: IT WORKS!!!!

    The HSEROUT code example in one of my previous post is working fine, also with 115200bps.

    I still have some transmission errors but I think this can be due to the small error rate - I'll try with a 18,432MHz crystal.

    Thanks a lot and have a nice day.
    Roger

  10. #10
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Using a "non-DEFINE-listed" oscillator speed

    Hi there,

    I need to use a 18,432MHz crystal with this PIC16F690 project to achieve a clean 115200bps serial comm.

    Looking at the OSC values in the DEFINEs list, I can't find the value "18".

    Shall I simply define the OSC as, i.e., "20" while connecting a 18MHZ crystal?

    The only drawback I can see is about timing in PAUSE commands or similar. I assume the HUSART will still run from the 18MHz osc; right?

    Any other problems I wouldn't see?
    Roger

Similar Threads

  1. Replies: 33
    Last Post: - 19th March 2010, 03:02
  2. Dynamic USB Serial Number (PIC18F4550)
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th July 2009, 17:03
  3. 16f88 internal osc 8mhz max serial baudrate ?
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 16th December 2008, 23:27
  4. PIC18F4680 to PC via MAX232 (RS232 serial) no output
    By opticsteam1 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th April 2008, 20:39
  5. interfacing to the pc serial port
    By kelangfei in forum General
    Replies: 4
    Last Post: - 7th October 2007, 22:35

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