- Notifications
You must be signed in to change notification settings - Fork2
Digispark ATtiny85 setup with command line interface. Simple LED blinking example to test frequency and timing.
License
aabbtree77/digispark-attiny85-command-line
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
MCS Digistump Digispark Attiny 85 is the cheapest complete MCU board whose (five-euro) price is close to that of the MCU chip (Attiny 85) alone.
The problem is that its programming (flashing)is not as trivial as it should be. Most tutorials involve theArduino IDE,but those IDE-centered workflows depend on the IDE version number and are not flexible and portable enough. Here are some notes about programming this board directly from the Ubuntu 22.04 command line terminal.
sudo apt-get install gcc build-essential gcc-avr binutils-avr avr-libc gdb-avr avrdude libusb-devgit clone https://github.com/micronucleus/micronucleus.gitcd micronucleus/commandlinemake
Add this line to .bashrc (note your path to micronucleus, mine is /home/tokyo/):
export PATH=$PATH:/home/tokyo/micronucleus/commandlineFlash Micronucleus bootloader t85_default.hex, and set the correct fuse values. See Updating Micronucleus for details.
This establishes the board as a "Digispark".
Use Micronucleus over USB to upload code:
make cleanmakemake install
or simply upload main.hex if you have obtained it by other means:
sudo -E env "PATH=$PATH" micronucleus --run main.hexThe fuses remain as they were (you don’t touch them again).
In the included Makefile,make install runs sudo with the environment PATH borrowed from the user spaceso that the micronucleus program becomes visible.
The promt issues
>Please plugin the device ...and one then needs to unplug and plug the board to USB port again before succeeding:
>Device is found!connecting: 33% complete>Device has firmware version 1.6>Available spacefor user applications: 6012 bytes>Suggested sleeptime between sending pages: 8ms>Whole page count: 94 page size: 64>Erasefunctionsleep duration: 752msparsing: 50% complete>Erasing the memory ...erasing: 66% complete>Starting to upload ...writing: 83% complete>Starting the user app ...running: 100% complete>> Micronucleus done. Thank you!
A sample code is included in this folder.
Executelsusb to check if the board is still visible on the USB port. If not, update/upload Micronucleus as shown below.
One problem with this board is that in order to update Micronucleus (bootloader), one still needs to wire an external ISP programmer such as USBasp to the corresponding pins MISO, MOSI, SCK and RESET. In order to update it:
cd micronucleus-master/firmware/releases
avrdude -P usb -c usbasp -p t85 -U flash:w:t85_default.hex
avrdude -P usb -c usbasp -p t85 -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xfe:m
This particular low fuse bit setting uses an internal 8 MHz oscillator with a division by 8 yielding F_CPU = 1000000u.
The above does not work.Micronucleus expects 16.5 MHz. Otherwise the USB signals are too slow and the USB device will not be detected.
Instead:
cd micronucleus-master/firmware/releasesavrdude -c usbasp -p t85 \ -U flash:w:t85_default.hex:i \ -U lfuse:w:0xe1:m \ -U hfuse:w:0xdd:m \ -U efuse:w:0xfe:m
Micronucleus is tied to specific fuses to run USB:
lfuse = 0xE1 → enable 16.5 MHz PLL clock, disable CKDIV8.
hfuse = 0xDD → keep reset pin enabled, set boot size properly.
efuse = 0xFE → default extended fuse.
Always set the main clock to 16.5 MHz.
Fuse bits (fuses) = stored in a dedicated NVM area in the chip. Persistent w.r.t. resets and power on/off until explicitly changed. They also determine the CPU clock.#define F_CPU 16500000UL inside code/firmware only tells the compiler what we think the clock speed is. Has no effect on hardware, but affects certain functions such as_delay_ms().
One should be extremely careful with the fuse bits. There are many ways to brick the device:
- Changing the lock bits. Only the omitted (shown above) or the default -U lock:w:0xFF:m is non-locking!
- High DWEN or RSTDISBL overrides RESET and will thus irreversibly break SPI and the ability to program!
- SPIEN should be 1, Enable Serial Program and Data Downloading, otherwise no SPI anymore!
- SELFPRGEN should be 1 if you want to use micronucleus.
By default, all the pins of the port B are set to the output pins, this even includes the reset pinPB5!
I wish I read aboutfuse settings earlier.
About
Digispark ATtiny85 setup with command line interface. Simple LED blinking example to test frequency and timing.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.

