ATtiny13

来自Jack's Lab
(版本间的差异)
跳转到: 导航, 搜索
(TroubleShooting)
(Install avrdude)
第92行: 第92行:
 
$ sudo make install
 
$ sudo make install
 
</source>
 
</source>
 +
 +
<br><br>
  
 
=== Upload ===
 
=== Upload ===

2015年11月15日 (日) 13:21的版本

目录

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

3.1 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



3.2 Upload

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



3.3 TroubleShooting

Symptom
avrdude: /dev/ttyUSB0 open failed 
Solution
Unload the driver blocking /dev/ttyUSB0, in my case:
modprobe -r ftdi_sio



4 See also













个人工具
名字空间

变换
操作
导航
工具箱