SUMMARY:
My ATtiny84 is running at 1/8th speed, delay(1000);
takes about eight seconds, and changing the fuses and other flags in platformio.ini
seems to have no affect. Thoughts why?
DETAIL:
I’m uploading to an ATtiny84 using an Arduino Uno as a programmer. Relatively basic setup.
No matter what I do though, I can’t seem to get my clock speed right. I’m guessing it’s something wrong with the fuses or CPU but, I’m at a loss.
It’s running at 1/8th speed, so clearly 1MHz vs 8MHz is at issue here, but changing fuses seems to have no affect. Note that I can’t set f_cpu
to 1000000L
because the FastLED library requires a higher clock speed and won’t compile.
Here’s my platformio.ini:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:attiny84]
platform = atmelavr
board = attiny84
framework = arduino
upload_protocol = custom
upload_speed = 19200
upload_flags =
-C
${platformio.packages_dir}/tool-avrdude/avrdude.conf
-p
$BOARD_MCU
-P
$UPLOAD_PORT
-b
$UPLOAD_SPEED
-c
stk500v1
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i
-U lock:w:0xFF:m
board_build.f_cpu = 8000000L
build_unflags = -DCLOCK_SOURCE=6
build_flags = -DCLOCK_SOURCE=0
board_fuses.lfuse = 0xE2
; board_fuses.hfuse = 0xDC
; board_fuses.lfuse = 0x62
board_fuses.hfuse = 0xDF
board_fuses.efuse = 0xFF
lib_deps =
fastled/FastLED@^3.6.0
mathertel/RotaryEncoder@^1.5.3
fabriziop/EEWL@^0.7.0
The project itself is open source. If you want to look at any other code, here’s the repo. Here’s the src folder commit as of the time of this writing. I do my best, but no promises on legibility
I’ve tried swapping out the fuses, with the flags commented above, and also played around with a number of other configurations using the AVR Fuse Calculator.
Bonus related issue: running “Set Fuses” directly (either the PIO menu or by command line) doesn’t work either, hitting me with an error message:
avrdude: no programmer has been specified on the command line or the config file
Specify a programmer using the -c option and try again
Even though under upload flags I clearly have -c
set to stk500v1
. For giggles I tried moving the -c
flag to the top of the listed upload flags, and the error turned into avrdude: ser_open(): can't open device "-b": The system cannot find the file specified.
I’m uh… in over my head here
I’ve tested on a handful of fresh ATtiny84 chips, and tried swapping out the cable, to no effect. And besides, the upload itself WORKS, it’s just at the wrong clock speed - which also makes it impossible to use FastLED, as NeoPixel / WS2812B communication requires fairly precise timing. I’m also using rotary encoders that need careful timing too… yeah. It’s been a long day.
Any idea why this isn’t working?
Thanks in advance!