先 unlock 芯片并修改 fuse bit,fuse bit 的值可以在 arduino-0018/hardware/arduino/boards.txt 里找到,这个文件里还说明了各种 AVR 应该使用的 bootloader 文件,例如 ATmega168 使用的是 ATmegaBOOT_168_diecimila.hex,这个文件稍后会用到。
boards.txt 中关于 Arduino Diecimila, Duemilanove, or Nano w/ ATmega168 的部分:
############################################################## diecimila.name=Arduino Diecimila, Duemilanove, or Nano w/ ATmega168 diecimila.upload.protocol=stk500 diecimila.upload.maximum_size=14336 diecimila.upload.speed=19200 diecimila.bootloader.low_fuses=0xff diecimila.bootloader.high_fuses=0xdd diecimila.bootloader.extended_fuses=0x00 diecimila.bootloader.path=atmega diecimila.bootloader.file=ATmegaBOOT_168_diecimila.hex diecimila.bootloader.unlock_bits=0x3F diecimila.bootloader.lock_bits=0x0F diecimila.build.mcu=atmega168 diecimila.build.f_cpu=16000000L diecimila.build.core=arduino ##############################################################
执行操作:
atommann# avrdude -p m168 -c usbasp -e -u -U lock:w:0x3f:m -U efuse:w:0x00:m -U hfuse:w:0xDD:m -U lfuse:w:0xFF:m avrdude: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.02s avrdude: Device signature = 0x1e9406 avrdude: erasing chip avrdude: reading input file "0x3f" avrdude: writing lock (1 bytes): Writing | ################################################## | 100% 0.01s avrdude: 1 bytes of lock written avrdude: verifying lock memory against 0x3f: avrdude: load data lock data from input file 0x3f: avrdude: input file 0x3f contains 1 bytes avrdude: reading on-chip lock data: Reading | ################################################## | 100% 0.01s avrdude: verifying ... avrdude: 1 bytes of lock verified avrdude: reading input file "0x00" avrdude: writing efuse (1 bytes): Writing | ################################################## | 100% 0.01s avrdude: 1 bytes of efuse written avrdude: verifying efuse memory against 0x00: avrdude: load data efuse data from input file 0x00: avrdude: input file 0x00 contains 1 bytes avrdude: reading on-chip efuse data: Reading | ################################################## | 100% 0.01s avrdude: verifying ... avrdude: 1 bytes of efuse verified avrdude: reading input file "0xDD" avrdude: writing hfuse (1 bytes): Writing | ################################################## | 100% 0.01s avrdude: 1 bytes of hfuse written avrdude: verifying hfuse memory against 0xDD: avrdude: load data hfuse data from input file 0xDD: avrdude: input file 0xDD contains 1 bytes avrdude: reading on-chip hfuse data: Reading | ################################################## | 100% 0.01s avrdude: verifying ... avrdude: 1 bytes of hfuse verified avrdude: reading input file "0xFF" avrdude: writing lfuse (1 bytes): Writing | ################################################## | 100% 0.01s avrdude: 1 bytes of lfuse written avrdude: verifying lfuse memory against 0xFF: avrdude: load data lfuse data from input file 0xFF: avrdude: input file 0xFF contains 1 bytes avrdude: reading on-chip lfuse data: Reading | ################################################## | 100% 0.01s avrdude: verifying ... avrdude: 1 bytes of lfuse verified avrdude done. Thank you.
接下来,写入 bootloader 并锁住 AVR。
atommann# avrdude -p m168 -c usbasp -U flash:w:ATmegaBOOT_168_diecimila.hex -U lock:w:0x0f:m avrdude: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.02s avrdude: Device signature = 0x1e9406 avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed To disable this feature, specify the -D option. avrdude: erasing chip avrdude: reading input file "ATmegaBOOT_168_diecimila.hex" avrdude: input file ATmegaBOOT_168_diecimila.hex auto detected as Intel Hex avrdude: writing flash (16294 bytes): Writing | ################################################## | 100% 77.03s avrdude: 16294 bytes of flash written avrdude: verifying flash memory against ATmegaBOOT_168_diecimila.hex: avrdude: load data flash data from input file ATmegaBOOT_168_diecimila.hex: avrdude: input file ATmegaBOOT_168_diecimila.hex auto detected as Intel Hex avrdude: input file ATmegaBOOT_168_diecimila.hex contains 16294 bytes avrdude: reading on-chip flash data: Reading | ################################################## | 100% 71.70s avrdude: verifying ... avrdude: 16294 bytes of flash verified avrdude: reading input file "0x0f" avrdude: writing lock (1 bytes): Writing | ################################################## | 100% 0.03s avrdude: 1 bytes of lock written avrdude: verifying lock memory against 0x0f: avrdude: load data lock data from input file 0x0f: avrdude: input file 0x0f contains 1 bytes avrdude: reading on-chip lock data: Reading | ################################################## | 100% 0.01s avrdude: verifying ... avrdude: 1 bytes of lock verified avrdude: safemode: Fuses OK avrdude done. Thank you.
完成!这时可以把 AVR 插到 Arduino 2009 上了(Arduino 2009 上有 6 针 ISP 编程接口,上面这些操作都可以在板上完成)。