環境:ubuntu12.04+atmega128A+JTAG ICEhtml
網上已經有不少教程了,在前人走過的路上天然格外輕鬆,不過仍是要稍微總結一下,畢竟仍是有些不同的。linux
(1)安裝工具鏈c++
>sudo apt-get install binutils-avr avr-libc gcc-avr編程
(安裝信息省略)
ubuntu
裝完後用以下命令查看是否成功windows
zhy@hoply:~$ avr-gcc -v
Using built-in specs.
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/4.5.3/lto-wrapper
Target: avr
Configured with: ../src/configure -v --enable-languages=c,c++ --prefix=/usr/lib --infodir=/usr/share/info --mandir=/usr/share/man --bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-libssp --build=i686-linux-gnu --host=i686-linux-gnu --target=avr
Thread model: single
gcc version 4.5.3 (GCC)
app
(2)安裝下載工具工具
>sudo apt-get install avrdude avrdude-docoop
裝完後值得說一下了,不少網上買的下載器是隻提供windows下的驅動,linux下怎麼用徹底沒講,這裏提供一個思路,供參考。測試
avr-dude支持不少種編程器,具體支持哪些能夠打開/usr/share/doc/avrdude-doc/avrdude-html/avrdude.html網頁文件的第2.1節查看,avrdude的詳細使用說明也就是這個。一樣,我也網購了這樣的一個編程器,只知道它是一個USB轉串口而製成的一個JTAG ICE,工做波特率什麼的徹底不知道,怎麼辦?只能本身試了。
zhy@hoply:~$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hubzhy@hoply:~$ ls /dev/ttyUSB*
/dev/ttyUSB0
設備名爲ttyUSB0,由於僅有一個USB串口設備
zhy@hoply:~$ sudo avrdude -p m128 -c jtag1 -P /dev/ttyUSB0 -t
avrdude: jtagmkI_recv(): failed to send command to serial port
如此,把可能的設備試了個遍,不行。這才意識到多是波特率設置問題,加上波特率參數再試
zhy@hoply:~$ sudo avrdude -p m128 -c jtag1 -b 9600 -P /dev/ttyUSB0 -t
avrdude: jtagmkI_recv(): failed to send command to serial port
就這樣一次又一次,終於被我試出來了!
zhy@hoply:~$ sudo avrdude -p m128 -c jtag1 -b 19200 -P /dev/ttyUSB0 -t
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1e9702
avrdude>
測試一下:
avrdude> part
>>> part
AVR Part : ATMEGA128
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PA0
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom 4 12 64 0 no 4096 8 0 9000 9000 0xff 0xff
flash 33 6 128 0 yes 131072 256 512 4500 4500 0xff 0xff
lfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
efuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
lock 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
calibration 0 0 0 0 no 4 0 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
avrdude> dump eeprom 0 16
>>> dump eeprom 0 16
0000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
avrdude> erase
>>> erase
avrdude: erasing chip
暫時沒什麼問題,後續再寫個程序試試看。