• AVR Freaks

Hot!PIC16F886 baud rate 115200 not working with 3686400 Mhz

Author
PIC4C code
Junior Member
  • Total Posts : 112
  • Reward points : 0
  • Joined: 2011/02/21 10:32:55
  • Location: 0
  • Status: offline
2020/04/07 10:25:05 (permalink)
0

PIC16F886 baud rate 115200 not working with 3686400 Mhz

I'm want to use the PIC_886 with a baud rate 115200 a crystal. With an oscilloscope the freq indicates freq right on.
I'm using the Tera Term VT which read OK at 115200 baud on my Bluetooth module.  #pragma config FOSC = HS, SYNC = 0, BRGH = 0, BRG16 = 1 per TABLE 12.5
All I get garbage from the VT.  Looking for some HELP pointers.
#1

7 Replies Related Threads

    hexreader
    Super Member
    • Total Posts : 1068
    • Reward points : 0
    • Joined: 2008/05/04 03:06:55
    • Location: England
    • Status: offline
    Re: PIC16F886 baud rate 115200 not working with 3686400 Mhz 2020/04/07 10:52:05 (permalink)
    0
    Let me guess.....   could be way off....
     
    You are sending back-to-back 'U' character as transmit signal. The oscilloscope will show half of the baud rate, so if oscilloscope shows 115200 Hz, this would represent 330400 baud (as one cycle is two signal bits). You need to the scope to show half of desired baud rate.
     
    Maybe you already are aware of the difference between symbol (bit) rate and cycle frequency, and my guess is wrong. 

    Experienced Hobbyist
    #2
    PIC4C code
    Junior Member
    • Total Posts : 112
    • Reward points : 0
    • Joined: 2011/02/21 10:32:55
    • Location: 0
    • Status: offline
    Re: PIC16F886 baud rate 115200 not working with 3686400 Mhz 2020/04/07 11:37:14 (permalink)
    0
    The scope is looking at OSC/CLKOUT pin RA6 to insure the ext crystal is working.
    #3
    crosland
    Super Member
    • Total Posts : 1936
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: PIC16F886 baud rate 115200 not working with 3686400 Mhz 2020/04/07 11:56:45 (permalink)
    +1 (1)
    PIC4C code
    #pragma config FOSC = HS, SYNC = 0, BRGH = 0, BRG16 = 1 per TABLE 12.5

     
    What about the rest of your UART setup code?
    #4
    1and0
    Access is Denied
    • Total Posts : 10779
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: PIC16F886 baud rate 115200 not working with 3686400 Mhz 2020/04/07 12:03:28 (permalink)
    +1 (1)
    PIC4C code

    PIC16F886 baud rate 115200 not working with 3686400 Mhz

    I'm want to use the PIC_886 with a baud rate 115200 a crystal. With an oscilloscope the freq indicates freq right on.
    I'm using the Tera Term VT which read OK at 115200 baud on my Bluetooth module.  #pragma config FOSC = HS, SYNC = 0, BRGH = 0, BRG16 = 1 per TABLE 12.5
    All I get garbage from the VT.  Looking for some HELP pointers.

    That is 3.6864 MHz, not 3686400 Mhz.  For 4 MHz or less, use FOSC = XT, not HS. What value do you have for SPBRG?
    #5
    hexreader
    Super Member
    • Total Posts : 1068
    • Reward points : 0
    • Joined: 2008/05/04 03:06:55
    • Location: England
    • Status: offline
    Re: PIC16F886 baud rate 115200 not working with 3686400 Mhz 2020/04/07 13:21:59 (permalink)
    +1 (1)
    Understand you now...
     
    The attached code seems to work for me - gives 57.6 kHz square wave out, which equates to 115200 baud.
     
     
    // random code for forum
    // PIC16F886 3.686400MHz crystal
    // sample UART baud rate test thrown together very fast, so may well contain bugs
    // author accepts no responsibility for anything, anywhere, ever

    #include "xc.h"

    #define _XTAL_FREQ 3686400

    // CONFIG1
    #pragma config FOSC = XT // Oscillator Selection bits (XT oscillator: RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
    #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
    #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
    #pragma config MCLRE = ON // RE3/MCLR pin function select bit (RE3/MCLR pin function is MCLR)
    #pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
    #pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
    #pragma config BOREN = ON // Brown Out Reset Selection bits (BOR enabled)
    #pragma config IESO = OFF // Internal External Switchover bit (Internal/External Switchover mode is disabled)
    #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
    #pragma config LVP = OFF // Low Voltage Programming Enable bit (RB3 pin has digital I/O, HV on MCLR must be used for programming)

    // CONFIG2
    #pragma config BOR4V = BOR21V // Brown-out Reset Selection bit (Brown-out Reset set to 2.1V)
    #pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (Write protection off)

    void chout(unsigned char txdata) {
     while(!TXIF); // wait for send register ready
     TXREG=txdata;
    }


    char chin() {

     while(!RCIF); // wait until Rx character received
     return RCREG;
    }

    // set up UART at 115200 baud, 8, n, 1
    // SYNC = 0, BRGH = 0, BRG16 = 1
    void InitUART(void) {

     TRISC6 = 1; // TX Pin
     TRISC7 = 1; // RX Pin

    // SPBRG = ((_XTAL_FREQ/16)/BAUDRATE) - 1;
     BRG16 = 1;
     BRGH = 1; // Fast baud rate
     SYNC = 0; // Asynchronous
     SPBRG = 7;
     SPEN = 1; // Enable serial port pins
     CREN = 1; // Enable reception
     SREN = 0; // No effect
     TXIE = 0; // Disable tx interrupts
     TX9 = 0; // 8-bit transmission
     RX9 = 0; // 8-bit reception
     TXEN = 0; // Reset transmitter
     TXEN = 1; // Enable the transmitter
    }


    void main(void) {

     InitUART();

     while(1) {
            chout('U'); // send square wave at half baud rate for easy scope measurement
     }


    }


    post edited by hexreader - 2020/04/07 13:23:01

    Experienced Hobbyist
    #6
    PIC4C code
    Junior Member
    • Total Posts : 112
    • Reward points : 0
    • Joined: 2011/02/21 10:32:55
    • Location: 0
    • Status: offline
    Re: PIC16F886 baud rate 115200 not working with 3686400 Mhz 2020/04/09 07:33:17 (permalink)
    0
    hexreader
    Problem solved
    I used your example code and it works fine.   I used table 12.5  SYNC=0,BRGH=0,BRG16=1 in my code and SPBRG=1  (baudsetting)   I don't understand how you used 7
    I read 57.60676   I used U (0x55) lots of time because of the square wave.
    Thanks
    #7
    1and0
    Access is Denied
    • Total Posts : 10779
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: PIC16F886 baud rate 115200 not working with 3686400 Mhz 2020/04/09 08:07:19 (permalink)
    0
    PIC4C code
    I used your example code and it works fine.   I used table 12.5  SYNC=0,BRGH=0,BRG16=1 in my code and SPBRG=1  (baudsetting)   I don't understand how you used 7

    He uses SPBRG=7 because he uses BRGH=1, instead of 0.
    #8
    Jump to:
    © 2020 APG vNext Commercial Version 4.5