yehudabch:
Hi all,I need to establish connection between a PC and arduino uno, using RS232. I have a shield for the RS232 but the problem is that the PC's baud rate is 57600 (I can't change that) and when I use the line "serial.begin(57600)" the actual baud rate (after sniffing with logic analyzer) is NOT 57600, there's an inaccuracy of 5% or even more.
Now, according to the datasheet (of atmega328p) page 241, is f_osc will be at 1.8432MHz, the accuracy
at that baud rate should be much better. I believe I can achieve this number with the correct code but I don't know that code...Any suggestions?
Do you have F_CPU set correctly in your "boards.txt" file?
I just ran my little AVR baud rate calculator utility and got this:
[b]Arduino Crystal and Baud Rate Calculator
----------------------------------------
Enter crystal frequency in Hz. or MHz.
(i.e. 16 or 16.0 or 16000000 are all OK)
Crystal frequency: 1.8432
Desired baud rate: 57600
Effective F_CPU: 1.843200 MHz.
UBRR register : 3 (0x0003)
UBRRH register : 0 (0x00)
UBRRL register : 3 (0x03)
UCSRA U2X bit : set (1)
Desired baud : 57600
Actual baud : 57600.000
Percent error : 0.000%[/b]
As you can see, your crystal is a perfect integer divider for standard baud rates (the percent error is zero).
(edit to add): I was under the impression you were using a 1.84 MHz crystal!!!
For a 16 MHz crystal, this is what you get for an Arduino:
[b]Arduino Crystal and Baud Rate Calculator
----------------------------------------
Enter crystal frequency in Hz. or MHz.
(i.e. 16 or 16.0 or 16000000 are all OK)
Crystal frequency: 16
Desired baud rate: 57600
Effective F_CPU: 16.000000 MHz.
UBRR register : 34 (0x0022)
UBRRH register : 0 (0x00)
UBRRL register : 34 (0x22)
UCSRA U2X bit : set (1)
Desired baud : 57600
Actual baud : 57142.857
Percent error : -0.794%
[/b]