PlatformIO Community

ATTiny85 set to 8MHz

How do I set an ATTiny85 to 8MHz (internal)?
In the ArduinoIDE there was a menu option to choose from but how do I do that in PlatformIO?

Btw setting this in the .ini only tells the compiler how fast the chip is but will not change the speed of the MCU:

; change MCU frequency
board_build.f_cpu = 80000000L

Thanks

Calculate the fuses for your config, then you can write them in the platformio.ini and program them accordingly (pio run -t fuses). You can also use external programs for this like BitBurner.

1 Like

Ok, I’ve calculated the fuses and put this into the .ini

[env:custom_fuses]
platform = atmelavr
board = attiny85
framework = arduino
board_fuses.lfuse = 0xE2
board_fuses.hfuse = 0xDF
board_fuses.efuse = 0xFF

this is the output. I doesn’t seem to set the fuses:

Processing custom_fuses (platform: atmelavr; board: attiny85; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/attiny85.html
PLATFORM: Atmel AVR 2.2.0 > Generic ATtiny85
HARDWARE: ATTINY85 8MHz, 512B RAM, 8KB Flash
DEBUG: Current (simavr) On-board (simavr)
PACKAGES:
 - framework-arduino-avr-attiny 1.3.2
 - tool-avrdude 1.60300.200527 (6.3.0)
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 9 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\custom_fuses\src\main.cpp.o
Archiving .pio\build\custom_fuses\libFrameworkArduinoVariant.a
Compiling .pio\build\custom_fuses\FrameworkArduino\HardwareSerial.cpp.o
Compiling .pio\build\custom_fuses\FrameworkArduino\Print.cpp.o
Compiling .pio\build\custom_fuses\FrameworkArduino\Stream.cpp.o
Compiling .pio\build\custom_fuses\FrameworkArduino\TinySoftwareSerial.cpp.o
Compiling .pio\build\custom_fuses\FrameworkArduino\Tone.cpp.o
Compiling .pio\build\custom_fuses\FrameworkArduino\WInterrupts.c.o
Compiling .pio\build\custom_fuses\FrameworkArduino\WMath.cpp.o
Compiling .pio\build\custom_fuses\FrameworkArduino\WString.cpp.o
Compiling .pio\build\custom_fuses\FrameworkArduino\abi.cpp.o
Compiling .pio\build\custom_fuses\FrameworkArduino\main.cpp.o
Compiling .pio\build\custom_fuses\FrameworkArduino\new.cpp.o
Compiling .pio\build\custom_fuses\FrameworkArduino\wiring.c.o
Compiling .pio\build\custom_fuses\FrameworkArduino\wiring_analog.c.o
Compiling .pio\build\custom_fuses\FrameworkArduino\wiring_digital.c.o
Compiling .pio\build\custom_fuses\FrameworkArduino\wiring_pulse.c.o
Compiling .pio\build\custom_fuses\FrameworkArduino\wiring_shift.c.o
Archiving .pio\build\custom_fuses\libFrameworkArduino.a
Linking .pio\build\custom_fuses\firmware.elf
Building .pio\build\custom_fuses\firmware.hex
Checking size .pio\build\custom_fuses\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  16.6% (used 85 bytes from 512 bytes)
Flash: [==        ]  16.2% (used 1326 bytes from 8192 bytes)
Configuring upload protocol...
AVAILABLE: usbtiny
CURRENT: upload_protocol = usbtiny
Looking for upload port...
Uploading .pio\build\custom_fuses\firmware.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e930b (probably t85)
avrdude: erasing chip
avrdude: reading input file ".pio\build\custom_fuses\firmware.hex"
avrdude: writing flash (1326 bytes):

Writing | ################################################## | 100% 2.29s

avrdude: 1326 bytes of flash written
avrdude: verifying flash memory against .pio\build\custom_fuses\firmware.hex:
avrdude: load data flash data from input file .pio\build\custom_fuses\firmware.hex:
avrdude: input file .pio\build\custom_fuses\firmware.hex contains 1326 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 2.57s

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

avrdude: safemode: Fuses OK (E:FF, H:DF, L:62)

avrdude done.  Thank you.
```

This looks to me as if you have pressed the “Upload” button instead of executing the “Set Fuses” task or pio run -t fuses as shown above.

image

You should get something like

$ pio run -t fuses 
Processing custom_fuses (platform: atmelavr; board: attiny85; framework: arduino)
------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/attiny85.html
PLATFORM: Atmel AVR 2.2.0 > Generic ATtiny85
HARDWARE: ATTINY85 8MHz, 512B RAM, 8KB Flash
DEBUG: Current (simavr) On-board (simavr)
PACKAGES: 
 - framework-arduino-avr-attiny 1.3.2 
 - tool-avrdude 1.60300.200527 (6.3.0) 
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 11 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Selected fuses: [lfuse = 0xE2, hfuse = 0xDF, efuse = 0xFF]
Setting fuses
...
1 Like

I wasn’t aware that there is something like project tasks.
Now it works - thanks for helping me out!

Bonus question: now I have to environs in my ini and when I press upload two tasks are run consecutive.
Do I have to delete the fuse part or is there a better way?

In your case you should really just have one environment which has the correct board and fuses – doesn’t make sense to have one without and one with. So just copy the

board_fuses.lfuse = 0xE2
board_fuses.hfuse = 0xDF
board_fuses.efuse = 0xFF

in your main env and work with that.

On a side note you can use the documented default_envs command to select a default environment (or more) if you ever have two or more.

[platformio]
default_envs = attiny85

[env:attiny85]
platform = atmelavr
board = attiny85
framework = arduino
board_fuses.lfuse = 0xE2
board_fuses.hfuse = 0xDF
board_fuses.efuse = 0xFF

[env:some_other_cool_env]
board = ..

Also as the docs show each own environment has its own submenu so you can always execute specific tasks (build, upload, fuses…) on that environment through that menu.

2 Likes

Thanks for that thorough answer!