16F18446 - setting baudrate for HW EUSART


+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    950

    Default 16F18446 - setting baudrate for HW EUSART

    Hi All,

    I had an example from Richard lately where he configured my 16F18446 HW serial's port.

    I didn't pay that much attention to it...

    Now that I'm looking closer on "how he did it", I can't figure it out.

    So I went to "visit" the DS and after lots of calculations and trials, I'm still stuck.

    This is an extract from Richard's code (as said from another thread/project), the piece of code I'm working on.

    Code:
    ' ====== PIC 16F18446 FUSES =======================================================================
    ' Internal oscillator
    #CONFIG
        __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTS_PWRT_64 & _LPBOREN_OFF & _BOREN_SBOREN & _BORV_LO & _ZCDDIS_OFF & _PPS1WAY_OFF & _STVREN_ON
        __config _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_SWDTEN & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTD_OFF & _WRTSAF_OFF & _LVP_OFF
        __config _CONFIG5, _CP_OFF
    #ENDCONFIG 
    
    @ ERRORLEVEL -306
    @ ERRORLEVEL -202
    
    ' ====== DEFINES / REGISTERS ======================================================================
    DEFINE OSC 32
    DEFINE ADC_BITS 12      'Number of bits in ADCIN result
    DEFINE HSER_TXSTA 24h   'Enable transmit, BRGH = 1
    DEFINE HSER_CLROERR 1   'Clear overflow automatically
    
    BAUDCON.3 = 1     'Enable 16 bit baudrate generator
    
    ' Baudrates @ 32MHz
    ' 9600
    'DEFINE HSER_SPBRG 832
    'SP1BRGH = 51
    
    ' 19200
    ''DEFINE HSER_SPBRG 416
    'SP1BRGH = 25
    
    ' 57600 
    'DEFINE HSER_SPBRG 138
    SP1BRGH = 0
     
    ' 115200
    'DEFINE HSER_SPBRG 68
    'SP1BRGH = 0
    
    ' ====== VARIABLES ================================================================================
    RC3PPS = 15 'TX PORTC.3 - set RC3 to EUSART TX
    
    ' ====== TEST PROGRAM =============================================================================
    HW_SERIAL:    
        HSerout ["Hello World!",13,10]
        HSerout ["Testing...",13,10]
        PAUSE 1000
        GOTO HW_SERIAL:

    While the settings for baudrates 57600 and 115200 work perfectly, I can't make it work for slower baudrates like 19200 or even 9600.


    I tried to follow the DS and, even if in Richard's example some values don't chage like for instance the SP1BRGH on, I thought I should use the following formula.

    Name:  Solving.jpg
Views: 13
Size:  34.8 KB


    It doesn't work.


    But looking at the baudrate examples table, I can't find the difference for all proposed baudrates.

    Name:  BaudRates.jpg
Views: 9
Size:  81.7 KB


    Can anyone please explain whre I'm missing the point (or points)?
    Last edited by flotulopex; Yesterday at 17:57.
    Roger

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


    Did you find this post helpful? Yes | No

    Default Re: 16F18446 - setting baudrate for HW EUSART

    when you get a result like
    DEFINE HSER_SPBRG 832 you realize something is very wrong since an 8 bit register can not accept that value ever

    you have enabled the 16 bit baud rate generator in every case


    BAUDCON.3 = 1 'Enable 16 bit baudrate generator

    for 19200
    SP1BRGL = 160:SP1BRGH = 1

    for 9600
    SP1BRGL = 64:SP1BRGH = 3


    BAUDCON.3 = 0 '8 bit baudrate generator
    for 9600
    SP1BRGH = 51

    for 19200
    SP1BRGH = 25
    Warning I'm not a teacher

Similar Threads

  1. 16F18446 - limit program memory size for burning time saving
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 22nd December 2024, 22:44
  2. 16F18446 - maybe missing some registers settings
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 20th December 2024, 18:43
  3. Blinker for 16F18446 - OSC settings and PORT addressing
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 10th February 2024, 14:40
  4. HSER baudrate
    By pedja089 in forum Serial
    Replies: 14
    Last Post: - 7th August 2011, 20:46
  5. different baudrate
    By danial in forum Serial
    Replies: 3
    Last Post: - 2nd February 2010, 12:37

Members who have read this thread : 3

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