USART affected by different clock freqs?

I'm using an Seeeduino Mega 128 to do a simple "talk" with a plain Atmega 328P (no Arduino bootloader). I'm pretty sure that the 328P is receiving data, and when it does, it is supposed to transmit a letter "C" back to the Seeeduino. However, there is no indication on the Serial Monitor for the Seeeduino that the 328P has transmitted anything.

Now, I know this code works, because this same code was uploaded to an Arduino Nano v3.0 (contains Atmega 328P on-board). The Nano would totally function correctly - transmitting a letter "C" to the Seeeduino, which can be verified via the Seeeduino's Serial Monitor. However, when I tried to replicate this simple transaction with the plain 328P, there's no USART transmit going on.

So, the only thing I can think of are the difference in clock frequencies. The Seeeduino and the Nano both work off of an on-board 16MHz oscillator. The plain 328P is just using the internal RC oscillator of 8MHz. Could this be the problem, even though USART is supposed to be asynchronous?

Could there be other possibilities of why transmit from a plain AVR to an Arduino-ized AVR would fail?

The plain 328P is just using the internal RC oscillator of 8MHz. Could this be the problem

Yes. The internal oscillator is ±10% from the factory. It can be tuned to better than ±1%; which is more than good enough for serial communications.

  1. When you compiled the sketch prior to programming, did you use an appropriate board definition so that it was compiled for 8MHz clock?

  2. Have you programmed the fuses in the 328p to turn off CLKDIV8? On a virgin chip CLKDIV8 will be enabled, so the 8MHz clock will be divided down to 1MHz.

  3. See CodingBadley's comment above regarding tolerance of the internal clock.

  1. When you compiled the sketch prior to programming, did you use an appropriate board definition so that it was compiled for 8MHz clock?

This might be the problem. I use the selection "Arduino Duemilanove or Nano w/ Atmega 328" for compiling and creating the hex file. Then, I use AVRISP mkII for uploading the hex file to my virgin Atmega 328P.

So, the Arduino IDE software is assuming my chip has an external 16Mhz oscillator? And, this must be messing up my USART communications and buad rate? It's kind of making sense to me right now.

Do I change the board definition file to reflect the chosen clock source and frequency? Are there other settings I should change?

I found this in "boards.txt":

atmega328.build.mcu=atmega328p
atmega328.build.f_cpu=16000000L
atmega328.build.core=arduino

If I just change the 16MHz to 8MHz, then I should be good to go, do you think? Do I need to change some settings elsewhere to ensure that USART, baud rate and anything else matches with the Arduino Mega 128?

mrjimbo:

  1. When you compiled the sketch prior to programming, did you use an appropriate board definition so that it was compiled for 8MHz clock?

This might be the problem. I use the selection "Arduino Duemilanove or Nano w/ Atmega 328" for compiling and creating the hex file. Then, I use AVRISP mkII for uploading the hex file to my virgin Atmega 328P.

So, the Arduino IDE software is assuming my chip has an external 16Mhz oscillator? And, this must be messing up my USART communications and buad rate? It's kind of making sense to me right now.

Do I change the board definition file to reflect the chosen clock source and frequency? Are there other settings I should change?

When uploading a program to a virgin atmega328, you need to create or use a board definition that defines the clock frequency that your target processor will be using after you have set the fuses. The upload process does not set the fuses, you need to do that separately. See Prototyping small embedded projects with Arduino | David Crocker's Solutions blog for how I did it.