ATtiny85 simulation in AtmelStudio 6.1 (build 2730, SP2)

atmel-studioattinymicrocontrollersimulation

I have written a piece of code which manipulates the DDR for port B:

#include <avr/io.h>

int main(void)
{
    DDRB = 0;

    DDRB = 1;
    DDRB = 2;
    DDRB = 4;
    DDRB = 8;
    DDRB = 16;
    DDRB = 32;
    DDRB = 64;
    DDRB = 128;

    return 0;
}

I'm using the simulator and I'm having a hard time in figuring out how this maps in the I/O view, and what will happen on the actual device. I'm stepping over the DDRB=1..128 instructions.

As expected, DDRB values in the I/O view go from 0x1 to 0x20 as I execute the first 6 instructions, DDRB=1..32. However the other two instructions DDRB=64,128 have the effect of setting DDRB in the I/O view to 0x0. In a way this is not entirely surprising, as the ATtiny85 has only 6 PB pins. But is this behavior expected?

The real question is: what are the little squares in the I/O view next to the value of DDRB saying? Here is the state of DDRB in I/O view after each single instruction in main:

DDRB=  0;  --> DDRB    0x37    0x0    000000
DDRB=  1;  --> DDRB    0x37    0x1    000000
DDRB=  2;  --> DDRB    0x37    0x2    000000
DDRB=  4;  --> DDRB    0x37    0x4    000001
DDRB=  8;  --> DDRB    0x37    0x8    000010
DDRB= 16;  --> DDRB    0x37    0x10   000100
DDRB= 32;  --> DDRB    0x37    0x20   001000
DDRB= 64;  --> DDRB    0x37    0x0    000000
DDRB=128;  --> DDRB    0x37    0x0    000000

Also, if I hover the mouse on the little squares, their names range from Bit 2 (the rightmost) to Bit 7 (the leftmost). How does this map to the pins of the real device? and also Why are they named from 2 to 7 instead than from 0 to 5, as on the device (PB0-PB5)?.

I thought initially that the configuration fuses in the simulator are responsible for certain bits of DDRB not being programmable. For instance I know that RSTDISBL must be unprogrammed to enable PB5, and I guess the same is true for the corresponding DDR. But which column is PB5 on the I/O view?.

I also tried to set the fuses in C code:

FUSES =
{
    .low = 0x62,
    .high = 0x5f,
    .extended = 0xff
};

The setting 0x5f for the high fuse should mean that RSTDISBL is disabled, according to the online fuse calculator. However the behavior in I/O view is still the same.

Best Answer

In a way this is not entirely surprising, as the ATtiny85 has only 6 PB pins. But is this behavior expected?

According to the ATtiny85 datasheet

enter image description here

bits 7:6 of PORTB, DDRB and PINB registers are read only locations with an initial value of 0.
So essentially you are writing to a location that the manufacturer says it is read only in which case all bets are off regarding the expected behaviour. It may work fine or it may cause problems.

what are the little squares in the I/O view next to the value of DDRB saying? But which column is PB5 on the I/O view?.

Each square is one bit, starting from 0 (right-most side) to 7 (left-most side). My version is slightly older (v6.x) and shown the bit numbers fine

enter image description here

enter image description here

I have added with red the bit representation of each box


Regarding the fuses, I don't think they have any effect on the simulation and you can't change them at runtime either.
Adding them in the code (I have never used that way) is just a way to tell the programmer to set them at a specific value during the device programming, it doesn't have an effect during the code execution.