ATMEGA328P 16MHz or 20MHz?

Hi all
Can anyone tell me why I read 2 different freq. in these two datasheets?
16MHz
vs
20MHz

And another thing: is ATMEGA328P-PU the same as ATMEGA328P regarding the bootloader?
Thanks

Because they are different grades of chip, Automotive v Standard.

They work the same, but have different signatures for programming the bootloader onto them, once it is on, the bootloader will report the same signature. Hope this helps.


I still have dubts...
Can I use a 16MHz crystal oscillator as a 20MHz one with the same uC?
Are the 2 bootloaders different?

ATmega328P is the general model name for the microcontroller. There is also a prefix that indicates the IC package that is used.

So when we say "ATmega328P", we are referring to the microcontroller in general, which includes all packaged forms of that silicon.

When we say "ATmega328P-PU", we are referring to the ATmega328P in the PDIP-28 IC package specifically. This lovely thing:

image

You can learn all the details by checking section 38.8 of the "ATmega48A/PA/88A/PA/168A/PA/328/P" datasheet, available for download here:

https://www.microchip.com/en-us/product/ATmega328P#document-table

Your question is unclear. If you are asking whether you can use a 20 MHz crystal oscillator with the ATmega328P microcontroler, the answer is "yes", as long as you are powering it at 4.5 V or higher.

Yes. The bootloader must be compiled for the clock speed the microcontroller will run at.

The reason is that the bootloader does serial communication with your computer at a specific baud rate (typically 115200 baud). The timings are dependent on the clock speed the chip is running at, and those timings are determined at compile time. So if you use the bootloader compiled for 16 MHz on a chip running at 20 MHz then the actual baud rate of the chip's serial communication would be 144000 baud (115200 x 20 / 16) instead of the expected 115200 and it would not be able to communicate with the computer.


The easiest way to get the ATmega328P bootloader precompiled for 20 MHz is by using the excellent "MiniCore" Arduino boards platform.

I'll provide instructions:

Install MiniCore

MiniCore is a 3rd party boards platform that adds support to the Arduino IDE for many configurations of the family of AVR microcontrollers including the ATmega328P. It can be installed very easily using the Arduino IDE Boards Manager.

  1. Select File > Preferences from the Arduino IDE menus.
  2. Enter the following URL into the "Additional Boards Manager URLs" field:
    https://mcudude.github.io/MiniCore/package_MCUdude_MiniCore_index.json
    
    If there are already Additional Boards Manager URLs there, separate them with commas.
  3. Click the OK button.
  4. Select Tools > Board > Boards Manager from the Arduino IDE menus.
  5. Wait for the updates to finish.
  6. Scroll down through the list of boards platforms until you see "MiniCore by MCUdude". Click on it.
  7. Click the Install button.
  8. Wait for the installation to finish.
  9. Click the Close button.

Select the correct board configuration

The installation of MiniCore has added some new boards options to the Arduino IDE. You must now select them.

  1. Select Tools > Board > MiniCore > ATmega328 from the Arduino IDE menus.
  2. Select Tools > Clock > External 20 MHz from the Arduino IDE menus.

You will notice that some additional custom configuration menus have been added under the Tools menu after selecting the "ATmega328" board. You can adjust those according to your needs as well.

Burn the bootloader

Prepare ISP programmer

You will need an ISP programmer. If you don't have a programmer, you can use a spare Arduino board as an "Arduino as ISP" programmer.

Arduino as ISP

The following instructions are for using an Arduino board as an "Arduino as ISP" programmer. If you have a dedicated programmer, you can skip to the next set of instructions.

Although the "Arduino as ISP" only works for programming targets of the AVR architecture, you can also use boards of a variety of architectures (e.g., "AVR", "SAMD", "megaAVR") as an "Arduino as ISP" programmer.

I will refer to the board which will used as an "Arduino as ISP" as the "programmer board" from here on. The board you are burning the bootloader to will be referred to as the "target board".

  1. Disconnect the Arduino boards from your computer.
  2. Make the following connections between the "programmer board" and the "target board".
    Refer to the "Connections" table on the SPI library reference page to determine the pin numbers.
    Programmer Target
    MISO MISO
    VCC 5V (VCC on 3.3 V boards)
    SCK SCK
    MOSI MOSI
    10 RESET
    GND GND
  3. Connect the "programmer board" to your computer with a USB cable.
  4. Select File > Examples > 11.ArduinoISP > Arduino ISP from the Arduino IDE menus.
  5. Select your "programmer board" from the Arduino IDE's Tools > Board menu.
  6. Select the port of your "programmer board" from the Arduino IDE's Tools > Port menu.
  7. Select Sketch > Upload from the Arduino IDE menus.
  8. Wait for the upload to finish.

You are now ready to burn the bootloader using your "Arduino as ISP" programmer.

Burn Bootloader

Instructions for burning the bootloader:

  1. Connect an ISP programmer to your Arduino board.
    If you are using an "Arduino as ISP", then you have already connected it according to the previous instructions.
  2. Select the target board from the Tools > Board menu and any other custom Tools menus (e.g., Tools > Processor).
  3. Select the appropriate programmer from the Tools > Programmer menu.
  4. Tools > Burn Bootloader
  5. Wait for the process to finish successfully.
  6. Unplug the USB cable of the programmer from the computer.
  7. Disconnect the programmer from the "target board".

Now connect the USB cable of the "target board" to your computer, select its port from the Tools > Port menu, and try uploading a sketch as usual.


There is detailed documentation about all of this in the MiniCore readme:

https://github.com/MCUdude/MiniCore#readme

1 Like

I mean can I put indifferently a 16MHz or a 20MHz quartz on the Arduino board I want to design along with 2 22pF caps as long as the bootloader is written accordingly? In the datasheet mentioning 20MHz as the freq it is not mentioned 16MHz and viceversa.

Yes. There is a range of supported clock speeds. You will see 20 MHz mentioned as the maximum of that range, but lower clock speeds are also supported. MiniCore provides boards definitions for the frequencies that are most likely to be used:

https://github.com/MCUdude/MiniCore#supported-clock-frequencies

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.