Saturday, March 1, 2014

Programming Attiny85 from Arduino IDE

Now that I can bootload code onto my ATTiny85's, its almost time to get down to some programming!     I do want to get into AVR C **ALOT** more, but also in the interest of maybe getting some participants in the project, I've opted to stick with the Arduino IDE for now.    This poses several issues, namely how to upload the sketch via the recently installed TinySafeBoot!?

I'd already modifed my attiny cores (arduino/hardware/tiny/boards.txt) to create a custom config for setting the fuses before i burned the bootloader (with atmel studio at the time).    It seemed to me, that I could modify the uploader, since the Arduino enviroment doesn't have "external tools" like Atmel Studio.   Unfortunately, this was not the case with Arduino 1.0.5, so I wound up updating to 1.5.6 beta.   I found some information about jeeLabs doing similar stuff w/ Tiny84 (https://github.com/jscrane/attiny) which got me pretty close.  I also did some heavy reading into the Arduino 1.5 platforms spec (https://code.google.com/p/arduino/wiki/Platforms1).   With this, I was able to generate the following bits to allow me to upload to TinySafeBoot from the Arduino IDE: 

BOARDS.TXT
attiny85at8TSB.name=ATtiny85 @ 8 MHz (internal oscillator; TSB Bootloader)
attiny85at8TSB.build.mcu=attiny85
attiny85at8TSB.build.f_cpu=8000000L
attiny85at8TSB.build.core=tiny
attiny85at8TSB.build.variant=standard
attiny85at8TSB.upload.tool=tsb
attiny85at8TSB.program.tool=avrdude
attiny85at8TSB.program.using=arduino:arduinoisp
attiny85at8TSB.program.maximum_size=8192
attiny85at8TSB.program.speed=19200
attiny85at8TSB.erase.tool=avrdude
attiny85at8TSB.erase.using=arduino:arduinoisp
attiny85at8TSB.erase.maximum_size=8192
attiny85at8TSB.erase.speed=19200
attiny85at8TSB.bootloader.tool=avrdude
attiny85at8TSB.bootloader.using=arduino:arduinoisp
attiny85at8TSB.bootloader.speed=19200
attiny85at8TSB.bootloader.low_fuses=0xC2
attiny85at8TSB.bootloader.high_fuses=0xD5
attiny85at8TSB.bootloader.extended_fuses=0xFE
attiny85at8TSB.bootloader.file=tiny85.hex

PLATFORMS.TXT
tools.tsb.cmd=tsb.exe
tools.tsb.path=c:\users\bblaze\desktop\tsb\
tools.tsb.upload.params.verbose=
tools.tsb.upload.params.quiet=
tools.tsb.upload.pattern="{path}\{cmd}" "{serial.port}" "FW" "{build.path}/{build.project_name}.hex" 

I will establish a programming bus to allow me to program multiple slaves soon.   I'm slightly concerned with the bootloader default ports (B0 / B1) because B0 overlaps the I2C pin that I'll be using to communicate with the master atmega328p.     For now, I'm just disconnecting that one line when I need to bootload.

My friend turned me on to the Arduino MasterReader / SlaveWriter sketch (http://arduino.cc/en/Tutorial/MasterReader#.UxJqzvldU5N)  which uses the wire lib across 2 atmega328p.   This is a good conceptual idea of what'll be going on.  Additionally, this instructable gives some good insight into i2c communication between microcontrollers (http://www.instructables.com/id/I2C_Bus_for_ATtiny_and_ATmega/)

  I've got programming capabilities on both master / slave. I've confirmed connectivity.  I've got the basic communication protocol hashed out in my head.   All the pieces are falling into place!

In the next post, I hope to have hashed out the basic schematic and have some workable sample code across a few slaves.


No comments: