ATmega328P individual IC bootloader and programming circuits

Here is the circuit I find:


USB to TTL CONVERTER ---------> ATMEGA328P
RST -----------> RST
RX -------------> TX
TX --------------> RX
GND ------------> GND
5V --------------> VCC

Hi @q12. The schematic provided here will be superior:

https://github.com/MCUdude/MiniCore#minimal-setup

The significant difference is the circuit connected to the DTR pin of the "UART" header (which is the connection to the USB to TTL converter). The bootloader must be activated before the upload process starts. That is done by resetting the ATmega328P. This circuit will cause the ATmega328P to be automatically reset during the upload. This is very convenient because otherwise you would need to remember to manually reset the ATmega328P during each upload, and you would need to get the timing just right (since the bootloader only remains activated for a short time).

1 Like

Thank you !
Here is the circuit I choose because there are 3 of them, with subtle differences.

I choose the most right one because the left one is for DIP package (long IC), and the middle is quite the same with the right, but I read a bit inside the documentation and I got that: "the ATmega328 and the ATmega328P got different device signatures, so selecting the wrong one will result in an error." I believe the middle cct is the simpler ATmega328 and not the ATmega328P model I have here. I hope Im right.


ok, so from your cct, I can observe that I must connect 2 devices to my blank IC. Wow.... ok.

Hi, @ptillisch .
From your page I can observe multiple crystal fv's and the X1 is not having any marking on it. Can I use any crystal fv from that list and that I have, in your cct? or is imperative to be 16MHz crystal dedicated only for this bootloader operation?

You can use any crystal. But if you do that then you must use that "MiniCore" boards platform to add support for the board to Arduino IDE, instead of using the normal "Arduino AVR Boards" platform of the Arduino UNO, etc.

The reason is that the board definitions of the "MiniCore" boards platform have a bootloader that supports arbitrary clock frequencies, whereas the bootloader of the "Arduino Uno" board definition is compiled for use only on a board that has a 16 MHz crystal.

1 Like

The clocks supported by MiniCore are listed here:

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

Instructions for installing the "MiniCore" boards platform are here:

https://github.com/MCUdude/MiniCore#boards-manager-installation

After installing it, select Tools > Board > MiniCore > ATmega328 from the Arduino IDE menus.

Next, select the clock configuration for your board from the Tools > Clock menu. You will see other menus under the Tools menu you can use to adjust the configuration of the board in other ways.

After you have selected the appropriate items from each of the menus, connect an ISP programmer to your board and then select Tools > Burn Bootloader from the Arduino IDE menus. In addition to flashing the appropriate bootloader to the ATmega328P, this will also set the configuration fuses on the chip according to your selections from those menus.

1 Like

it is completely wrong suggestion.
With or without a bootloader, the code after compilation does not need any decoding and can be used immediately to work with the controller and its registers.
The only point to use a bootloader is to give you the ability to load code with USB-TTL converter instead of using the ISP.

But since you still need to connect the ISP to load the bootloader itself, loading the bootloader is just an unnecessary operation. You can use the Arduino IDE and load code via the ISP without a bootloader.

2 Likes

Put another way, the bootloader is there to receive your Arduino machine code, store it in memory, then jump to it when done receiving it. The bootloader code resides at the location the Arduino initiates operation at, whether it's been reset, or powered on.

When you reset an Arduino that has bootloader, the Arduino first runs the bootloader code; if no 'load' activity is detected on serial, then the bootloader eventually jumps to the start of the code previously loaded in the Arduino, whatever that is.

Via ICSP, you directly store machine code in memory, where the bootloader would have been, and the 'reset' tweak causes the Arduino to initiate at the reset location - starting your code.
There's a bit more to it, but that's the gist.

2 Likes

One thing to note - for some applications, the several-hundred-millisecond delay introduced by the bootloader's monitoring for load activity is unacceptable - the user's code must start up and be in control as soon as possible. In that case, the best option is to load via ICSP, so the code is in control immediately. But, it's not as convenient as working in the IDE and simply clicking on compile-and-download. So, many will do the convenient until the application is 'complete', then do the last download via ICSP, eliminating the bootloader delay.

1 Like

Thank you both @b707 and @camsysca for your last 2 answers.
I didn't find this answer anywhere, easy to understand at least. Like you just did here. Very good, and thank you !
So this bootloader code is just to identify other ways of connections, like my USB-TTL converter. And that the blank IC will run perfectly the machine code if provided through ICSP from our Arduino R3 board. Well, now is clear for me !
So that 16MHz crystal I dont need it anymore, if Im to upload my code through ICSP port, right? If I understood right, that was necessary only to correctly load the bootloader program from arduino board.
-So now, what is the wiring for this ICSP port? I suspect it is as simple as in the picture, from that ICSP port directly on the blank IC pins. And if I read it correctly, I can even use the internal 8MHz clock of my blank IC, like I was using it when it was on the R3 board pretty much. Right? Again, this is my first time doing this shenanigans. Ive read about it, I am aware about it, but never done it.
Thank you !

That is incorrect. You can use a bootloader on a board that doesn't have an external clock. You only need to make sure to use a bootloader that is compiled for an 8 MHz clock, or an "auto-baud" bootloader like the one provided by MiniCore.

You also need to make sure that the definition of the board you have selected in Arduino IDE is configured for using the internal oscillator.

The "Arduino Uno" board definition provides a bootloader compiled for 16 MHz clock speed, and also sets the configuration fuses on the ATmega328P to use an external clock source. So that board definition can't be used with a board that doesn't have an external 16 MHz clock. But MiniCore's "ATmega328" board definition provides a Tools > Clock > Internal 8 MHz configuration option that can be used with such a board.

Correct.

That is correct.

A crystal is superior to the internal oscillator because the internal oscillator is relatively inaccurate. In theory, the internal oscillator might be so far off as to cause problems like serial communication working at certain baud rates. However, in practice the internal oscillator is usually completely sufficient.

1 Like

Thank you !
Now, what is the Arduino IDE settings, to tell Arduino R3 board to use only its ICSP port?
And if there are some other settings needed before sending a normal blinking test code to the blank IC?

To use the Uno as an ISP programmer, follow this tutorial:

https://docs.arduino.cc/built-in-examples/arduino-isp/ArduinoISP/

  1. Install the MiniCore boards platform by following these instructions:
    https://github.com/MCUdude/MiniCore#boards-manager-installation
  2. Tools > Board > MiniCore > ATmega328 from the Arduino IDE menus.
  3. Select Tools > Clock > Internal 8 MHz from the Arduino IDE menus.
  4. If you are only going to upload to the board via ICSP, select Tools > Bootloader > No bootloader from the Arduino IDE menus.

After you have everything all set up, select Tools > Burn Bootloader from the Arduino IDE menus. This will set the configuration fuses on the target ATmega328P according to the selected board definition. You only need to do this one (and again if you later change the board configuration).

Now select Sketch > Upload Using Programmer from the Arduino IDE menus. This will upload the sketch you have open in Arduino IDE to the target ATmega328P.

2 Likes
  • I will do it exactly as you tell me !
  • But first I have to link the IC with tiny wires, make a small board for it, because those adapter boards are on the way, make that special ICSP cable, hopefully I can find a rectangular "jack" in my scraps, and also link 1 or 2 leds to some IO pins for the uploaded code tests.
  • So all these will take some time. I will post pictures too. So pay attention ! haha.
  • Im very happy you clarify everything to me. Im not very clear though about still loading that bootloader through your minicore platform. Im not against it, and I am curious about it too, but tell me why is still needed. I want to have a crystal clear method here for future me. Also, can you explain as simple as possible what those fuses mean? In my mind, like on Microchip PICs, I had to set up the PIC first in code, and then enter in the main program executable. I think these fuses are like those PIC settings, what to use and what to close internally before starting anything. I find these settings, at least for PICs, were extremely confusing and because of that, they were VERY hard to set up properly, I always forget 1 or 2 very tricky details that I always forget them. I hope your fuses are more easy to understand and set up than those unnecessarily hard settings on PICs.
  • Thank you !

You need to understand that the "Burn Bootloader" operation typically accomplishes two different things:

  • Set the configuration fuses
  • Flash the bootloader binary

Despite the "Bootloader" in "Burn Bootloader", if you select Tools > Bootloader > No bootloader from the Arduino IDE menus then Tools > Burn Bootloader will not flash a bootloader binary. So in this case the purpose of the "Burn Bootloader" operation is solely to correctly set the configuration fuses on the ATmega328P. If you don't perform a "Burn Bootloader" operation, then the chip will have the factory default fuse settings, which might not be appropriate (for example, the chip will be running at 1 MHz).

It is not necessary. You only need to make sure you have the appropriate board configuration selected in Arduino IDE and then perform a "Burn Bootloader" operation. The fuses will be automagically set correctly.

If you do want to learn about it, consult the ATmega328P datasheet.

You might also find this tool to be useful:

https://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega328p

1 Like

Post #18:

It simply tells your processor to talk to a UART.

I'm going to mute tracking on this post now, so I never have to read this again.

1 Like

I don't think it is a very good description of what the bootloader does.

The primary purpose of the bootloader is to receive data from the UART and write it to the flash memory of the ATmega328P.

The bootloader implements a communication protocol which allows the upload tool to send commands for various operations (one of which is flashing). Another capability of interest in certain rare cases is reading, where the bootloader reads the data from the flash memory and sends it over the UART. This allows us to recover the program binary from one board (assuming it hasn't been locked to prevent this), which can then be flashed to other boards.



I made this diagram for wiring from ICSP directly to the IC pins. Verify it as well.
This is how I will make the test board, with this wiring.
I managed to find a longer rectangular plug that was scrapped and I cut it to fit these 6 pins, I also managed to change the wiring in that plug, to match the color of some pins here, and be a bit more easy to work with,

The breakout board you plan on using will give you nothing but headaches. You can get 3 of the below boards for $6.35 USD
https://oshpark.com/shared_projects/UpYHazwf

You can install only the the components your project requires. I recommend having the board house install at a minimum the ATMega, the 3 bypass caps and an external 16Mhz resonator. I understand you plan to use the internal 8 Mhz resonator but you never know. They are dirt cheap. The external resonator requires care installing without damage.

If you're not in the US you can most likely find a board house in your area with a similar design available.

You have the right idea rolling your own. However, I believe you are starting on the wrong platform with that breakout board.

2 Likes

I finished the board! (on an ordinary cardboard)
This is temporary and is teaching me more about this IC -its hardware side so far.
I used the diagram on the table.
I have 2 LEDs on pin17 and pin32 of the IC (arduino uno equivalent pin13 and pin2).
You can zoom into my image to see those 2 leds drawn on the diagram.
I hope I did it right. Always verify me because this is my first time and stupid mistakes are to be expected.
And theoretically, when Im powering Arduino Uno R3, it ill also power that extension board along with it. Right? I hope so.
So from this point, what to do next?

1 Like