系统环境:Ubuntu10.10
板子型号:Arduino2009
烧录工具:USBTinyISP
Arduino是什么?一款很火的用来搭建电子积木的开发板,既然叫积木,所以入手很简单,更多介绍去搜索。
USBTinyISP是一个方便使用的高速的AVR编程器,是Arduino官方支持的一款固件烧录器(还有常用的如USBAsp烧录器)。
对于Linux和Mac系统,USBTinyISP是可以直接使用的,不需要安装驱动(Windows下是需要安装驱动的,链接参见后面,主要用于连接参考)
1. 通过USB转串口线将USBTinyISP连接到PC。(注意:USBTinyISP不是一个USB-Serial设备,它有自己的Avrdude支持的USB协议,所以当你插入到PC时将看不到一个COM端口或者ttyUSB串口建立。)
2. 注意检查跳线“PWR”应该短接,短接后就不需要再为后面的Arduino开发板单独供电了。
![](https://i-blog.csdnimg.cn/blog_migrate/f69001c82e10cddf6712f457b1557fc4.png)
3. 将USBTinyISP上那根6针的ISP连接线与Arduino开发板的6针ICSP相连(注意不要插反了!!)
![](https://i-blog.csdnimg.cn/blog_migrate/64f517fa109710f2f39a5abc65fdda04.png)
我是参照上图中插入的,但好像是反了,一直提示“avrdude: initialization failed, rc=-1”之类的错误,害得折腾半天也没找到原因,后来折腾过程中"插错"了一回竟然可以了,所以对于网络上的文档不可尽信才是(当然也并非是文档错 了,而是要与USBTinyISP上一端的插法保持一致才行),反正遇到问题时都试一下就对了。
4. 关于Arduino开发板的Bootloader都在它的开发包里面,现在最新的好像是arduino-0022,所以需要先下载这个包。(对于 ubuntu也可以直接通过apt安装arduino软件包,版本好像是0018,但不知道是否包含了Bootloader文件,我没去找过);还有一点 需要注意的就是Arduino有很多版本,一定要清楚自己板子的型号然后找到正确的Bootloader文件。可以在 arduino-0022/hardware/arduino/boards.txt 里找到对应板子的型号,如Arduino2009的板子对应是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
##############################################################
上面的那些参数在后面的烧写命令中都会用到,通过上面文件可以得知需要使用的Bootloader文件是ATmegaBOOT_168_diecimila.hex
5. 开始烧写操作:
详细的操作指令如下,大部分参数都已经在上面boards.txt所对应的段落里写明了,但需要注意一下“-c usbtiny”参数,因为这里使用的是USBTinyISP烧录器;而如果使用的是USBAsp烧录器,则需要改成“-c usbasp”了;对于其它的烧录器,可以在“-c”后面随便给串字符执行,然后会报错并给出所有支持设备列表的。(可以先不加最后的那个“-F”参数执 行试试,如果不成功再加上,该参数理论是不需要的,但我这边必须得加)
就两条命令(注意需要ROOT权限执行),第一条先unlock 芯片并修改 fuse bit,fuse bit 的值:
zwang@wzc-laptop:~/source/arduino-0022/hardware/arduino/bootloaders/atmega$ sudo avrdude -p m168 -c usbtiny -e -u -U lock:w:0x3f:m -U efuse:w:0x00:m -U hfuse:w:0xDD:m -U lfuse:w:0xFF:m -F avrdude: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.01s avrdude: Device signature = 0x1e940b avrdude: Expected signature for ATMEGA168 is 1E 94 06 avrdude: erasing chip avrdude: reading input file "0x3f" avrdude: writing lock (1 bytes): Writing | ################################################## | 100% 0.00s 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.00s avrdude: verifying ... avrdude: 1 bytes of lock verified avrdude: reading input file "0x00" avrdude: writing efuse (1 bytes): Writing | ################################################## | 100% 0.00s 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.00s avrdude: verifying ... avrdude: 1 bytes of efuse verified avrdude: reading input file "0xDD" avrdude: writing hfuse (1 bytes): Writing | ################################################## | 100% 0.00s 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.00s avrdude: verifying ... avrdude: 1 bytes of hfuse verified avrdude: reading input file "0xFF" avrdude: writing lfuse (1 bytes): Writing | ################################################## | 100% 0.00s 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.00s avrdude: verifying ... avrdude: 1 bytes of lfuse verified avrdude done. Thank you.
第二条写入Bootloader文件并lock AVR:
zwang@wzc-laptop:~/source/arduino-0022/hardware/arduino/bootloaders/atmega$ sudo avrdude -p m168 -c usbtiny -U flash:w:ATmegaBOOT_168_diecimila.hex -U lock:w:0x0f:m -F avrdude: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.01s avrdude: Device signature = 0x1e940b avrdude: Expected signature for ATMEGA168 is 1E 94 06 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% 9.55s 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% 8.53s avrdude: verifying ... avrdude: 16294 bytes of flash verified avrdude: reading input file "0x0f" avrdude: writing lock (1 bytes): Writing | ################################################## | 100% 0.02s 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.00s avrdude: verifying ... avrdude: 1 bytes of lock verified avrdude: safemode: Fuses OK avrdude done. Thank you.
附上Mega1280烧写命令:
sudo avrdude -p m1280 -c usbtiny -e -u -U lock:w:0x3f:m -U efuse:w:0xF5:m -U hfuse:w:0xDA:m -U lfuse:w:0xFF:m -F sudo avrdude -p m1280 -c usbtiny -U flash:w:rep2_firmware_v7.2.0.hex -U lock:w:0x0f:m -F
参考链接:
[1] Arduino bootloader:www.atommann.com/learn/arduino/arduino-bootloader.html
[2] USBTinyISP AVR/Arduino官方下载器:robotexplorers.com/?q=node/12
[3] Arduino 官方支持下载线 USBtinyISP 使用手册:blog.flamingoeda.com/2009/05/01/arduino-...8%E6%89%8B%E5%86%8C/