ATtiny13

来自Jack's Lab
跳转到: 导航, 搜索

目录

1 Overview

The ATtiny13 looks like this:

            ------
     RESET-|o     |- VCC
 PB3(ADC3)-|ATtiny| -PB2 (SCK)
 PB4(ADC2)-|  13  | -PB1(MISO)
       GND-|      | -PB0(MOSI)
            ------

1.1 Features

  • 1K Bytes of In-System Self-programmable Flash program memory via SPI Port
  • 64 Bytes EEPROM
  • 64 Bytes Internal SRAM
  • One 8-bit Timer/Counter with Prescaler and Two PWM Channels
  • 4-channel, 10-bit ADC with Internal Voltage Reference
  • Programmable Watchdog Timer with Separate On-chip Oscillator
  • On-chip Analog Comparator
  • 1.8 - 5.5V for ATtiny13V
  • 2.7 - 5.5V for ATtiny13


1.2 Low Power Consumption

  • Active Mode:
    • 1 MHz, 1.8V: 240 µA
  • Power-down Mode:
    • < 0.1 µA at 1.8V



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
             ------
      RESET-|o     |- VCC
  PB3(ADC3)-|ATtiny| -PB2 (SCK) -> DSR 黄
  PB4(ADC2)-|  13  | -PB1(MISO) -> CTS 绿
        GND-|      | -PB0(MOSI) -> DCD 蓝
             ------

  miso  = 3;  # D3/CTS
  sck   = 5;  # D5/DSR
  mosi  = 6;  # D6/DCD
  reset = 7;  # D7/RI
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:blink.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 Notes

Analog Comparator

The comparator just samples two inputs, AIN0 and AIN1. If the voltage on AIN0 is high than AIN1 a digital 1 will be written to the ACO bit in the ACSR register. A digital 0 will be written if AIN0 is lower than AIN1.




5 See also














个人工具
名字空间

变换
操作
导航
工具箱