September 17, 2024

Biscotti firmware -- fuses and CPU clock

The Biscotti source indicates that it expects the CPU clock to be running at 4.8 Mhz. A fresh from the factory ATtiny13 is set up to run at 1.2 Mhz. This implies that the folks at Convoy configure the processor fuses.

The ATtiny13 has two fuse bytes. The unprogrammed state for all the bits in these is "1". Some of the bits get programmed at the factory. These are documented in section 17.2 (page 104) of the datasheet. There are 3 bits of interest as far as the CPU clock:

CKDIV8 comes programmed to 0, indicating that the base clock gets divided by 8. There is also a clock prescaler register (CLKPS, not a fuse) that provides 4 bits that can be used to reduce the clock (see page 26-28). The CKDIV8 fuse controls the initial state of the prescaler bits. When the CKDIV8 fuse is "1" (unprogrammed), these bits are 0001 and yield a division by 1. When the CKDIV8 fuse is "0" (programmed), these bits are 0011 and yield a division by 8. Software can change this to values from 1 to 256 after startup.

The CKSEL bits come from the factory set to "10" which causes the RC oscillator to run at 9.6 Mhz. A setting of "01" will give 4.8 Mhz.

Just for the record, setting CKSEL to "00" selects and external clock. Setting CKSEL to "11" slects an internal 128 kHz oscillator.

So, we can get 4.8 or 9.6 undivided; 0.6 or 1.2 if we divide by 8. Apparently Convoy configures the fuses to get 4.8 undivided.

Documentation in the Biscotti source

He gives the fuse settings in a comment at the start.
The fuse bytes are set to 0xff and 0x75

So CKDIV8 is 1 (no divide by 8) and CKSEL is 01 (4.8 Mhz RC clock), just as we surmised. The SUT bits are set to 01, which gives a somewhat faster startup also.

Making it so

There was already an entry in my makefile. I type "make fuse" and get:
avrdude -p attiny13 -c usbasp -B10 -U hfuse:w:0xFF:m -U lfuse:w:0x75:m
Set SCK frequency to 93750 Hz

Processing -U hfuse:w:0xFF:m
Reading 1 byte for hfuse from input file 0xFF
Writing 1 byte (0xFF) to hfuse, 1 byte written, 1 verified

Processing -U lfuse:w:0x75:m
Reading 1 byte for lfuse from input file 0x75
Writing 1 byte (0x75) to lfuse, 1 byte written, 1 verified
Avrdude done.  Thank you.
And you are welcome!

Reading fuses

Yes you can do this with the following inscrutable syntax:
make rfuse
avrdude -p attiny13 -c usbasp -B10 -U hfuse:r:-:i -U lfuse:r:-:i
Set SCK frequency to 93750 Hz

Processing -U hfuse:r:-:i
Reading hfuse memory ...
Writing 1 byte to output file 
:01000000FF00
:00000001FF

Processing -U lfuse:r:-:i
Reading lfuse memory ...
Writing 1 byte to output file 
:010000006A95
:00000001FF

Avrdude done.  Thank you.
In the above case, the hfuse is 0xff and the lfuse is 0x6A.

High voltage fuse games

You can be stupid and/or careless and burn fuse settings that "brick" your ATtiny. In those cases, you may have to resort to using voltages other than 5 volts to fix fuse settings. I have not dug into the details, but here is a link:
Feedback? Questions? Drop me a line!

Tom's Light Info / [email protected]