Baud Rate

Thread Starter

Guinness1759

Joined Dec 10, 2010
64
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:

mik3

Joined Feb 4, 2008
4,843
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.
There is information and example in the datasheet. You might need to divide the clock by 4.
 

Thread Starter

Guinness1759

Joined Dec 10, 2010
64
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:

Thread Starter

Guinness1759

Joined Dec 10, 2010
64
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

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.
 

Thread Starter

Guinness1759

Joined Dec 10, 2010
64
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.
 
Top