Arduino Programming Shield

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Arduino Programming Shield

Postby aivoryellis » Fri Dec 09, 2011 10:56 pm

Hi, recently I bought the Standalone AVR ISP Programmer Shield Kit. Unfortunately, I can't get it to work. I have a blank ATmega328P and when even I try and burn the bootloader, I get this error or something like it:
Code: Select all
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x01
avrdude: stk500_initialize(): (a) protocol error, expect=0x14, resp=0x10
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: stk500_disable(): unknown response=0x12


This is using the included ArduinoISP sketch. Then I try the Standalone Programmer Shield Kit sketch when I burn the bootloader (attempt):
Code: Select all
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x01
avrdude: stk500_initialize(): (a) protocol error, expect=0x14, resp=0x10
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: stk500_disable(): unknown response=0x12


The same thing. I have made sure that I have no unwanted nodes, I have followed the tutorial on Adafruit correctly and have no idea how to fix this. Please help.

EDIT: I am using the Arduino Uno R2 and Arduino 1.0.

Thanks,
Asa Ivory-Ellis
aivoryellis
 
Posts: 9
Joined: Fri Dec 09, 2011 10:47 pm

Re: Arduino Programming Shield

Postby Charxian » Sat Dec 10, 2011 2:26 pm

I just recieved the same kit and can't bootload either, but my error is:

Code: Select all
avrdude: stk500_program_enable(): protocol error, expect=0x14, resp=0x50
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51


I am using a duemilanove and tried on windows7 and xp.

Thanks for any help!
Charlene
Charxian
 
Posts: 4
Joined: Thu Dec 08, 2011 5:35 pm

Re: Arduino Programming Shield

Postby jwhance » Sun Dec 11, 2011 8:27 am

I had a similar problem with the programming shield. The "blank" 328P that came with the shield from Adafruit worked fine but I had some 328s (not "P" but that doesn't matter) from DigiKey that would not program. It was like they weren't there. I had 5 brand new 328s and I just couldn't believe that all 5 were defective. I also have an AVRISP mkii and when attempting to use that, it also would not talk to the chips, I couldn't even read the device signature. I used the AVRISP to read out the fuse bits from my Arduino UNO and also the 328P from Adafruit. The only significant difference is in the LFUSE byte. The Atmel default is 0x62, which says Internal RC oscillator" for clock, while Ada and Arduino use 0xFF which specifies an external oscillator.

That got me into looking at HV (high-voltage) programming (it's not all that "high", just +12V) which will work no matter what. I found information at mightyohm.com on how to use an Arduino to program an ATMega using HV mode and I rigged up a circuit similar to his on my breadboard, sure enough the chips were good and were setup just like the datasheet says as far as the fuse bits are concerned. So I used Jeff's (from MightyOhm) to reset the fuse bits just like the Adafruit blank chip and voila! the programmer now works perfectly on the chips I "reset" with the HV programmer.

I'm still not sure WHY this was needed, after analyzing the fuses between Atmel and Adafruit the only one that I think might have been the problem is the internal vs. external oscillator setting. Atmel sets it to internal, the Adafruit 328P was set to external. This should not matter but my theory is that for whatever reason the ATMega328s I got from DigiKey would NOT run on internal RC oscillator in my setup. It's not clear why, perhaps my +5V is too high or too low, or too slow coming up or too noisy. If I get a chance I am going to reset the LFUSE back to the factory setting and see if I can get the problem to repeat.

But the bottom line is that unfortunately I was NOT able to find a way to use the blank 328s with the Adafruit programming shield without using the HV programming method to set them to EXTERNAL clock mode.

If anyone else has some other theories I'd be interested in knowing. I hope this helps... By the way, it's pretty easy to setup a work-alike for HV programming using the MightyOhm schematic and sketch. Just one tip on something I missed. The "VCC" signal on the HV programmer is NOT +5V power. It's an Arduino output used to power the device being programmed. I also just used an external +12V power supply since I didn't have a 12V boost converter handy. You could just switch it on/off manually but I rigged up a spare ULN2003 driver and resistor to switch the +12V on/off since I also didn't have the transistor array that MightyOhm uses. I only had a handful of 328s to reprogram so I just set it up, fixed them and moved on.
jwhance
 
Posts: 15
Joined: Sun Dec 11, 2011 7:54 am

Re: Arduino Programming Shield

Postby adafruit » Sun Dec 11, 2011 12:32 pm

when using the standalone programmer sketch, DO NOT try to 'program with ArduinoISP'
simply open up the serial monitor
User avatar
adafruit
 
Posts: 10490
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: Arduino Programming Shield

Postby jwhance » Sun Dec 11, 2011 12:48 pm

I was attempting to use mine in "standalone" mode. I.e. the "pushbutton" method. So at least my problem was not with Arduino software.
jwhance
 
Posts: 15
Joined: Sun Dec 11, 2011 7:54 am

Re: Arduino Programming Shield

Postby aivoryellis » Sun Dec 11, 2011 1:09 pm

I am actually trying to burn the uno bootloader onto an ATMega328 chip. That's when I get the error. I will try the serial monitor thing ASAP.
aivoryellis
 
Posts: 9
Joined: Fri Dec 09, 2011 10:47 pm

Re: Arduino Programming Shield

Postby adafruit » Sun Dec 11, 2011 4:33 pm

jwhance wrote:I was attempting to use mine in "standalone" mode. I.e. the "pushbutton" method. So at least my problem was not with Arduino software.


if it works with the blank 328P but not blank 328's please try some other 328P's
User avatar
adafruit
 
Posts: 10490
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: Arduino Programming Shield

Postby aivoryellis » Sun Dec 11, 2011 5:40 pm

When I try and burn the bootloader on an ATMega328, I get the error that I posted above.
aivoryellis
 
Posts: 9
Joined: Fri Dec 09, 2011 10:47 pm

Re: Arduino Programming Shield

Postby adafruit » Sun Dec 11, 2011 5:51 pm

aivoryellis wrote:When I try and burn the bootloader on an ATMega328, I get the error that I posted above.


using which arduino? which programming sketch? with what menu option? with what chip? please list precisely what you're doing, what code you are running and which chip you are programming
User avatar
adafruit
 
Posts: 10490
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: Arduino Programming Shield

Postby aivoryellis » Sun Dec 11, 2011 5:55 pm

adafruit wrote:using which arduino? which programming sketch? with what menu option? with what chip? please list precisely what you're doing, what code you are running and which chip you are programming


I am using the Arduino Uno R2. I'm using this sketch:
Code: Select all
// this sketch turns the Arduino into a AVRISP
// using the following pins:
// 10: slave reset
// 11: MOSI
// 12: MISO
// 13: SCK

// Put an LED (with resistor) on the following pins:
// 8: Error - Lights up if something goes wrong (use red if that makes sense)
// 7: Programming - In communication with the slave
// 6: Heartbeat - shows the programmer is running
//
// October 2009 by David A. Mellis
// - Added support for the read signature command
//
// February 2009 by Randall Bohn
// - Added support for writing to EEPROM (what took so long?)
// Windows users should consider WinAVR's avrdude instead of the
// avrdude included with Arduino software.
//
// January 2008 by Randall Bohn
// - Thanks to Amplificar for helping me with the STK500 protocol
// - The AVRISP/STK500 (mk I) protocol is used in the arduino bootloader
// - The SPI functions herein were developed for the AVR910_ARD programmer
// - More information at http://code.google.com/p/mega-isp

#include "pins_arduino.h"  // defines SS,MOSI,MISO,SCK
#define RESET SS

#define LED_ERR 8
#define LED_PMODE A0
#define LED_HB 6

#define HWVER 2
#define SWMAJ 1
#define SWMIN 18

// STK Definitions
#define STK_OK 0x10
#define STK_FAILED 0x11
#define STK_UNKNOWN 0x12
#define STK_INSYNC 0x14
#define STK_NOSYNC 0x15
#define CRC_EOP 0x20 //ok it is a space...

void pulse(int pin, int times);

void setup() {
  Serial.begin(19200);
  pinMode(LED_PMODE, OUTPUT);
  pulse(LED_PMODE, 2);
  pinMode(LED_ERR, OUTPUT);
  pulse(LED_ERR, 2);
  pinMode(LED_HB, OUTPUT);
  pulse(LED_HB, 2);
 
  pinMode(9, OUTPUT);
  // setup high freq PWM on pin 9 (timer 1)
  // 50% duty cycle -> 8 MHz
  OCR1A = 0;
  ICR1 = 1;
  // OC1A output, fast PWM
  TCCR1A = _BV(WGM11) | _BV(COM1A1);
  TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // no clock prescale
}

int error=0;
int pmode=0;
// address for reading and writing, set by 'U' command
int here;
uint8_t buff[256]; // global block storage

#define beget16(addr) (*addr * 256 + *(addr+1) )
typedef struct param {
  uint8_t devicecode;
  uint8_t revision;
  uint8_t progtype;
  uint8_t parmode;
  uint8_t polling;
  uint8_t selftimed;
  uint8_t lockbytes;
  uint8_t fusebytes;
  int flashpoll;
  int eeprompoll;
  int pagesize;
  int eepromsize;
  int flashsize;
}
parameter;

parameter param;

// this provides a heartbeat on pin 9, so you can tell the software is running.
uint8_t hbval=128;
int8_t hbdelta=8;
void heartbeat() {
  if (hbval > 192) hbdelta = -hbdelta;
  if (hbval < 32) hbdelta = -hbdelta;
  hbval += hbdelta;
  analogWrite(LED_HB, hbval);
  delay(40);
}
 

void loop(void) {
  // is pmode active?
  if (pmode) digitalWrite(LED_PMODE, HIGH);
  else digitalWrite(LED_PMODE, LOW);
  // is there an error?
  if (error) digitalWrite(LED_ERR, HIGH);
  else digitalWrite(LED_ERR, LOW);
 
  // light the heartbeat LED
  heartbeat();
  if (Serial.available()) {
    avrisp();
  }
}

uint8_t getch() {
  while(!Serial.available());
  return Serial.read();
}
void readbytes(int n) {
  for (int x = 0; x < n; x++) {
    buff[x] = Serial.read();
  }
}

#define PTIME 30
void pulse(int pin, int times) {
  do {
    digitalWrite(pin, HIGH);
    delay(PTIME);
    digitalWrite(pin, LOW);
    delay(PTIME);
  }
  while (times--);
}

void spi_init() {
  uint8_t x;
  SPCR = 0x53;
  x=SPSR;
  x=SPDR;
}

void spi_wait() {
  do {
  }
  while (!(SPSR & (1 << SPIF)));
}

uint8_t spi_send(uint8_t b) {
  uint8_t reply;
  SPDR=b;
  spi_wait();
  reply = SPDR;
  return reply;
}

uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
  uint8_t n;
  spi_send(a);
  n=spi_send(b);
  //if (n != a) error = -1;
  n=spi_send(c);
  return spi_send(d);
}

void empty_reply() {
  if (CRC_EOP == getch()) {
    Serial.print((char)STK_INSYNC);
    Serial.print((char)STK_OK);
  }
  else {
    Serial.print((char)STK_NOSYNC);
  }
}

void breply(uint8_t b) {
  if (CRC_EOP == getch()) {
    Serial.print((char)STK_INSYNC);
    Serial.print((char)b);
    Serial.print((char)STK_OK);
  }
  else {
    Serial.print((char)STK_NOSYNC);
  }
}

void get_version(uint8_t c) {
  switch(c) {
  case 0x80:
    breply(HWVER);
    break;
  case 0x81:
    breply(SWMAJ);
    break;
  case 0x82:
    breply(SWMIN);
    break;
  case 0x93:
    breply('S'); // serial programmer
    break;
  default:
    breply(0);
  }
}

void set_parameters() {
  // call this after reading paramter packet into buff[]
  param.devicecode = buff[0];
  param.revision = buff[1];
  param.progtype = buff[2];
  param.parmode = buff[3];
  param.polling = buff[4];
  param.selftimed = buff[5];
  param.lockbytes = buff[6];
  param.fusebytes = buff[7];
  param.flashpoll = buff[8];
  // ignore buff[9] (= buff[8])
  //getch(); // discard second value
 
  // WARNING: not sure about the byte order of the following
  // following are 16 bits (big endian)
  param.eeprompoll = beget16(&buff[10]);
  param.pagesize = beget16(&buff[12]);
  param.eepromsize = beget16(&buff[14]);

  // 32 bits flashsize (big endian)
  param.flashsize = buff[16] * 0x01000000
    + buff[17] * 0x00010000
    + buff[18] * 0x00000100
    + buff[19];

}

void start_pmode() {
  spi_init();
  // following delays may not work on all targets...
  pinMode(RESET, OUTPUT);
  digitalWrite(RESET, HIGH);
  pinMode(SCK, OUTPUT);
  digitalWrite(SCK, LOW);
  delay(50);
  digitalWrite(RESET, LOW);
  delay(50);
  pinMode(MISO, INPUT);
  pinMode(MOSI, OUTPUT);
  spi_transaction(0xAC, 0x53, 0x00, 0x00);
  pmode = 1;
}

void end_pmode() {
  pinMode(MISO, INPUT);
  pinMode(MOSI, INPUT);
  pinMode(SCK, INPUT);
  pinMode(RESET, INPUT);
  pmode = 0;
}

void universal() {
  int w;
  uint8_t ch;

  for (w = 0; w < 4; w++) {
    buff[w] = getch();
  }
  ch = spi_transaction(buff[0], buff[1], buff[2], buff[3]);
  breply(ch);
}

void flash(uint8_t hilo, int addr, uint8_t data) {
  spi_transaction(0x40+8*hilo,
  addr>>8 & 0xFF,
  addr & 0xFF,
  data);
}
void commit(int addr) {
  spi_transaction(0x4C, (addr >> 8) & 0xFF, addr & 0xFF, 0);
}

//#define _current_page(x) (here & 0xFFFFE0)
int current_page(int addr) {
  if (param.pagesize == 32) return here & 0xFFFFFFF0;
  if (param.pagesize == 64) return here & 0xFFFFFFE0;
  if (param.pagesize == 128) return here & 0xFFFFFFC0;
  if (param.pagesize == 256) return here & 0xFFFFFF80;
  return here;
}
uint8_t write_flash(int length) {
  if (param.pagesize < 1) return STK_FAILED;
  //if (param.pagesize != 64) return STK_FAILED;
  int page = current_page(here);
  int x = 0;
  while (x < length) {
    if (page != current_page(here)) {
      commit(page);
      page = current_page(here);
    }
    flash(LOW, here, buff[x++]);
    flash(HIGH, here, buff[x++]);
    here++;
  }

  commit(page);

  return STK_OK;
}

uint8_t write_eeprom(int length) {
  // here is a word address, so we use here*2
  // this writes byte-by-byte,
  // page writing may be faster (4 bytes at a time)
  for (int x = 0; x < length; x++) {
    spi_transaction(0xC0, 0x00, here*2+x, buff[x]);
    delay(45);
  }
  return STK_OK;
}

void program_page() {
  char result = (char) STK_FAILED;
  int length = 256 * getch() + getch();
  if (length > 256) {
      Serial.print((char) STK_FAILED);
      return;
  }
  char memtype = getch();
  for (int x = 0; x < length; x++) {
    buff[x] = getch();
  }
  if (CRC_EOP == getch()) {
    Serial.print((char) STK_INSYNC);
    if (memtype == 'F') result = (char)write_flash(length);
    if (memtype == 'E') result = (char)write_eeprom(length);
    Serial.print(result);
  }
  else {
    Serial.print((char) STK_NOSYNC);
  }
}
uint8_t flash_read(uint8_t hilo, int addr) {
  return spi_transaction(0x20 + hilo * 8,
    (addr >> 8) & 0xFF,
    addr & 0xFF,
    0);
}

char flash_read_page(int length) {
  for (int x = 0; x < length; x+=2) {
    uint8_t low = flash_read(LOW, here);
    Serial.print((char) low);
    uint8_t high = flash_read(HIGH, here);
    Serial.print((char) high);
    here++;
  }
  return STK_OK;
}

char eeprom_read_page(int length) {
  // here again we have a word address
  for (int x = 0; x < length; x++) {
    uint8_t ee = spi_transaction(0xA0, 0x00, here*2+x, 0xFF);
    Serial.print((char) ee);
  }
  return STK_OK;
}

void read_page() {
  char result = (char)STK_FAILED;
  int length = 256 * getch() + getch();
  char memtype = getch();
  if (CRC_EOP != getch()) {
    Serial.print((char) STK_NOSYNC);
    return;
  }
  Serial.print((char) STK_INSYNC);
  if (memtype == 'F') result = flash_read_page(length);
  if (memtype == 'E') result = eeprom_read_page(length);
  Serial.print(result);
  return;
}

void read_signature() {
  if (CRC_EOP != getch()) {
    Serial.print((char) STK_NOSYNC);
    return;
  }
  Serial.print((char) STK_INSYNC);
  uint8_t high = spi_transaction(0x30, 0x00, 0x00, 0x00);
  Serial.print((char) high);
  uint8_t middle = spi_transaction(0x30, 0x00, 0x01, 0x00);
  Serial.print((char) middle);
  uint8_t low = spi_transaction(0x30, 0x00, 0x02, 0x00);
  Serial.print((char) low);
  Serial.print((char) STK_OK);
}
//////////////////////////////////////////
//////////////////////////////////////////


////////////////////////////////////
////////////////////////////////////
int avrisp() {
  uint8_t data, low, high;
  uint8_t ch = getch();
  switch (ch) {
  case '0': // signon
    empty_reply();
    break;
  case '1':
    if (getch() == CRC_EOP) {
      Serial.print((char) STK_INSYNC);
      Serial.print("AVR ISP");
      Serial.print((char) STK_OK);
    }
    break;
  case 'A':
    get_version(getch());
    break;
  case 'B':
    readbytes(20);
    set_parameters();
    empty_reply();
    break;
  case 'E': // extended parameters - ignore for now
    readbytes(5);
    empty_reply();
    break;

  case 'P':
    start_pmode();
    empty_reply();
    break;
  case 'U':
    here = getch() + 256 * getch();
    empty_reply();
    break;

  case 0x60: //STK_PROG_FLASH
    low = getch();
    high = getch();
    empty_reply();
    break;
  case 0x61: //STK_PROG_DATA
    data = getch();
    empty_reply();
    break;

  case 0x64: //STK_PROG_PAGE
    program_page();
    break;
   
  case 0x74: //STK_READ_PAGE
    read_page();   
    break;

  case 'V':
    universal();
    break;
  case 'Q':
    error=0;
    end_pmode();
    empty_reply();
    break;
   
  case 0x75: //STK_READ_SIGN
    read_signature();
    break;

  // expecting a command, not CRC_EOP
  // this is how we can get back in sync
  case CRC_EOP:
    Serial.print((char) STK_NOSYNC);
    break;
   
  // anything else we will return STK_UNKNOWN
  default:
    if (CRC_EOP == getch())
      Serial.print((char)STK_UNKNOWN);
    else
      Serial.print((char)STK_NOSYNC);
  }
}

I am using the ATMega328P-PU and I upload the sketch and select Arduino as ISP under programmer and then I click burn bootloader.
Last edited by aivoryellis on Sun Dec 11, 2011 5:59 pm, edited 1 time in total.
aivoryellis
 
Posts: 9
Joined: Fri Dec 09, 2011 10:47 pm

Re: Arduino Programming Shield

Postby adafruit » Sun Dec 11, 2011 5:58 pm

From http://www.ladyada.net/library/arduino/arduinoisp.html

According to the the ArduinoISP writeup from Arduino.cc, thus does not work with the newest UNO Arduinos. BUT we got it to work just fine, so not sure if the issue was fixed or its a rare error, or what.


some UNOs dont work well, try the standalone AVR programmer sketch tutorial

http://ladyada.net/library/tools/standaloneisp.html
User avatar
adafruit
 
Posts: 10490
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: Arduino Programming Shield

Postby aivoryellis » Sun Dec 11, 2011 6:06 pm

I would try this, but I don't have a bootloaded chip which I thought was necessary.

EDIT: I'm trying it now but I can't even upload the code to my Uno.
Code: Select all
avrdude: stk500_recv(): programmer is not responding
aivoryellis
 
Posts: 9
Joined: Fri Dec 09, 2011 10:47 pm

Re: Arduino Programming Shield

Postby adafruit » Mon Dec 12, 2011 3:07 pm

a blank chip comes with the shield kit
User avatar
adafruit
 
Posts: 10490
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: Arduino Programming Shield

Postby aivoryellis » Mon Dec 12, 2011 4:56 pm

I know that but what I'm saying is that I can't upload my code to the arduino, even with nothing attached. I'm getting a "programmer is not responding error":
Code: Select all
avrdude: stk500_recv(): programmer is not responding

Also, every other sketch works and the size is very big (30022/32256)
aivoryellis
 
Posts: 9
Joined: Fri Dec 09, 2011 10:47 pm

Re: Arduino Programming Shield

Postby adafruit » Mon Dec 12, 2011 5:01 pm

did you replace the arduino chip in the arduino? try rebooting, restarting the IDE, etc. until you can get blink sketch working again
User avatar
adafruit
 
Posts: 10490
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Next

Return to Arduino

Who is online

Users browsing this forum: dauriac, mibignistinly and 13 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [102]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]