- •Features
- •Pin Configurations
- •Disclaimer
- •Overview
- •Block Diagram
- •Pin Descriptions
- •Port B (PB5..PB0)
- •RESET
- •AVR CPU Core
- •Introduction
- •Architectural Overview
- •Status Register
- •Stack Pointer
- •Interrupt Response Time
- •SRAM Data Memory
- •Data Memory Access Times
- •EEPROM Data Memory
- •EEPROM Read/Write Access
- •Atomic Byte Programming
- •Split Byte Programming
- •Erase
- •Write
- •I/O Memory
- •Clock Systems and their Distribution
- •CPU Clock – clkCPU
- •I/O Clock – clkI/O
- •Flash Clock – clkFLASH
- •ADC Clock – clkADC
- •Clock Sources
- •Default Clock Source
- •External Clock
- •System Clock Prescaler
- •Switching Time
- •Idle Mode
- •Power-down Mode
- •Analog to Digital Converter
- •Analog Comparator
- •Brown-out Detector
- •Internal Voltage Reference
- •Watchdog Timer
- •Port Pins
- •Resetting the AVR
- •Reset Sources
- •Power-on Reset
- •External Reset
- •Brown-out Detection
- •Watchdog Reset
- •Watchdog Timer
- •Timed Sequences for Changing the Configuration of the Watchdog Timer
- •Safety Level 1
- •Safety Level 2
- •Interrupts
- •I/O Ports
- •Introduction
- •Configuring the Pin
- •Toggling the Pin
- •Reading the Pin Value
- •Unconnected Pins
- •Alternate Port Functions
- •Alternate Functions of Port B
- •Register Description for I/O-Ports
- •Port B Data Register – PORTB
- •External Interrupts
- •8-bit Timer/Counter0 with PWM
- •Overview
- •Registers
- •Definitions
- •Counter Unit
- •Output Compare Unit
- •Force Output Compare
- •Modes of Operation
- •Normal Mode
- •Fast PWM Mode
- •Phase Correct PWM Mode
- •Prescaler Reset
- •External Clock Source
- •Analog Comparator
- •Analog Comparator Multiplexed Input
- •Features
- •Operation
- •Starting a Conversion
- •Changing Channel or Reference Selection
- •ADC Input Channels
- •ADC Voltage Reference
- •ADC Noise Canceler
- •Analog Input Circuitry
- •ADC Accuracy Definitions
- •ADC Conversion Result
- •ADLAR = 0
- •ADLAR = 1
- •debugWIRE On-chip Debug System
- •Features
- •Overview
- •Physical Interface
- •Software Break Points
- •Limitations of debugWIRE
- •debugWIRE Related Register in I/O Memory
- •debugWire Data Register – DWDR
- •Performing a Page Write
- •Reading the Fuse and Lock Bits from Software
- •Preventing Flash Corruption
- •Fuse Bytes
- •Latching of Fuses
- •Signature Bytes
- •Calibration Byte
- •Page Size
- •Serial Downloading
- •Data Polling Flash
- •Data Polling EEPROM
- •Chip Erase
- •Programming the Flash
- •Programming the EEPROM
- •Reading the Flash
- •Reading the EEPROM
- •Power-off sequence
- •Electrical Characteristics
- •Absolute Maximum Ratings*
- •External Clock Drive Waveforms
- •External Clock Drive
- •ADC Characteristics – Preliminary Data
- •Active Supply Current
- •Idle Supply Current
- •Power-down Supply Current
- •Pin Pull-up
- •Register Summary
- •Instruction Set Summary
- •Ordering Information
- •Packaging Information
- •Erratas
- •Table of Contents
Serial Downloading |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Both the Flash and EEPROM memory arrays can be programmed using the serial SPI |
||||||||||||||
|
bus while |
RESET |
is pulled to GND. The serial interface consists of pins SCK, MOSI |
|||||||||||
|
(input) and MISO (output). After |
RESET |
is set low, the Programming Enable instruction |
|||||||||||
|
needs to be executed first before program/erase operations can be executed. NOTE, in |
|||||||||||||
|
Table 49 on page 102, the pin mapping for SPI programming is listed. Not all parts use |
|||||||||||||
|
the SPI pins dedicated for the internal SPI interface. |
|||||||||||||
|
Figure 53. Serial Programming and Verify(1) |
|||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+1.8 - 5.5V |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VCC |
|
|
|
|
MOSI |
|
|
|||||||||
|
|
|
|
|||||||||||
|
|
|
MISO |
|
|
|
||||||||
|
|
|
|
|
||||||||||
|
|
|
SCK |
|
|
|||||||||
|
|
|
|
|||||||||||
RESET
GND
Notes: 1. If the device is clocked by the internal Oscillator, it is no need to connect a clock source to the CLKI pin.
Table 49. Pin Mapping Serial Programming
Symbol |
Pins |
I/O |
Description |
|
|
|
|
MOSI |
PB0 |
I |
Serial Data in |
|
|
|
|
MISO |
PB1 |
O |
Serial Data out |
|
|
|
|
SCK |
PB2 |
I |
Serial Clock |
|
|
|
|
When programming the EEPROM, an auto-erase cycle is built into the self-timed programming operation (in the Serial mode ONLY) and there is no need to first execute the Chip Erase instruction. The Chip Erase operation turns the content of every memory location in both the Program and EEPROM arrays into 0xFF.
Depending on CKSEL Fuses, a valid clock must be present. The minimum low and high periods for the serial clock (SCK) input are defined as follows:
Low:> 2 CPU clock cycles for fck < 12 MHz, 3 CPU clock cycles for fck >= 12 MHz
High:> 2 CPU clock cycles for fck < 12 MHz, 3 CPU clock cycles for fck >= 12 MHz
102 ATtiny13
2535A–AVR–06/03
Serial Programming
Algorithm
ATtiny13
When writing serial data to the ATtiny13, data is clocked on the rising edge of SCK.
When reading data from the ATtiny13, data is clocked on the falling edge of SCK. See Figure 54 and Figure 55 for timing details.
To program and verify the ATtiny13 in the Serial Programming mode, the following sequence is recommended (see four byte instruction formats in Table 51):
1.Power-up sequence:
Apply power between VCC and GND while RESET and SCK are set to “0”. In some systems, the programmer can not guarantee that SCK is held low during power-up. In this case, RESET must be given a positive pulse of at least two CPU clock cycles duration after SCK has been set to “0”.
2.Wait for at least 20 ms and enable serial programming by sending the Programming Enable serial instruction to pin MOSI.
3.The serial programming instructions will not work if the communication is out of synchronization. When in sync. the second byte (0x53), will echo back when issuing the third byte of the Programming Enable instruction. Whether the echo is correct or not, all four bytes of the instruction must be transmitted. If the 0x53 did not echo back, give RESET a positive pulse and issue a new Programming Enable command.
4.The Flash is programmed one page at a time. The memory page is loaded one byte at a time by supplying the 5 LSB of the address and data together with the Load Program memory Page instruction. To ensure correct loading of the page, the data low byte must be loaded before data high byte is applied for a given address. The Program memory Page is stored by loading the Write Program memory Page instruction with the 3 MSB of the address. If polling is not used,
the user must wait at least tWD_FLASH before issuing the next page. (See Table 50.) Accessing the serial programming interface before the Flash write operation completes can result in incorrect programming.
5.A: The EEPROM array is programmed one byte at a time by supplying the address and data together with the appropriate Write instruction. An EEPROM memory location is first automatically erased before new data is written. If polling
is not used, the user must wait at least tWD_EEPROM before issuing the next byte. (See Table 50.) In a chip erased device, no 0xFFs in the data file(s) need to be programmed.
B: The EEPROM array is programmed one page at a time. The Memory page is loaded one byte at a time by supplying the 2 LSB of the address and data together with the Load EEPROM Memory Page instruction. The EEPROM Memory Page is stored by loading the Write EEPROM Memory Page Instruction with the 4 MSB of the address. When using EEPROM page access only byte locations loaded with the Load EEPROM Memory Page instruction is altered. The remaining locations remain unchanged. If polling is not used, the used must wait
at least tWD_EEPROM before issuing the next page (See Table 48). In a chip erased device, no 0xFF in the data file(s) need to be programmed.
6.Any memory location can be verified by using the Read instruction which returns the content at the selected address at serial output MISO.
7.At the end of the programming session, RESET can be set high to commence normal operation.
8.Power-off sequence (if needed): Set RESET to “1”.
Turn VCC power off.
103
2535A–AVR–06/03
Data Polling Flash |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
When a page is being programmed into the Flash, reading an address location within |
|||||||
|
the page being programmed will give the value 0xFF. At the time the device is ready for |
||||||
|
a new page, the programmed value will read correctly. This is used to determine when |
||||||
|
the next page can be written. Note that the entire page is written simultaneously and any |
||||||
|
address within the page can be used for polling. Data polling of the Flash will not work |
||||||
|
for the value 0xFF, so when programming this value, the user will have to wait for at |
||||||
|
least tWD_FLASH before programming the next page. As a chip-erased device contains |
||||||
|
0xFF in all locations, programming of addresses that are meant to contain 0xFF, can be |
||||||
|
skipped. See Table 50 for tWD_FLASH value. |
|
|||||
Data Polling EEPROM |
When a new byte has been written and is being programmed into EEPROM, reading the |
||||||
|
address location being programmed will give the value 0xFF. At the time the device is |
||||||
|
ready for a new byte, the programmed value will read correctly. This is used to deter- |
||||||
|
mine when the next byte can be written. This will not work for the value 0xFF, but the |
||||||
|
user should have the following in mind: As a chip-erased device contains 0xFF in all |
||||||
|
locations, programming of addresses that are meant to contain 0xFF, can be skipped. |
||||||
|
This does not apply if the EEPROM is re-programmed without chip erasing the device. |
||||||
|
In this case, data polling cannot be used for the value 0xFF, and the user will have to |
||||||
|
wait at least tWD_EEPROM before programming the next byte. See Table 50 for tWD_EEPROM |
||||||
|
value. |
|
|||||
|
Table 50. Minimum Wait Delay Before Writing the Next Flash or EEPROM Location |
||||||
|
|
|
|
||||
|
Symbol |
|
|
|
Minimum Wait Delay |
||
|
|
|
|
||||
|
tWD_FLASH |
|
|
|
4.5 ms |
||
|
tWD_EEPROM |
|
|
|
4.0 ms |
||
|
tWD_ERASE |
|
|
|
4.0 ms |
||
|
tWD_FUSE |
|
|
|
4.5 ms |
||
Figure 54. Serial Programming Waveforms
SERIAL DATA INPUT |
MSB |
LSB |
(MOSI) |
|
|
SERIAL DATA OUTPUT |
MSB |
LSB |
(MISO) |
|
|
SERIAL CLOCK INPUT |
|
|
(SCK) |
|
|
SAMPLE |
|
|
104 ATtiny13
2535A–AVR–06/03
|
|
|
|
|
|
|
|
|
|
|
|
ATtiny13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
Table 51. Serial Programming Instruction Set |
|
|
|
|
|
|||||||
|
|
|
|
|
|
|||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Instruction Format |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||
Instruction |
Byte 1 |
Byte 2 |
Byte 3 |
Byte4 |
|
Operation |
||||||
|
|
|
|
|
|
|
|
|||||
Programming Enable |
1010 1100 |
0101 0011 |
xxxx xxxx |
xxxx xxxx |
|
Enable Serial Programming after |
||||||
|
|
|
|
|
|
|
|
|
|
RESET |
goes low. |
|
|
|
|
|
|
|
|
||||||
Chip Erase |
1010 1100 |
100x xxxx |
xxxx xxxx |
xxxx xxxx |
|
Chip Erase EEPROM and Flash. |
||||||
|
|
|
|
|
|
|
||||||
Read Program Memory |
0010 H000 |
0000 000a |
bbbb bbbb |
oooo oooo |
|
Read H (high or low) data o from |
||||||
|
|
|
|
|
|
|
|
|
|
Program memory at word address a:b. |
||
|
|
|
|
|
|
|
||||||
Load Program Memory Page |
0100 H000 |
000x xxxx |
xxxb bbbb |
iiii iiii |
|
Write H (high or low) data i to Program |
||||||
|
|
|
|
|
|
|
|
|
|
memory page at word address b. Data |
||
|
|
|
|
|
|
|
|
|
|
low byte must be loaded before Data |
||
|
|
|
|
|
|
|
|
|
|
high byte is applied within the same |
||
|
|
|
|
|
|
|
|
|
|
address. |
||
|
|
|
|
|
|
|
||||||
Write Program Memory Page |
0100 1100 |
0000 000a |
bbxx xxxx |
xxxx xxxx |
|
Write Program memory Page at |
||||||
|
|
|
|
|
|
|
|
|
|
address a:b. |
||
|
|
|
|
|
|
|
||||||
Read EEPROM Memory |
1010 0000 |
000x xxxx |
xxbb bbbb |
oooo oooo |
|
Read data o from EEPROM memory at |
||||||
|
|
|
|
|
|
|
|
|
|
address b. |
||
|
|
|
|
|
|
|
||||||
Write EEPROM Memory |
1100 0000 |
000x xxxx |
xxbb bbbb |
iiii iiii |
|
Write data i to EEPROM memory at |
||||||
|
|
|
|
|
|
|
|
|
|
address b. |
||
|
|
|
|
|
|
|
||||||
Load EEPROM Memory |
1100 0001 |
0000 0000 |
0000 00bb |
iiii iiii |
|
Load data i to EEPROM memory page |
||||||
Page (page access) |
|
|
|
|
|
buffer. After data is loaded, program |
||||||
|
|
|
|
|
|
|
|
|
|
EEPROM page. |
||
|
|
|
|
|
|
|
|
|
||||
Write EEPROM Memory |
1100 0010 |
00xx xxxx |
xxbb bb00 |
xxxx xxxx |
|
|
|
|
||||
Page (page access) |
|
|
|
|
|
Write EEPROM page at address b. |
||||||
|
|
|
|
|
|
|
||||||
Read Lock bits |
0101 1000 |
0000 0000 |
xxxx xxxx |
xxoo oooo |
|
Read Lock bits. “0” = programmed, “1” |
||||||
|
|
|
|
|
|
|
|
|
|
= unprogrammed. See Table 43 on |
||
|
|
|
|
|
|
|
|
|
|
page 99 for details. |
||
|
|
|
|
|
|
|
||||||
Write Lock bits |
1010 1100 |
111x xxxx |
xxxx xxxx |
11ii iiii |
|
Write Lock bits. Set bits = “0” to |
||||||
|
|
|
|
|
|
|
|
|
|
program Lock bits. See Table 43 on |
||
|
|
|
|
|
|
|
|
|
|
page 99 for details. |
||
|
|
|
|
|
|
|
||||||
Read Signature Byte |
0011 0000 |
000x xxxx |
xxxx xxbb |
oooo oooo |
|
Read Signature Byte o at address b. |
||||||
|
|
|
|
|
|
|
||||||
Write Fuse bits |
1010 1100 |
1010 0000 |
xxxx xxxx |
iiii iiii |
|
Set bits = “0” to program, “1” to |
||||||
|
|
|
|
|
|
|
|
|
|
unprogram. |
||
|
|
|
|
|
|
|
||||||
Write Fuse High bits |
1010 1100 |
1010 1000 |
xxxx xxxx |
iiii iiii |
|
Set bits = “0” to program, “1” to |
||||||
|
|
|
|
|
|
|
|
|
|
unprogram. See Table 37 on page 81 |
||
|
|
|
|
|
|
|
|
|
|
for details. |
||
|
|
|
|
|
|
|
||||||
Read Fuse bits |
0101 0000 |
0000 0000 |
xxxx xxxx |
oooo oooo |
|
Read Fuse bits. “0” = programmed, “1” |
||||||
|
|
|
|
|
|
|
|
|
|
= unprogrammed. |
||
|
|
|
|
|
|
|
||||||
Read Fuse High bits |
0101 1000 |
0000 1000 |
xxxx xxxx |
oooo oooo |
|
Read Fuse High bits. “0” = pro- |
||||||
|
|
|
|
|
|
|
|
|
|
grammed, “1” = unprogrammed. See |
||
|
|
|
|
|
|
|
|
|
|
Table 37 on page 81 for details. |
||
|
|
|
|
|
|
|
||||||
Read Calibration Byte |
0011 1000 |
000x xxxx |
0000 0000 |
oooo oooo |
|
Read Calibration Byte |
||||||
|
|
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
If o = “1”, a programming operation is |
||
Poll RDY/BSY |
|
|
1111 0000 |
0000 0000 |
xxxx xxxx |
xxxx xxxo |
|
|||||
|
|
|
|
|
|
|
|
|
|
still busy. Wait until this bit returns to |
||
|
|
|
|
|
|
|
|
|
|
“0” before applying another command. |
||
|
|
|
|
|
|
|
|
|
|
|
|
|
Note: a = address high bits, b = address low bits, H = 0 - Low byte, 1 - High Byte, o = data out, i = data in, x = don’t care
105
2535A–AVR–06/03
Serial Programming
Characteristics
High-voltage Serial
Programming
Figure 55. Serial Programming Timing
MOSI
tOVSH |
|
|
|
tSHOX |
tSLSH |
|
|
SCK
tSHSL
MISO
tSLIV
Table 52. Serial Programming Characteristics, TA = -40°C to 85°C, VCC = 1.8 - 5.5V (Unless Otherwise Noted)
Symbol |
Parameter |
Min |
Typ |
Max |
Units |
|
|
|
|
|
|
1/tCLCL |
Oscillator Frequency (ATtiny13V) |
0 |
|
1 |
MHz |
tCLCL |
Oscillator Period (ATtiny13V) |
1,000 |
|
|
ns |
|
Oscillator Frequency (ATtiny13L, VCC = 2.7 - |
|
|
|
|
1/tCLCL |
5.5V) |
0 |
|
8 |
MHz |
tCLCL |
Oscillator Period (ATtiny13L, VCC = 2.7 - 5.5V) |
125 |
|
|
ns |
|
Oscillator Frequency (ATtiny13, VCC = 4.5V - |
|
|
|
|
1/tCLCL |
5.5V) |
0 |
|
16 |
MHz |
tCLCL |
Oscillator Period (ATtiny13, VCC = 4.5V - 5.5V) |
67 |
|
|
ns |
tSHSL |
SCK Pulse Width High |
2 tCLCL* |
|
|
ns |
tSLSH |
SCK Pulse Width Low |
2 tCLCL* |
|
|
ns |
tOVSH |
MOSI Setup to SCK High |
tCLCL |
|
|
ns |
tSHOX |
MOSI Hold after SCK High |
2 tCLCL |
|
|
ns |
tSLIV |
SCK Low to MISO Valid |
TBD |
TBD |
TBD |
ns |
Note: 1. |
2 tCLCL for fck < 12 MHz, 3 tCLCL for fck >= 12 MHz |
|
|
|
|
This section describes how to program and verify Flash Program memory, EEPROM Data memory, Lock bits and Fuse bits in the ATtiny13.
106 ATtiny13
2535A–AVR–06/03
ATtiny13
Figure 56. High-voltage Serial Programming
11.5 - 12.5V |
4.5 - 5.5V |
||||||||
|
|
|
|
ATtiny |
|
|
|
|
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PB5 (RESET) |
VCC |
|
|
|
||
|
|
|
|
||||||
SERIAL CLOCK INPUT |
|
|
|
PB3 (XTAL1) |
PB2 |
|
|
|
|
SERIAL DATA OUTPUT |
|
|
|
|
|
||||||||
|
|
|
|
|
|
PB1 |
|
|
|
|
SERIAL INSTR. INPUT |
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
GND |
PB0 |
|
|
|
|
SERIAL DATA INPUT |
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
Table 53. Pin Name Mapping
Signal Name in High-voltage |
|
|
|
Serial Programming Mode |
Pin Name |
I/O |
Function |
|
|
|
|
SDI |
PB0 |
I |
Serial Data Input |
|
|
|
|
SII |
PB1 |
I |
Serial Instruction Input |
|
|
|
|
SDO |
PB2 |
O |
Serial Data Output |
|
|
|
|
SCI |
PB3 |
I |
Serial Clock Input (min. 220ns period) |
|
|
|
|
The minimum period for the Serial Clock Input (SCI) during High-voltage Serial Programming is 220 ns.
Table 54. Pin Values Used to Enter Programming Mode
Pin |
Symbol |
Value |
|
|
|
SDI |
Prog_enable[0] |
0 |
|
|
|
SII |
Prog_enable[1] |
0 |
|
|
|
SDO |
Prog_enable[2] |
0 |
|
|
|
107
2535A–AVR–06/03
