Pages

Friday, February 28, 2014

ATMega / ATtiny experiments - Pt2 - Bootloaders

So, last night i was able to get the aforementioned AVR112 application note code (TWI Bootloader) loaded onto my ATTiny slave.  However, for the life of me, I can't get the code onto the master (albeit a different processor then the example).   I finally gave up on that after spending all night and morning on it.

After work, I started playing with a different one "TinySafeBootloader".    This one seems pretty cool, it's able to reprogram itself, basically updating the bootloader itself!   It can also program mulitple slaves on a single programming bus, by using different passwords for each.   Again, I was able to get it going on my slave (I THINK!).  This time, I compiled the assembler file for my particular target and was able to hack up my attiny arduino files to slightly modify the programming fuses and upload the bootloader.    The difference b/w this one and the AVR note is this one works on any two-wire serial bus.   I programmed the bootloader and attempted to send it a sample program via my FTDI breakout...  Nothing..  It doesn't seem to want to connect.   I changed a few things in my arduino boards file and reloaded several times, same thing..      I really like the things it offers, but I've also seen a few people say they couldn't get it to work.  While the documentation is great as far as WHAT / HOW it does what it does, its certainly lacking the implementation details!  

I'm going to hack on it a little bit longer and hopefully see some progress, otherwise - NEEEXXXTT!     More to follow, stay tuned.

Thursday, February 27, 2014

ATmega Master / Multiple ATtiny Slave experiments - pt 1

So, I've got this idea for a totally modular synth / controller / whatever environment.   A master ATMega runs an event driven framework and manages any time sensitive operations.   It delegates tasks to a series of "modules" much like Digitial IO, Analog IO, MIDI, Matrix LED, etc. Rather then connecting the master straight to a shift register chain, or some other peripherals,  the functionality would be controlled by the ATtiny slave.  

Why would I want to do this?  Well, I've got several musical related projects (Midi sequencer, wavetable oscillator, midi controllers) and I'd like to reign in the codebase a little.  Each project has many similarities that could easily be abstracted.  I feel the advantages are huge for a few reasons:  

1) UI and other long running tasks don't tie up the more crucial time sensitive bits
2) Modules could become their own standalone gizmos
3) Modules could be interconnected in almost limitless ways

Proposed Core functionality:
  • Event Driven framework or RTOS
  • MIDI IO with thru / clock sync / clock gen
  • Bootload slaves via I2c
  • Allow configuration of slave address / role 

Modules will have an address and a corresponding role.   A simple messaging setup should allow a few bits
to delegate any task and value from the core to the slave.  

Proposed modules for V1:

  • Analog In  (rotary pots, audio, cv, etc) 
  • Analog Out  (i2c dac, audio / cv) 
  • Digital In (button / encoders)
  • Digital out (led, trigger, etc)
  • RGB LED Matrix 
  • I2c text and graphical lcds
  • Keypad decoding

Phase 1 - Communicating amongst devices
Initially, I'd planned to use a straight up serial bus from master to slaves and use i2c peripherals on the slaves. I POC'd this a little and talked to some friends and it seems the consensus is to use i2c from master-> slave, then SPI or bitbang i2c out from the attiny slaves.    Seems legit..

Phase 2 - The switch from Arduino to AVR.    
All of my existing work is Arduino.   Its nice to an extent, but as i started to delve deeper, I realized I'm going to need the ability to bootload slaves from the master.  While I could recreate the wheel,  I found that Atmel application note AVR112 pretty much nails the requirement here.  A PC runs an application which executes the update from a host microcontroller to a target over "TWI" (atmels name for i2c) or USI.  

I installed Atmel Studio and was able to send a blink program to my attiny by leveraging the arduinoAsISP application I already had loaded on my Arduino Uno.   I setup an "external tool" in Atmel Studio which would execute:

Command: C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude.exe
Parameters: -b19200  -C"C:\Program Files (x86)\Arduino\hardware/tools/avr/etc/avrdude.conf" -v -v -v -v -pattiny85 -cstk500v1 -P\\.\COM6  -Uflash:w:"$(TargetDir)$(TargetName).hex":i

Now I can simply F7 to build a debug version of my program, and then run the external tool to send it to the AVR..  COOL..  

Well, cool until I got back to the bootloader end of things.    Having a bootloader in this environment seems like a no-brainer! Shuffling ISP wires, or moving chips back and forth to programming devices doesn't sound very fun!   I WANT CODE!  I managed to get the bootloader slave code into atmel studio from the provided .zip from atmel.  I tried to compile it - ERROR!   Apparently, Atmel doesn't use AVR-GCC as a compiler for their example code because its not really a "commercially viable" compiler or something..    I had to download / install the IAR Embedded Workbench to compile them to .hex, which i will then in turn use AVRDude to upload to my target device.  

Hopefully, I'll at least get the bootloader up and functional tonight and my next post, I'll look at getting the master to progam the slave and load another program (blink and led , followed by some introductory communication)






references:

 midibox (http://www.ucapps.de)