I regularly order self made boards with SMT assembly. They come with blank atmega328 chips. The first time when I tried programming one I noticed that the clock speed was around 1/16 of what it should be. Than I realized, o yeah... I have to bootloader first because of fuse settings.
To eliminate the process of burning the bootloader. What fuses and all can I set in the source code of my programs? The atmega should just behave like it is an average arduino nano.
I typically do 'normal' things with coding. So I use analogWrite(), millis(), analogRead() etc.
Wat I don't understand is how I can write values to the registers. I understand how I can address each bit manually, but how do I write all 8 bits at once? Is that possible at all to begin with?
You can use avrdude tool from the command line to program fuses, see the avrdude UG. It is programmed by bytes: low fuse byte, high, etc. You can program just one fuse byte, avrdude switch is like this: "-U lfuse:w:0xF7:m".
It is possible to do this in your program (atmega's datasheet, ..avr/boot.h), but why? Especially if "the atmega should just behave like it is an average arduino nano", you will need to do this just once. This is the configuration and you don't suppose to do it in the program.
You can't set the fuses from your source code
Only during programming using ICSP
Ok clear.
It is a board design for other people and I am working on a 2nd easier method (1st method being the Arduino IDE) to program the board. I prefer to have it is as simple as people unzipping a folder of mine, set the COM port in some file and double click on someBatchFile.bat to do the programming. I have used a batch script in the past for flashing boards.
Than people don't need to install the arduino IDE at all.
to write bootloader and to write only fuses needs nearly the same time amount
It is not so much about speed, but about 'labour' (2 whole mouse clicks, right?). How fewer mouse clicks an a-technical person has to do, how fewer things can go wrong.
I think I am best off with a script which uses avrdude to burn both bootloader/set fuses and flash the board.
You can use avrdude tool from the command line to program fuses
Unless if I get this to work. I am happy either way. Whatever works!
I was providing background information I was not trying to provoke an off-topic discussion... Besides the a-technical person has everything to do with the fuse bits. He would be following a tutorial with which his actions will set the fuses. He is just not aware about any of this.
(Jim, that quote was of Budvar not of mine)
.. what good does that do you If you don't have a bootloader, then you need an ICSP programmer
I don't have USB or breakout Uart pins either. I need to program once, fire and forget.
What good it does? Well it simply gets my design to work. That's all. The fuses have te be set one way or another don't they? We are talking about blank chips. Whether the fuses are set during bootloader burning or flashing the final program does not really matter to me. Just as long as it works.
I dug up the script I once used. The upload line is this one. (It could pick different .hex files to use)
Yes, you can, like @kolaha and @hansibull wrote. However, you have to have use ISP programming and according -c arduino in your commands it seems that you did not.
The spaces don't have to be there at all, they're optional. I actually prefer without, since it makes it more obvious which parameter the flag belongs to
I think that 'programming' (or flashing actually) doesn't get much simpler than this.
With the upper line you can 'prepare' an Arduino by turning it into a programmer
And the 2nd well. see the screenshots.