ATtiny13
来自Jack's Lab
目录 |
1 Overview
The ATtiny13 looks like this:
------ PB0(MOSI)-|ATtiny|-GND PB1(MISO)-| 13 |- PB2 (SCK)-| |- VCC-| o|-RES ------
2 Hello World
2.1 Prepare the toolchain
$ sudo apt-get install gcc-avr
2.2 Blink
- blink.c
#include <avr/io.h> #define F_CPU 1000000UL #include <util/delay.h> int main(void) { DDRB = 8; // PB3 will be output, all others input while (1) { PORTB = 8; _delay_ms(1000); PORTB = 0; _delay_ms(1000); } return 0; }
- Makefile
MCU=attiny13 CC=avr-gcc OBJCOPY=avr-objcopy CFLAGS=-g -mmcu=$(MCU) -Os all: blink.hex blink.hex : blink.o $(OBJCOPY) -R .eeprom -O ihex blink.o blink.hex blink.o : blink.c $(CC) $(CFLAGS) -Os -o blink.o blink.c clean: rm -f *.hex *.o
- Build
$ make
3 Upload Flash
- Install avrdude
$ git clone git://github.com/laclefyoshi/avrdude-serjtag.git avrdude $ cd avrdude $ tar zxvf bin/avrdude-5.11.1.tar.gz $ cd avrdude-5.11.1 $ (linux optional) patch -p1 < ../src/avrdude-5.8-baud.patch $ patch -p1 < ../src/avrdude-5.10-serjtag.patch $ patch -p1 < ../src/avrdude-5.11-serjtag.patch $ patch -p1 < ../src/avrdude-5.8-ft245r.patch $ patch -p1 < ../src/avrdude-5.11-ft245r.patch $ patch -p1 < ../src/avrdude-5.8-confu2.patch
Installing libftd2xx drivers: http://www.ftdichip.com/Drivers/D2XX.htm
$ sudo apt-get install libusb-1.0.0-dev libusb-dev $ ./configure CFLAGS="-g -O2 -DSUPPORT_FT245R" LIBS="-lftd2xx" --prefix=/usr/local $ make $ sudo make install
- Connect FT232R and ATtiny13 look like this
------ RTS-|ATtiny|-GND RXD-| 13 |- TXD-| |- VCC-| o|-DTR ------
- Connect the FTDI chip with the computer
- Unload the ftdi driver
$ sudo rmmod ftdi_sio
- Test if avrdude works. Tell it to output the hfuse
$ sudo ./avrdude -cft232r1 -pt13 -P ft0 -U hfuse:r:-:h -B 1 avrdude: BitBang OK avrdude: pin assign miso 1 sck 0 mosi 2 reset 4 avrdude: drain OK ft245r: bitclk 4800 -> ft baud 2400 avrdude: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.00s avrdude: Device signature = 0x1e9007 avrdude: current erase-rewrite cycle count is -158 (if being tracked) avrdude: reading hfuse memory: Reading | ################################################## | 100% 0.01s avrdude: writing output file "<stdout>" 0xeb avrdude: safemode: Fuses OK avrdude done. Thank you.
- seems to work. Now upload blink2.hex:
$ sudo avrdude -cft232r -pt13 -P ft0 -U flash:w:blink2.hex -B 1
Now draw RES and the thing will start blinking
4 TroubleShooting
- Symptom
avrdude: /dev/ttyUSB0 open failed
- Solution
Unload the driver blocking /dev/ttyUSB0, in my case: modprobe -r ftdi_sio
5 See also
- http://www.staerk.de/thorsten/ATtiny13
- http://www.staerk.de/thorsten/Compile_a_program_for_attiny13
- http://www.bot-thoughts.com/2011/07/working-with-attiny13.html
- http://doswa.com/2010/08/24/avrdude-5-10-with-ftdi-bitbang.html
- http://software.opensuse.org/package/cross-avr-gcc