In order to use an ATtiny85 as an AVRFID, it is necessary to know the exact inner workings of these microcontrollers.

attiny85_pins

For I/O-operations the pins (2=PB3, 3=PB4, 5=PB0, 6=PB1, 7=PB2) can be used. The configuration of the ports is affected by the three 8-bit registers PORTB (data register), DDRB (data direction register) and PINB (port input pins):

  • PORTB: Depends on the configuration of the DDRB. If DDRB is an input, PORTB sets the internal Pull-up resistors (0=off; 1=on). If DDRB is an output, PORTB sets high/low outputs (0=low; 1=high). Single ports are addressed by PORTB0-PORTB5.
  • DDRB: Selects the direction of a pin (0=Input; 1=Output). Single pins are addressed by DDB0-DDB5.
  • PINB: A logical 1 toggles the accroding bit in PORTB. Single port input pins are addressed by PIN0-PIN5.

As one can see in picture above, a whole list of alternative functions of the ports (PB0-PB5) exist. For programming the AVR, port PB2 is connected to the source clock (SCK) and PB0 and PB1 provides a serial peripheral interface bus (MOSI: master output – slave input; MISO: master input – slave output). When working as a RFID tag, the antenna is connected to the ports PB3 and PB4, because these ports can receive external clock sources (XTAL1/XTAL2), normally provided by crystals or oscillators. In this case the radio frequency of the RFID communication will work as this external source clock for the ATtiny85.

Basic informations for the general use of registers (German) help as well as this simple assembler tutorial. Another example for addressing the AVR ports in assembler, can be seen at these links: port description (German), AVR I/O ports description and AVR I/O Instructions.

Sometimes _SFR_IO_xxx functions are used. These functions are specified in the avr/io.h library. The function adds an 0x20 offset, which is needed to handle the overlapping I/O memory RAM. For example the function _SFR_IO_ADDR(DDRB) sets the DDRB. More details can be found in this messageboard thread.