2022-08-09 - slowly programming slow AVRs

recently i've promised to my sons i'll build them solar-powered toy satellite to be “launched” form 3D-printed Ariane 5 model rocket. i'll write more on that once it's finished.

genesis

since the thing is solar-powered, it's crucial to keep power usage as low as possible (step-up DC/DC losses + blinking LED are already eating up a lot), so i decided to go with ATtiny13's lowest possible frequency – internal RC oscillator, running at 128kHz, with internal prescaler set to 8… ending up at 16kHz! :D felt awesome… until i've flashed fuse-bits to enable the oscillator and chip stopped responding.

first i though i screwed up fuse bit values, and disabled serial programming (happened to me in the past). since this is SMD, i'd need to re-solder a new unit to make it working… instead i decided to drill down a bit and see what's up. AVR fuse calc confirmed i've set all the bits correctly (cross-checked with datasheet). then i came across a post on how to reset fuse bits via programmer. long story short – you can reset fuses like this:

avrdude -P usb -c usbasp -p attiny13 -U lfuse:w:0x6A:m -U hfuse:w:0xFF:m -B 1kHz

this is how i've learned there, that ISP programmer must run slower than AVR it is programming, to make it work! in theory 1/4th speed should suffice. in practice 1/8th is stable enough to work. so in case of 16kHz clock, i need 2kHz ISP. i'm using AVR since some double-digit years and i was never aware of that. 8-/

programming the programmer

anyway – i was almost there when i hit another issue – error from avrdude (well – actually a warning, that should be an error):

 avrdude: set SCK frequency to 2000 Hz
 avrdude: warning: cannot set sck period. please check for usbasp firmware update.

looks like my ISP programmer does not handle SCK option thus i cannot slow down ISP… quick search on the internet reveled that this is indeed an issue with firmware version (as avrdude suggested). i've ordered another one from the internet – one advertised that it already has a firmware with SCK support… which 2 days later also turned out to be false!

good news was that the firmware can be updated when you have 2 AVR programmers, that i now happend to posses. quick soldering of JP2, some cabling, then flashing:

wget https://www.fischl.de/usbasp/usbasp.2011-05-28.tar.gz
tar xzvf usbasp.2011-05-28.tar.gz 
avrdude -p atmega8 -P usb -c usbasp -U flash:w:bin/firmware/usbasp.atmega8.2011-05-28.hex:i

and the issue is solved! i can now flash my code, to 16kHz running CPU! :D

# avrdude -P avrdoper -c usbasp -B 2kHz -p "attiny13" -U "flash:w:led_sat.bin"

avrdude: set SCK frequency to 2000 Hz
avrdude: AVR device initialized and ready to accept instructions
...

final notes

after checking USBasp homepage, what was striking to me, is that 11 yrs old firmware is still not being flashed to the newest ISP programmers on the market! it's out there. it's free. what's the problem? i know these programmers are not that expensive (<6 EUR, inc. shipping), but still…

blog/2022/08/09/2022-08-09_-_slowly_programming_slow_avrs.txt · Last modified: 2022/08/21 19:06 by basz
Back to top
Valid CSS Driven by DokuWiki Recent changes RSS feed Valid XHTML 1.0