Skip to content
Rodion Gorkovenko edited this page Dec 24, 2018 · 2 revisions

Flashing Miskatino (or anything) to Arduino via SPI

Download (or fetch from arduino setup) the avrdude program and its config - to separate folder for convenience, let's assume it is called /avrdude_home. Then execute command like this:

$ /avrdude_home/avrdude -C/avrdude_home/avrdude.conf -patmega328p -P/dev/ttyACM0 -b19200 -cavrisp

or for windows it may look a bit modified:

> \avrdude_home\avrdude -C\avrdude_home\avrdude.conf -patmega328p -PCOM10 -b19200 -cavrisp

Let'me describe it in details. Firstly we put the path and executable of avrdude itself - the program to be executed. The next with -C... is the path to its configuration file (don't know why it won't detect automatically). Parameter -p... gives the specific chip type. It's printed on the chip - but for most USB-less arduinos it is AtMega328p. Now with -P... (capital!) we specify communication port to which the "programmer" is connected - check your device list or device manager. At last -b... gives the baud rate (it is defined in programmer code, see above) and -c... is the programmer type.

This command does nothing except checking that:

  • programmer is connected to computer on given port and with given speed
  • target chip is properly connected to programmer.

So we are expected to see output like this:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f

avrdude: safemode: Fuses OK (H:07, E:D9, L:FF)

avrdude done.  Thank you.

Now to write the prepared .hex file we just add erase and upload parameters (erase is needed because upload writes only zero bits - this is specific of Flash memory):

/avrdude_home/avrdude -C/avrdude_home/avrdude.conf -patmega328p -P/dev/ttyACM0 -b19200 -cavrisp
        -e -U flash:w:mini-nano-duemilanove-16mhz.hex

Make sure it is written in a single line, despite I split it for clarity :)

If everything is well, we'll see output showing progress of uploading and then reading-verifying the result.

Fuses

The last thing to take care is to burn fuses. They specify running frequency, starting from bootloader and few other things, like resetting on low voltage. This is thing I don't like in AVRs/Arduinos - that these settings coundn't be changed from program itself.

We usually may want the following:

  • choose running frequency either from crystal (when with 16 Mhz, like on arduino board) - or 8 mhz from internal oscillator (useful for bare AtMega328 chip);
  • disable bootloader (especially if your hex-file don't contain it)
  • disable reset on low voltage (to be able running from two AA batteries for example)

For 16 MHz Arduino Mini / Nano / Duemilanove fuses could be like this:

E: 07, H: D9, L: FF

For 8 MHz version without quartz, using internal clock (of the same Atmega328p-based boards) change the lower fuse:

E: 07, H: D9, L: E2

And if you prefer to leave default fuses on the same chip (the same with L:62), you got 1 MHz internal clock which can be great for saving energy (it consumes around 1 mA then) - though UART will run at 14400 and all delays are multiplied by 8. Nevertheless it may be quite ok for projects using SPI/I2C/GPIO only and not requiring fast processing. ADC will slow down also (though its prescaler could be updated by program).

Note that AvrDude swaps E and H when printing out (obvious bug). To write them we use the first command with addition:

-U efuse:w:0x07:m
-U hfuse:w:0xD9:m
-U lfuse:w:0xFF:m

I recommend executing it in 3 separate operations. The most common trouble here could be if you set the chip to work from quartz with no quartz attached or it is not working - after this chip won't start at all even for programming. However you can fix with the trick - connect output of programmer's own quartz to frequency input of target chip...

Clone this wiki locally