1. Guinness1759

    Thread Starter Member

    Dec 10, 2010
    64
    0
    I have a PIC16F1827 and I'm trying to set the UART to 9600 baud. I currently have

    SPBRG = 0b00000101;

    I'm using the default clock speed. I would use an oscilloscope but I don't have one. If anyone knows the correct setting for the SPBRG register let me know. :D BTW, I used the code example for UART and set it to 9600 baud and it is also not the correct baud rate.
     
    Last edited: Jun 2, 2011
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    If you have the PICKIT2 you can use it in logic analyser mode with the PICKIT2 software to see what the output is.
     
    Guinness1759 likes this.
  3. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    The "default" power-up/reset clock speed for the internal oscillator is 500-kHz (datasheet section 5.6). Is that the speed you really want to use? If so, it limits your baud rate options quite a bit (see below).

    Regards, Mike

    [​IMG]
     
    Last edited: Jun 4, 2011
    Guinness1759 likes this.
  4. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    There is information and example in the datasheet. You might need to divide the clock by 4.
     
    Guinness1759 likes this.
  5. Guinness1759

    Thread Starter Member

    Dec 10, 2010
    64
    0
    I got tired of guessing so I finally got a DAQ board and used it as an oscilloscope. Finally I needed the SPBRG register set to 0b00000010 to work. I also had to set the High Speed Baud rate option in the TXSTA register.

    Now on to the next problem, check my new thread. :)

    edit: Looks like I spoke too soon, it's getting the values, but they are not correct.
     
    Last edited: Jun 6, 2011
  6. Guinness1759

    Thread Starter Member

    Dec 10, 2010
    64
    0
    I just set the SPBRG register to 67 hex because I'm using 1200 baud. With those settings I'm getting a pulse width of about 4 ms. I'm getting a value of F8 F8 80 FE on the receiver, but I'm sending a value of 0F F0 0F AA.
     
  7. Guinness1759

    Thread Starter Member

    Dec 10, 2010
    64
    0
    So, it appears I got it working now, I had to take the 103 and divide by 4. So I used a SPBRG of 26 and now it appears to be finally working. Special thanks to MMcLaren and mik3, the combination of your advice helped me solve the problem.
     
  8. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    So what's your clock frequency? Is it 500-kHz?
     
Loading...