I am using an Arduino Uno, and I need to create a program that calculates the actual baud rate and the percent error for all standard baud rate in Arduino monitor program.

  • 4
    It's listed in datasheets. The table is called: "Equations for Calculating Baud Rate Register Setting" – KIIV Jan 30 '18 at 9:18
  • Welcome to Arduino:SE. Please be aware that this is not a free design house or an on-demand online technical encyclopedia. You might find it helpful to review the site tour and Help Centre and, in particular, How to Ask. – sempaiscuba Jan 30 '18 at 9:18
  • See wormfood.net/avrbaudcalc.php – Mikael Patel Mar 31 '18 at 12:02
  • Jasmine, if you found the below answer helpful, please upvote it and/or mark it as the answer. That's a good way of thanking @EdgarBonet for his hard work. See stackoverflow.com/help/privileges/vote-up to understand why voting is important. – MechtEngineer Mar 31 '18 at 23:53

First, look at the code used by the Arduino core library to configure the USART baud rate register: it's in HardwareSerial::begin(). The general formula is

uint16_t baud_setting = (F_CPU / 4 / baud - 1) / 2;

but beware of the hard-coded exception. You can replicate that part of the code in your own.

Then, look at the ATmega328P datasheet. More specifically, at section 24.4.1. Internal Clock Generation – The Baud Rate Generator. Here you find the formula

BAUD = F_CPU / (8*(UBRR0 + 1))

assuming the U2X0 bit has been set (again, beware of the hard-coded exception). Combine both formulas and you get the actual baud rate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.