Meet the new, improved, autonomous, self-guiding, hassle-free, portable ISP programmer!
It works as follows:
- hook up a JeeNode or JeeNode USB to your computer
- upload the isp_capture.pde sketch to it
- insert the Flash Board and hook it up to the target
- program the target, using this as a standard STK500/AVRISP programmer @ 19200 baud
- wait for the LED to blink twice
And this is where the fun starts:
- connect the JeeNode to a battery or any other power source
- insert the above Flash Board again and hook it up to the target
- press the button on the Flash Board
- wait for the LED to first turn off and then start flashing
You’ve just programmed another target MPU … look ma, no hands!
The first hookup went through a normal programming cycle, but it also stored everything in the EEPROM on the Flash Board: code, data, fuses, verification bytes, everything. That’s why I’m calling this a capturing programmer.
When pressing the button, it essentially repeats all the same steps.
This works for anything you can program with an AVRISP programmer: ATmega, ATtiny, whatever. And it will even capture multiple programming cycles, as long as they are started before the LED blinks twice, i.e. within a few seconds. So you could set up a script to call avrdude with a few different things to do – e.g. set fuses, program the flash, program the AVR EEPROM, set the lock bits.
There are some tricks under the hood to make this work. First of all, the baudrate as ISP programmer is set to 19200, so that the bootloader in the JeeNode doesn’t accidentally take over after reset (it listens at 57600 baud).
Another trick, and the main reason this all works transparently, is that the entire serial communication session is stored in EEPROM as is. When pressing the button, it simply replays the input to the programmer code as if it was coming from the serial port (and matches the results, also against EEPROM). There is some logic involved to be able to store both input and output streams, and keep them properly apart.
The EEPROM is connected via I2C to port 3. I used the MemoryPlug and MemoryStream classes from the Ports library to access it.
Lastly, there is some debugging built in. While used as AVRISP programmer, the serial port is in use for programming @ 19200 baud. But when in replay mode, the serial port is set to 57600 baud and used to report what the programmer is doing. Here is a transcript:
[isp_capture] ISP bytes: 39680 Code size: -32768 Page size: 128 Data size: 1024 Signature: 86 00 00 01 01 01 01 03 FF 95 0F Programming... Done in 13.9 seconds.
That’s it. There is visual feedback when programming succeeds in the form of a flashing LED, so that this setup can be used without serial link. I’d like to add auto power-down one day, for serious battery use.
I’m going to use a bunch of Flash Boards here, pre-loaded with the different contents of ATmega’s and ATtiny’s I’m constantly preparing here at Jee Labs. Will probably also dedicate a bunch of JeeNodes to this, but that’s optional – any available JeeNode can be temporarily turned into an ISP programmer by simply uploading the “isp_capture.pde” sketch to it and inserting a Flash Board.
Now I can easily reprogram all those Room nodes in the house!!
PS. There’s nothing JeeNode-specific about this setup. The on-board wireless isn’t used (yet?).
PPS. For your convenience, I’ve tagged all related posts on this weblog with ISP.