In AVR Programmers I: Arduino as ISPwe built an AVR programmer using an Arduino Uno. Pin10 of our Programmer toggles the reset of our target chip. A hex file from your PC is uploaded through the programmer to the target chip.
We programmed the Uno with the ArduinoISP sketchso that it became a USB to SPI serial data converter. Avrdude now sees the board as a -c avrisp or -c stk500v1 device on the same USB serial port.
A green LED named heartbeat pulses to remind us that it is working as a programmer. A red error LED needs you to press reset button on the board.
6pin and 10pin headers are quite standard for AVR programmers and development boards. Careful matching pins, do not force connectors, they are keyed to control orientation. Look for number, dot and triangle symbols for pin1.
We can build an AVR programmer using an ATmega8 chip in place of the Arduino. ATmega328p, ATmega8 and ATmega88 chips have the same pinouts but different RAM and flash.
We say that the chips have the same footprint. Wikipedia uses this graphic for a 28pin dual in-line package (DIP).
Sketches and C/C++ programs for the Uno can run in an ATmega8 if they use less than 8kByte of flash and 1kByte of RAM. The Update Firmware section will show how we can upload to the chip in our USBasp dongle.
USBASP ConceptA gentleman named Thomas Fischl designed an AVR programmer called the USBasp. His design is available for you to build your own. He sells branded versions and there are many inexpensive copies.
Look closely. You can get more design drawings at his website. CON2 is the 10pin ICSP header. Short JP2 and you add a connection to the reset pin and put the USBasp into a flashing mode. The USB port has +5V, gnd, D+ and D- leads connected to IO pins on the ATmega8 chip.
A USB signal interupts the processor and starts a programming cycle. Pin PB2 of the ATmega8 toggles to reset the target chip. Then commands to write a hex file from the computer to the target chip come in on the USB and are translated into SPI serial peripheral interface to write into the flash memory of the target.
Inexpensive dongles come already with working firmware to be -c usbasp programming circuit. No serial comm port is assigned. Windows PCs will need driver software to use these programmer devices. Further down we look at how we can update firmware in the device.
LinuxPlug the USBasp programmer into a Linux computer. dmesg and lsusb commands should show the device recognized.
To upload a hex file on a comms port your user account in Linux needs to have the privileges of the dialout group. If you see messages saying you are blocked from sending a file on your comms port then try the CLI command.
$ sudo usermod -a -G dialout $USER
Windows DriverPlug the USBasp programmer into a PC. Windows will need a driver so that it recognizes the USBasp and knows how to use it. There will not be a serial port assigned.
The USBasp site now recommends using Zadigfor installing drivers in your computer.
Follow instructions menu Options->List AllDevices select USBasp. It will take a minute to install driver libusb-win32(version). More details in project FabISP AVR ISP ATtiny44.
You may have to refresh your driver if you switch between USBtiny and USBasp programmer devices.
Terminal command to download firmware from an Arduino target.
avrdude -p m328p -c usbasp -U flash:r:target.hex:i
Avrdude is the firmware upload program used by Arduino IDE to write a hex file into the flash of your device. It can be run for Linux CLI or Windows command prompt. You don't need a -P com port for a USBasp programmer.
Make sure you have all the parameters typed correctly. Check the -p part, -c circuit, hex file name, etc.
Arduino IDEMenu Tools->Programmer->USBasp then Sketch->Upload Using Programmer.
Menu Tools->External Tools... and add a new entry. Avrdude.exe must be on the computer. The arguments field tells avrdude to use a -c usbasp to write a hex file named after the project.
Arguments: -p atmega328p -c usbasp -U flash:w:$(BinDir)\$(TargetName).hex:i
Buy a USBasp dongle and it will arrive already with an ISP program like the sketch in an Arduino ISP. Build your own programmer and you will need a sketch or C/C++ program to run in it.
The sketch is software but we call it firmware because it is part of the product and we rarely expect to change it. Mr. Fischl publishes firmwares from 2011. You can explore Matrixstorm who offer alternatives.
You may receive messages telling you to update your firmware to fix an issue. We can use a second programmer to upload a new sketch to the first programmer. Let's look at this graphic from Wavgat.
Close the connection for JP1 labeled Upgrade standby. Wires with Dupont connectors or a box jumper can short this connection. Look at the schematic above and you see it connects the reset pin of the MCU to the ICSP box header.
Connect like this: one programmer on the USB of the pc downloads firmware load from target dongle.
Open a Command Prompt or CLI terminal. Type this command to read the firmware in the flash of the target.
avrdude -p m8 -c usbasp -U flash:r:dongleFW.hex:i
Watch the progress bars.
Now, you have a safe backup of the program that is running in the USBasp dongle. Change :r: to :w: and you can write this same firmware back into the device. Or upload new firmware from some website.
It's not workingModify the avrdude command and make it work at a baud rate speed -b 19200 or -b 9600. Change from USB3.0 ports to USB2.0 ports on your computer. Try different USB data cables. Make sure you are using the correct -p part and -c circuit parameters.
avrdude -p t13 -c usbasp -b 9600 -U flash:r:target.hex:i
Maybe not. If you are programming an Atmel AVR processor with a USBasp device then you may not want to add the bootloader program. It consumes flash and is only needed to work with Arduino IDE.
Comments