Avrdude to read fuses [solved]

I have a new AtTiny85 chip on a breadboard, connected to an Arduino Uno serving as ISP.

I’d like to understand the fuses of the AtTiny85 and then set it up to be 16.5MHz internal clock.

I read:

  • lfuse 62
  • hfuse DF
  • efuse FF

Decoding with http://www.engbedded.com/fusecalc/
AtTiny85: ckdiv8, spien
Does that mean the chip runs at 8MHz/8 = 1MHz ?

If I set lfuse to 0xE2 (removing ckdiv8) then I should be running 8MHz?

If I want to run at 16.5MHz should I write:

  • lfuse F1 (CKSEL 001, SUT 11 i.e. PLL clock, 16CK/14CK + 64ms)
  • hfuse DD (BODlevel1 2.8V)
  • efuse FE (self program enable)

What fuse properties must I always preserve to not brick it?

  • SPI program download (needed to send program)
  • Reset enabled (needed to program with ISP?)
  • Only internal or PLL clock if I have no cristal.

Thanks!

For those trying to read the fuses, that’s how I got it to work:

I had no clue what are the parameters so I used the parameters spewed by AVRdude when I compile successfully, and used the -U lfuse:r:-:i command.

Getting Fuses:

PS C:\Program Files (x86)\Arduino\hardware\tools\avr\bin> ./avrdude.exe -c stk500v1 -p attiny85 -P com4 -U lfuse:r:-:i -v -C ..\etc\avrdude.conf -b 19200

avrdude.exe: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2009 Joerg Wunsch

             System wide configuration file is "..\etc\avrdude.conf"

             Using Port                    : com4
             Using Programmer              : stk500v1
             Overriding Baud Rate          : 19200
             AVR Part                      : ATtiny85
             Chip Erase delay              : 400000 us
             PAGEL                         : P00
             BS2                           : P00
             RESET disposition             : possible i/o
             RETRY pulse                   : SCK
             serial program mode           : yes
             parallel program mode         : yes
             Timeout                       : 200
             StabDelay                     : 100
             CmdexeDelay                   : 25
             SyncLoops                     : 32
             ByteDelay                     : 0
             PollIndex                     : 3
             PollValue                     : 0x53
             Memory Detail                 :

                                      Block Poll               Page
          Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               eeprom        65    12     4    0 no        512    4      0  4000  4500 0xff 0xff
               flash         65     6    32    0 yes      8192   64    128 30000 30000 0xff 0xff
               signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
               lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
               lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
               hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
               efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
               calibration    0     0     0    0 no          2    0      0     0     0 0x00 0x00

             Programmer Type : STK500
             Description     : Atmel STK500 Version 1.x firmware
             Hardware Version: 2
             Firmware Version: 1.18
             Topcard         : Unknown
             Vtarget         : 0.0 V
             Varef           : 0.0 V
             Oscillator      : Off
             SCK period      : 0.1 us

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ## | 100% 0.06s

avrdude.exe: Device signature = 0x1e930b
avrdude.exe: safemode: lfuse reads as 62
avrdude.exe: safemode: hfuse reads as DF
avrdude.exe: safemode: efuse reads as FF
avrdude.exe: reading lfuse memory:

Reading | ## | 100% 0.02s

avrdude.exe: writing output file "<stdout>"
:01000000629D
:00000001FF

avrdude.exe: safemode: lfuse reads as 62
avrdude.exe: safemode: hfuse reads as DF
avrdude.exe: safemode: efuse reads as FF
avrdude.exe: safemode: Fuses OK (H:FF, E:DF, L:62)

avrdude.exe done.  Thank you.

Getting ISP programmer properties from a successfult build:

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -pattiny85 -cstk500v1 -PCOM4 -b19200 -Uflash:w:C:\Users\dant\AppData\Local\Temp\build4666128290593242810.tmp/YAMA_2.0_Tiny85_temp_4th_ju.cpp.hex:i 

avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : [b]COM4[/b]
         Using Programmer              : [b]stk500v1[/b]
         Overriding Baud Rate          : [b]19200[/b]
         AVR Part                      : [b]ATtiny85[/b]
         Chip Erase delay              : 400000 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : possible i/o
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    12     4    0 no        512    4      0  4000  4500 0xff 0xff
           flash         65     6    32    0 yes      8192   64    128 30000 30000 0xff 0xff
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          2    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ### | 100% 0.06s

avrdude: Device signature = 0x1e930b
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "C:\Users\dant\AppData\Local\Temp\build4666128290593242810.tmp/YAMA_2.0_Tiny85_temp_4th_ju.cpp.hex"
avrdude: writing flash (6212 bytes):

Writing | ################################################## | 100% 10.44s

avrdude: 6212 bytes of flash written
avrdude: verifying flash memory against C:\Users\dant\AppData\Local\Temp\build4666128290593242810.tmp/YAMA_2.0_Tiny85_temp_4th_ju.cpp.hex:
avrdude: load data flash data from input file C:\Users\dant\AppData\Local\Temp\build4666128290593242810.tmp/YAMA_2.0_Tiny85_temp_4th_ju.cpp.hex:
avrdude: input file C:\Users\dant\AppData\Local\Temp\build4666128290593242810.tmp/YAMA_2.0_Tiny85_temp_4th_ju.cpp.hex contains 6212 bytes
avrdude: reading on-chip flash data:

Reading | #### | 100% 6.75s

avrdude: verifying ...
avrdude: 6212 bytes of flash verified

avrdude done.  Thank you.

a-ha I remembered I have a Digispark AtTiny85 board that's wired.

Device signature = 0x1e930b lfuse E1 (PLL clock, CKSEL=0001, SUT=10 i.e: 1K CK/14 CK +64ms) hfuse DD (SPI enable, BODlevel1 2.8V) efuse FE (self programming enabled, used by bootloaders)

Looks like the fuse values I had picked were pretty good. I don't quite grok what CKSEL/SUT delays really do. :/

Well, jackpot. It works.

I reprogrammed the fuses and the WS2812B LEDs work now...

PS C:\Program Files (x86)\Arduino\hardware\tools\avr\bin> ./avrdude.exe -c stk50
0v1 -p attiny85 -P com4 -U [b]lfuse:w:0xe1:m[/b] -U [b]hfuse:w:0xdd:m[/b] -U [b]efuse:w:0xfe:m [/b]-v
 -C ..\etc\avrdude.conf -b 19200

avrdude.exe: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2009 Joerg Wunsch

             System wide configuration file is "..\etc\avrdude.conf"

             Using Port                    : com4
             Using Programmer              : stk500v1
             Overriding Baud Rate          : 19200
             AVR Part                      : ATtiny85
             Chip Erase delay              : 400000 us
             PAGEL                         : P00
             BS2                           : P00
             RESET disposition             : possible i/o
             RETRY pulse                   : SCK
             serial program mode           : yes
             parallel program mode         : yes
             Timeout                       : 200
             StabDelay                     : 100
             CmdexeDelay                   : 25
             SyncLoops                     : 32
             ByteDelay                     : 0
             PollIndex                     : 3
             PollValue                     : 0x53
             Memory Detail                 :

                                      Block Poll               Page
          Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW
 MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ -----
 ----- ---------
               eeprom        65    12     4    0 no        512    4      0  4000
  4500 0xff 0xff
               flash         65     6    32    0 yes      8192   64    128 30000
 30000 0xff 0xff
               signature      0     0     0    0 no          3    0      0     0
     0 0x00 0x00
               lock           0     0     0    0 no          1    0      0  9000
  9000 0x00 0x00
               lfuse          0     0     0    0 no          1    0      0  9000
  9000 0x00 0x00
               hfuse          0     0     0    0 no          1    0      0  9000
  9000 0x00 0x00
               efuse          0     0     0    0 no          1    0      0  9000
  9000 0x00 0x00
               calibration    0     0     0    0 no          2    0      0     0
     0 0x00 0x00

             Programmer Type : STK500
             Description     : Atmel STK500 Version 1.x firmware
             Hardware Version: 2
             Firmware Version: 1.18
             Topcard         : Unknown
             Vtarget         : 0.0 V
             Varef           : 0.0 V
             Oscillator      : Off
             SCK period      : 0.1 us

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.06s

avrdude.exe: Device signature = 0x1e930b
avrdude.exe: safemode: lfuse reads as 62
avrdude.exe: safemode: hfuse reads as DF
avrdude.exe: safemode: efuse reads as FF
avrdude.exe: reading input file "0xe1"
avrdude.exe: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.06s

avrdude.exe: 1 bytes of lfuse written
avrdude.exe: verifying lfuse memory against 0xe1:
avrdude.exe: load data lfuse data from input file 0xe1:
avrdude.exe: input file 0xe1 contains 1 bytes
avrdude.exe: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.02s

avrdude.exe: verifying ...
avrdude.exe: 1 bytes of lfuse verified
avrdude.exe: reading input file "0xdd"
avrdude.exe: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.06s

avrdude.exe: 1 bytes of hfuse written
avrdude.exe: verifying hfuse memory against 0xdd:
avrdude.exe: load data hfuse data from input file 0xdd:
avrdude.exe: input file 0xdd contains 1 bytes
avrdude.exe: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.02s

avrdude.exe: verifying ...
avrdude.exe: 1 bytes of hfuse verified
avrdude.exe: reading input file "0xfe"
avrdude.exe: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.06s

avrdude.exe: 1 bytes of efuse written
avrdude.exe: verifying efuse memory against 0xfe:
avrdude.exe: load data efuse data from input file 0xfe:
avrdude.exe: input file 0xfe contains 1 bytes
avrdude.exe: reading on-chip efuse data:

Reading | ################################################## | 100% 0.02s

avrdude.exe: verifying ...
avrdude.exe: 1 bytes of efuse verified

avrdude.exe: safemode: lfuse reads as E1
avrdude.exe: safemode: hfuse reads as DD
avrdude.exe: safemode: efuse reads as FE
avrdude.exe: safemode: Fuses OK (H:FE, E:DD, L:E1)

avrdude.exe done.  Thank you.

Do you have ATMEL's doc2586.pdf, the ATtiny85 family datasheet?

It’s online somewhere. I’ve perused it but there’s some concepts I have not understood.
A layman explanation would be great in particular what CKSEL / SUT settings really mean
in practical terms.

I get the internal clock is 6 or 8MHz, and that there’s a PLL that somehow generates a semi-precise 16.5MHz (why 16.5?), and the possibility to divide the clock by 5.

With an external crystal the clock runs up to 20MHz and as low as a few 100KHz.

Now why are there many selectable delays for whatever events, IDK.