NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Support Forum » modifying Baud rate is it related to ADC

October 16, 2010
by esc
esc's Avatar


I need some helping trying to understand something. In my project if I need to lower the baud rate of sending data out of the TXD pin of the MCU (b/c for my wireless transmission the 115200 is to high..i need like 2400).

Do I need to also modify the related ADCSRA bits? I saw in the temp project the ADCSRA were modified to support the 1/128 which if we take the clock speed multiplied by that value we get the 115200. Are ADC and UART baud rate suppose to be related or just a coincidence? I guess I am wondering if the ADC has to run at the same freq as the baud rate. If so I didn't see from the guide anything higher than 128 to get to 2400 when multiplied. I am probably completely off base here and not making sense (heck I am even confusing myself :) )

I am just trying to wrap my head around this at a high level.



October 16, 2010
by Rick_S
Rick_S's Avatar

If you are using standard Nerdkits files, the baud rate is set in the file uart.c found in your libnerdkits directory. If you look at that program in the uart)init() function, you will see the registers used for setting the baud rate.

void uart_init() {
  // set baud rate
  UBRR0H = 0;
  UBRR0L = 7;   // for 115200bps with 14.7456MHz clock
  // enable uart RX and TX
  UCSR0B = (1<<RXEN0)|(1<<TXEN0);
  // set 8N1 frame format
  UCSR0C = (1<<UCSZ01)|(1<<UCSZ00);

  // set up STDIO handlers so you can use printf, etc
  fdevopen(&uart_putchar, &uart_getchar);

Now if you look at the datasheet for the USART0 section you'll find tables that tell you what to set the registers to, to achieve many different baud rates.

In this case, to set 2400bps with a 14.7456 clock, UBBRn would be 383 or UBBR0H = 1 & UBBR0L = 127. (I think I got that right :) )

What you could do, is add another function to uart.c that would init at the desired baud rate or copy uart.c to another file that has been modified. That way you can keep the original intact.

Hope that helps a bit,


October 16, 2010
by esc
esc's Avatar

ok thank you. I guess what I was getting confused about was in the tempsensor.c file we have this line:

// set analog to digital converter

// to be enabled, with a clock prescale of 1/128

// so that the ADC clock runs at 115.2kHz.

ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);

Do I have to modify these so the ADC runs at 2400 too? I didn't see in the guide how to do that. Or was the fact the ADC clock is set at 115.2kHz and the UAR is at 115200 just a coincidence and they are really unrelated?

Thanks again,


October 16, 2010
by Rick_S
Rick_S's Avatar

Other than they both are dependent upon the crystal speed, they are unrelated. They each have their own registers for their setup.


Post a Reply

Please log in to post a reply.

Did you know that 20 LEDs can be controlled from 11 microcontroller pins, to make a twinkling heart outline? Learn more...