I set the fuses of my attiny85 so it uses the internal 128khz clock, prescaled so it is 16kHz. I set the CKOUT fuse too so I can check the clock using an oscilloscope on pin 3 and yes it is 16kHz.
Now my problem is I have no option in the Arduino IDE to compile my code for 16kHz clock speed. The slowest I have is 128khz, which causes the "blink" sketch to run for 8 seconds up, 8 seconds low on my attiny instead of 1 second.
I tried with "attiny" from David A. Mellis using https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json (Slowest : 1Mhz) and "ATTinyCore" from Spence Konde using http://drazzy.com/package_drazzy.com_index.json (Slowest : 128khz).
Does someone know how I can set my Arduino IDE to compile the code for an attiny85 using the 16khz internal clock ?
(Please, no question "why use a 16khz clock ?". The point is, this chip may be set to 16khz clock, so it should be possible to program it to use such clock speed)
Thank you.
1 Answer 1
The Arduino core you've referenced (and pretty much all other AVR Arduino cores too) specify the clock frequency that a particular selected board is running at in the boards.txt
file. The platform.txt
file then retrieves that value and creates the F_CPU
macro with the clock frequency in hertz as a value.
For the ATTinyCore by Spence Konde, the ATTiny85 board definition is the attinyx5
section. There, you can either add a new clock selection menu item or modify the settings of an existing one, e.g.
attinyx5.menu.clock.128internal=128 kHz (internal WDT)
attinyx5.menu.clock.128internal.bootloader.low_fuses=0xC4
attinyx5.menu.clock.128internal.build.f_cpu=128000L
attinyx5.menu.clock.128internal.build.clocksource=3
The file is locally under C:\Users\<user>\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr1円.5.2
.
There, f_cpu
should be modified to 16000L
for 16KHz, the low_fuses
(lfuse) setting should be set to 0x24
and the text "128 kHz" should be adapted too. This is working per the comment on the question.
On a final note, you should create an issue at the core's repo to have a 16kHz added by default.
Also, you might find it easier to work with PlatformIO (+VSCode) instead of the Arduino IDE. A getting started page is here. In PlatformIO, instead of having to modify the internal boards.txt
file, you can create a project configuration file (platformio.ini
) in which you specify the same thing setting.
[env:attiny85]
platform = atmelavr
board = attiny85
framework = arduino
board_build.f_cpu = 16000L
; for upload settings, see
; https://docs.platformio.org/en/latest/platforms/atmelavr.html#upload-using-programmer
-
1Thank you for all the informations ! A lot to read, a lot to learn, a lot to try ! :pSquall124– Squall1242021年08月08日 15:43:08 +00:00Commented Aug 8, 2021 at 15:43
f_cpu
foremost. I don't know aboutclocksource = 3
though, look that up in the code. Theboards.txt
should locally be inC:\Users\<user>\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr1円.5.2