tiny45 Programming through an Arduino (or any other AVR)


i'm crossposting (well, pasting) new blog, but....i wanted see if this, , previous installments, help:

https://burntcouch.blogspot.com/2016/08/tiny45-programming-with-arduino-ide.html
https://burntcouch.blogspot.com/2016/08/tiny45-programming-with-arduino-ide-ver.html
https://burntcouch.blogspot.com/2016/08/tiny45-programming-part-3.html

part 3 ultimate conclusion...the post long fit here, soo....
-----------------------------------

..and last lap?  use arduino generic avr programming device: leverage low-end tools come linux , arduino ide stuff gods of high-level programming never intended.

---------------

and there other benefits of programming on bare metal way, if one's willing little homework.  cheaper:  bare mega328 costs $5 or less, compared $10 cheapest possible arduino; , tiny45 can bought in volume @ $0.99 device!  , knowing little bit more how avrs work, , how programming tools job, can't hurt.

one of problems arduino ide bloat code bit; isn't problem on arduinos, have relatively large amount of flash , static ram compared size of bootloader , more routine sample programs.  on older , smaller devices, though, program , static ram space major issue.

<code not included, see https://burntcouch.blogspot.com/ >

this simple program can write on avr, no matter how it....and ide still end using 808 bytes of program space , 9 bytes of ram.  suspect delay() function takes bulk of that.
-----------
a few days earlier, i'd spent half day installing , cramming winavr package on old dell inspiron 7000 (windows 2000, 128 mb of ram, 4gb hd!), because 1 of few pc's junk pile furnished useful parallel port.  until discovered arduino had been using avr assembler, atmel's avr studio on pc, , old homebuilt sp12 programmer ancient avr devices.  have several at90s2313's , 8515's, mega16, mega8515, , number of tiny26's (ancestor of 261/461/861), of wanted continue use.

i didn't have trouble working winavr, , in process managed muddle through rather complicated 'demo.c' program on avr-libc support site.....which example (more or less), implement 'fader' program in previous post on subject.  modified demo, working on various macros embedded in 'iocompat.h' file, , got work pwm stuff on tiny26.  good....

but...i didn't want lug out old clunk programmer , yet computer when wanted use old uc's, dammit!  , wanted use linux well...so next?

while using winavr stuff, used command line, illustrated in avr-libc tutorials 'demo.c' above, hand, so:

insp7000 c:\code\> avr-gcc -g -os -mmcu=attiny26 demo.c -o demo.o
insp7000 c:\code\> avr-objcopy -j .text -j .data -o ihex demo.o demo.hex


this built me 300+ byte file in 'demo.hex', , sp12 dongle uploaded so:

insp7000 c:\code\> avrdude -p t26 -c sp12 -u flash:w:demo.hex

(notice avr-gcc , avr-libc know attiny26 'atttiny26', while avrdude believes called 't26'.  gotta keep our wits us, kids...)

which no more 70-80 bytes on tiny26....impressive!  , more point, worked.  , note simpler 'blink' program tiny45 above, letting arduino ide heavy lifting, 10 times size.

size matters; tiny26 has 2k of flash, while mega328p (the core of arduino uno) has 32k waste.  can better, not in way of pain.

--------------

so, last example should give proper hackerly ideas, right?  avr-gcc , avrdude there arduino ide installed; , unlike ide, avrdude has full pin descriptions , functions defined every avr clear microcontroller stone age.  in theory, @ least, if have arduinoisp software loaded on uno, should able make arduino program avr device, long avr-libc , avrdude know device exists.

first, let's in 'programmers.txt'  in arduino ide install folder (<folder>/hardware/arduino/avr/) , see kind of directives sent avrdude 'arduino isp' programmer defined there:

<not included, see https://burntcouch.blogspot.com/ >

and see.  unlike when hitting arduino directly through ide, must talk directly serial.port (not pseudodevice 'usb'), define baud rate talk through arduino (as if serial port rather destination code want write).

so that's 1 piece of pie.  other piece is....which programmer use on avrdude command line if aren't going out on parallel port sp12 dongle?  entering 'avrdude -c ?' gives list of programmers knows about:

<not included, see https://burntcouch.blogspot.com/ >

the 1 looks close is, 'arduino', let's use command line options found above in combination we've got here, , try talking gadget , see:

<not included, see https://burntcouch.blogspot.com/ >

so wow, works!  is, indeed, correct sig attiny45.  arduino uno passes our request right through using arduinoisp software (with jumpered on capacitor across reset line) our 'legacy' device.

so now, how new version of blink program?  let's see here:

<code not included, see https://burntcouch.blogspot.com >

compile avr-gcc , use avr-objcopy create hex file, avrdude can write it.  100 bytes used total!

so how did concoct above?  among other things, looked (and at) main header files ide loads when create new program...i.e. @ arduino.h file, stored @ <ide install folder>/hardware/arduino/avr/cores/.  lots of handy macros in there, , nice list of other files included in ide builds default.  since trying program on bare metal, making few assumptions possible device, can muck , pare @ list bit, drill down through few #includes find , need, guess don't need.  can go with:

#include <inttypes.h>
#include <avr/io.h>

#define f_cpu 8000000ul   // 8mhz on t45 - needs defined before including util/delay.h

#include <util/delay.h>        //  _delay_us(double) , _delay_ms(double)


there 1 gotcha in first attempt @ this:  avr-gcc bitched incessantly f_cpu not knew about, #define cpu frequency there....i tried including util/delay.h without it, , immediate had wake call.  (right?  right?) delay functions wouldn't work right if based on clock speed of device, , didn't know number was.  arbitrary avr device can't assumed have rtc or pll clock built-in, other way have time base run off cpu clock, and....

in case...paring #includes down bare minimum shows can safely leave out, while still giving nice short cuts, , handy template building more complicated stuff later on.



Arduino Forum > Using Arduino > Microcontrollers > tiny45 Programming through an Arduino (or any other AVR)


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'