Sunday, May 13, 2012

Programming the Optiboot into the ATmega328

I have been using the PicKit2 and a ZIF socket to program the 18F series of MCU. This setup is inexpensive and handy. I would like to have a similar setup for use with the Atmel mcu's.

USBasp: The least expensive ATmega in circuit programmer, ISP,  I have come across is the USBasp which is sold on many sites and all seem to be by different unknown manufacturers. The USBasp sold by HobbyKing for $4.50 had good reviews and a cable with both 10 pin and 6 pin connectors. The Arduino boards, as well as my designs, use a 6 pin ISP connector. I also located 28 pin, 0.3" ZIF sockets made by Textool,  # 228-3341, which I cannot find in the Textool datasheets since it has been discontinued.  I ordered and have received 2 sockets and they indeed have that number. Here are some sources for the USBasp:
  1. HobbyKing of HK: USBasp programming device for Atmel processors
  2. XHeli: KK control board USBasp
  3. Fun4diy: USBasp kit
  4. ProtoStack: USBasp AVR Programmer
Except for the HobbyKing unit all the USBasp above have 10 pin cables so that a 10 pin to 6 pin adapter will be needed. If you are good at making IDC cables you can make a cable similar to HobbyKing's.

EMS ISP Shield:  Evil Magic Science makes a Arduino shield kit that contains a ZIF socket and can be used with the Arduino ISP sketch to program bootloaders into ATmega MCU's. Adafruit sells a similar kit. The bare pcb from the EMS kit, which is sold separately, could be used as a standalone ZIF board with the USBasp to do the same thing.

OptiLoader: This sketch, which can be found here, turns a Arduino board into a stand alone optiboot programmer. The sketch contains images of OptiBoot hex files for several ATmega devices. When the reset switch is pressed, OptiLoader looks at the attached ATmega device to determine what it is and then programs it with the correct OptiBoot. While doing this, sequence data is sent out the serial port which can be monitored with the Arduino IDE serial communication tool.

For a setup using solderless breadboards look here. My setup will use a modified Evil Mad Science ISP shield, purchased as a bare pcb, and an Arduino Duemilanove

AdaLoader: This sketch, which can be found here, is based on the OptiLoader, but uses LED's and a beeper as progress feed back. The AdaLoader sketch has only one bootloader image and the LadyAda site describes how to change the image. The AdaLoader uses LED's for PROG and ERROR connected to pins A0 and D8, respectively, and a beeper to indicate program completion at pin A3. To program the bootloader press reset after loading the ATmega into the ZIF socket assuming your using the ISP shield.

ArduinoISP: This sketch which is part of the Arduino IDE download and can be found in the Examples folder turns an Arduino board into and AVRISP programmer. The ArduinoISP uses LED's for PROG, ERROR and HEARTBEAT connected to pins D7, D8 and D9, respectively.

ArduinoISP2: This sketch which is available at LaydAda is based on the ArduinoISP sketch, but has been modified to work with Arduino IDE 1.0. The ArduinoISP2 uses LED's for PROG and ERROR using A0 and D8. A beeper connected to A3 signals program complete. To program the ATmega328P device, first, dowmload the ArduinoISP2 sketch to the Arduino, then using the IDE do Tools > Burn Bootloader > w/Arduino as ISP. The green LED will light indicating the bootloader is being loaded. When loading is complete the green light will go out and the IDE will show "Done burning bootloader".

EMS ISP Shield Modifications:
Changes
  1. Cut land from reset switch and connect switch to Arduino Reset pin.
  2. Cut land from anode of Hello LED and connect to A0 pin.
  3. Add beeper and connect to pin A3.


New ISP Loader Shield
Project Objective: To design a shield which can be used with all of the above sketches.


Specification List:
  1. 28 pin ZIF socket
  2. Reset switch paralleling Arduino board reset switch
  3. Power switch for socket
  4. Both 6 and 10 pin ISP connectors with target power jumper
  5. LED's for PROG, ERROR and HEARTBEAT
  6. Beeper
  7. Serial LCD connector
The PCB for the new ISP shield has been received and assembled. The shield was plugged into a Duemilanove, the Arduino IDE 1.0 loaded, the Arduino ISP compiled and downloaded. Using the Tool menu, Burn Bootloader was selected and got a AVRdude sync error. I shifted to IDE 0023 with same results. From reading the web, this is a Auto reset problem. At this point I substituted my home grown Arduino clone, GMduino, described elsewhere in this blog. The only real difference between my clone and the commercial boards is the use of a .1uf capacitor for the auto reset circuit and a switch to disable auto reset.. The commercial boards use a resistor. Using the IDE 0023 I programmed ATmega328P device right off. Not only that, disabling auto reset was not necessary. Is it the capacitor? More testing.


ISPL Shield Rev A
Schmatic:

ISP Loader Shield Rev B

Problems with AutoReset: Normally, before a sketch is downloaded to the Arduino the serial port DTR signal  triggers which cause a reset and the bootloader to execute. AVRdude when it connects to the Arduino board also triggers DTR on the serial port causing an Auto Reset.


Still working on this. 6/6/12



No comments:

Post a Comment