AVR programmer with avrdude in linux

Hello, I’ve recently purchased one of these and am having trouble programming it/with it. I’m using avrdude and as a test, this command: avrdude -c avrispv2 -p atmega168 -P /dev/ttyACM0, Which results in this:

avrdude: stk500v2_command(): command failed
avrdude: stk500v2_command(): unknown status 0xc9
avrdude: stk500v2_program_enable(): cannot get connection status
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.

avrdude done. Thank you.

running as root has the same result. I’m new to avr programming and this has been kicking my butt, so please help me.
In the case that it helps, I’m running arch linux x86_64 with the latest kernel

thank you.

Hello, mikhail.

I’m sorry you are having trouble.

What kind of AVR are you trying to program? How is it connected to the programmer? How is it powered?

–David

I’m trying to reprogram an iClicker. It has an Atmega8 processor, is connected with the cable that comes with the programmer and is powered by 3 AAA batteries.

Shouldn’t the command I used work even if the programmer is not connected to any other avr?

Hello mikhail.

What makes you think it should be possible to reprogram the iClicker? Is there a tutorial or manual you are following? The manufacturer may have disabled SPI programming in the fuse bits of the AVR; if that is the case you will need to replace the AVR or get a different kind of programmer. Also, the 6-pin header you found may or may not have the standard pins in it.

Please measure the voltage on the AVR’s VDD line and also on the programmer’s VDD line and let us know what you measured. If your connections are correct, the voltages should be same. I suspect that with only three AAA batteries the VDD might be low enough that the programmer would refuse to program the AVR. By default, the minimum VDD allowed is 4.38 V. You can change that setting of the programmer if you compile and run PgmCmd from the Pololu USB SDK.

Now that I look at it more carefully, I am not sure what avrdude should do in response to your command, but we can see that it ran its stk500v2_program_enable function, which attempted to put the AVR in to programming mode. Your command specified the wrong AVR. Try this command instead:

avrdude -p m8 -P /dev/ttyACM0 -c avrispv2 -B 3 -U flash:r:clicker.hex 

The -U option tells avrdude to read the flash to a new file named clicker.hex. The -B option tells it to program at 200 kHz, which should work for any AVR whose clock frequency is 800 kHz is more. Do you know what frequency the ATmega8 is running at?

–David

It’s based on a proof-of-concept hack investigated in this research paper (I used their instructions for soldering header pins, etc.)

I’m not at home atm, but I’m pretty sure the voltages are the same.

Like I said, I’m new to this, what exactly is it that the programmer does? My understanding is that it is an interface for communicating with another avr; is this wrong? For anything to work, does it have to be connected to the other avr?

You said you are pretty sure that those voltages are the same. Do you also know what voltage they actually are? As I explained above, that is important.

You said “another AVR”. That phrase only applies if there are two AVRs in the picture, but as far I know you only have one AVR. (Our newer Pololu USB AVR Programmer does not contain an AVR.)

To program an AVR, you need to produce certain electrical signals on some of its pins. By producing the right signals, you can activate the AVR’s in-system programming (ISP) interface which is also sometimes called in-circuit serial programming (ICSP) and is called “Serial Downloading” in the ATmega8 datasheet. This interface allows you to read/write the flash, eeprom and fuse bits of the AVR. Since PCs do not have the right connector or software to produce those particular electrical signals, you need an external programmer like the Pololu USB AVR Programmer. It should be noted that ISP is just one of several interfaces that AVRs have for programming, and this particular interface can be disabled.

Many of the features of our programmer work without an AVR connected, for example the USB connection, the configuration utility, the TTL serial port, and the SLO-scope. There is also a serial command that you can issue on the Programming Port that will return the name of the programmer but I don’t know if avrdude will allow you to just run that command without doing anything else.

–David

Here’s output of sudo mono PgmCmd -s:

Serial number:                  00020268
Firmware version:               1.01
Settings:
  ISP Frequency:                200 kHz
  Line A Identity:              None
  Line B Identity:              None
  AVR ISP hardware version:     F
  AVR ISP software version:     2.A
  Target VDD allowed minimum:   4384 mV
  Target VDD allowed max range: 512 mV
Last programming:
  Error: None
  Measured Target VDD Minimum:  N/A
  Measured Target VDD Range:    N/A
SLO-scope:
  State:                        Off
  Line A output:                Off
  Line B output:                Off

but then, after I run avrdude -p m8 -P /dev/ttyACM0 -c avrispv2 -B 3 -U flash:r:clicker.hex
the output becomes

Serial number:                  00020268
Firmware version:               1.01
Settings:
  ISP Frequency:                200 kHz
  Line A Identity:              None
  Line B Identity:              None
  AVR ISP hardware version:     F
  AVR ISP software version:     2.A
  Target VDD allowed minimum:   4384 mV
  Target VDD allowed max range: 512 mV
Last programming:
  Error: Target VDD bad
    Target VDD either went too low or had too much range, so programming was
    aborted.  Make sure that the target is powered on and its batteries are not
    too low (if applicable).
  Measured Target VDD Minimum:  0 mV !
  Measured Target VDD Range:    1472 mV !
SLO-scope:
  State:                        Off
  Line A output:                Off
  Line B output:                Off

What do I need to change to make it work?

Hello, mikhail. Thanks for giving me that information.

The programmer is reporting that the target VDD was between 0 and 1472 mV during programming. That is too low for your AVR to safely be programmed (the operating range of the ATmega8 is 4.5-5.5 V). You probably need to change the way you are powering the AVR.

It’s possible that there may be a problem with your programmer, so please measure the voltage on the AVR’s VDD line and also on the programmer’s VDD line with a multimeter and let us know what you measured. If your connections are correct, the voltages should be the same.

–David

I don’t own a multimeter. However, I swapped the 3 AAA batteries out for a 9v one and now i get this output for sudo mono PgmCmd -s:

Serial number:                  00020268
Firmware version:               1.01
Settings:
  ISP Frequency:                200 kHz
  Line A Identity:              None
  Line B Identity:              None
  AVR ISP hardware version:     F
  AVR ISP software version:     2.A
  Target VDD allowed minimum:   4384 mV
  Target VDD allowed max range: 512 mV
Last programming:
  Error: None
  Measured Target VDD Minimum:  4544 mV
  Measured Target VDD Range:    256 mV
SLO-scope:
  State:                        Off
  Line A output:                Off
  Line B output:                Off

and this for sudo avrdude -p m8 -P /dev/ttyACM0 -c avrispv2 -B 3 -U flash:r:clicker.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9307
avrdude: reading flash memory:

Reading | ################################################## | 100% 1.65s

avrdude: writing output file "clicker.hex"
avrdude: error opening clicker.hex: No such file or directory
avrdude: output file clicker.hex auto detected as invalid format
avrdude: invalid output file format: -1
avrdude: write to file 'clicker.hex' failed

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

it looks as if some thing good is going on (?) but its not saving it! it just makes an empty file called clicker.hex

It looks like you have fixed your AVR powering issues. However, I am a little concerned that you may have broken some other part of the board by putting the 9 V battery in to a product that was designed for 3 AAA batteries, which would have a nominal voltage of 3.75 V (or more depending on the type of battery).

It looks like you successfully read the flash of the AVR on to your computer but there was a problem with avrdude that prevented it from saving the file. Try this slightly modified version of the command:

sudo avrdude -p m8 -P /dev/ttyACM0 -c avrispv2 -B 3 -U flash:r:clicker.hex:i

The only difference is the “:i” format specifier at the end, which tells avrdude to write the file in the Intel HEX format and is known to fix the error message you are getting.

–David