Go Down

Topic: Turn Arduino into an ISP programmer (Read 10 times) previous topic - next topic

whosawhatsis

#45
Feb 20, 2010, 09:33 pm Last Edit: Feb 20, 2010, 09:35 pm by whosawhatsis Reason: 1
Quote
...

I know the formulas for parallel resistance, but does anyone get why it works like it does?  How could there be a resistance of 100 Ohms, when the only path for the electricity to travel is through parallel 200 Ohm resistors? :P

Because you have two 200 Ohm paths for the current to flow through, so twice as much gets through, the same amount as one 100 Ohm path.

TchnclFl



That makes sense.  I guess I never devoted enough of my brain to the problem :P.

Artur

#47
Apr 04, 2010, 03:54 am Last Edit: Apr 04, 2010, 03:57 am by Zhan Reason: 1
http://arduino.cc/en/Tutorial/ArduinoISP
I'd like to change the default pinout (10, 11, 10, 13) but if I just change this lines:
#define SCK 13
#define MISO 12
#define MOSI 11
#define RESET 10
I get error message when I try to burn bootloader.
How I can change this?

TchnclFl

I don't think you can.

I believe those pins are specific to the ATmega chip, and you can't get those signals on other pins.

John Phagan


gadget

#50
Apr 27, 2010, 05:02 am Last Edit: Apr 27, 2010, 01:41 pm by gadget Reason: 1
I'm trying to burn the bootloader onto a 328p using a breadboard and circuit described in the playground. Everything is wired correctly, the Mega ISP sketch loaded (from examples) as per the description but when I go to burn (using IDE0018 with  Duemilanove + 328 option and using "Arduino as ISP" I get the message that the signature is wrong (1e9406 when it should be 1e950f).

The arduino board used as the ISP is a Diecimila/168. The same thing happens if I run avrdude from the command line. It appears to be reading the 168 signature on the board, rather than the target chip.

I get the same result even if no target chip is present. I have no idea what's wrong and any help would be much appreciated!

UPDATE: Solved my issue. It turns out that for whatever reason, the Mega ISP sketch does not like running on the Diecimila with a Atmega 168 aboard. I switched the chip to a bootloaded 328 from another project and everything worked perfectly. Go figure - does anyone have any explanation for this?


ILO

I have an arduino mega and would like to use it as an isp programmer for an atmega328. I followed the instructions and wiring in the playground (Mega-ISP) but it did not work for me. I also experimented modifying the code and the wiring of (Reset, MOSI, MISO, SCK) from (10,11,12,13) to
(53, 51, 50, 52) to support the Arduino Mega SPI instead of the Arduino Duemilanove but that did not work either. Any ideas?
:-[

ILO

Eureka.  :D
I finally managed to make it work. I did not use the 22pF capacitors and removed the ground to pin 8 and the 5V to pin 20.Here are all the pin connections that you want to use for the Arduino Mega:

Arduino Mega Pins [ch8594] ATMega328
5V [ch8594] 7
GND [ch8594] 22
SCK (Serial Clock)  52 [ch8594]19
MISO (Master In Slave Out) 50 [ch8594]18
MOSI (Master Out Slave In) 51 [ch8594]17
RESET (acts as Slave Select pin) 53 [ch8594]1

Also on the ATMega328:
16MHz crystal between pins 9 & 10
10K Pull up resistor on pin 1


ILO

Quote

// this sketch turns the Arduino Mega into an AVRISP
// using the following pins: 
// Arduino Mega [ch8594] AtMega328
// 5V [ch8594] 7
// GND [ch8594] 22
// 52 SCK (Serial Clock) [ch8594]19
// 50 MISO (Master In Slave Out) [ch8594]18
// 51 MOSI (Master Out Slave In) [ch8594]17
// 53 RESET (acts as Slave Select pin) [ch8594]1

// Also on the ATMega328:
// 16MHz crystal between pins 9 & 10
// 10K Pull up resistor on pin 1

// Put an LED (with resistor) on the following pins:
// 9: Heartbeat - shows the programmer is running
// 8: Error - Lights up if something goes wrong (use red if that makes sense)
// 7: Programming - In communication with the slave
//

// May 2010 by ILO Romero
// - Modified code and pin connection descriptions to support Arduino ATMega
//
//
// 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

#define SCK 52
#define MISO 50
#define MOSI 51
#define RESET 53

#define LED_HB 9
#define LED_ERR 8
#define LED_PMODE 7

#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(7, OUTPUT);
  pulse(7, 2);
  pinMode(8, OUTPUT);
  pulse(8, 2);
  pinMode(9, OUTPUT);
  pulse(9, 2);
}

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
  •  = 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)

moorecj

I am trying to burn the arduino bootloader into an Atmega328p using the Arduino as ISP method

The boards I'm using is are SB Freeduinos (diecimila derivatives)

When trying to burn the arduino bootloader i get this error while using the arduino as isp method.

avrdude: stk500_2_ReceiveMessage(): timeout

I have the two boards connected as shown in the first example here:
http://arduino.cc/en/Tutorial/ArduinoISP

The code that has been loaded into the Arduino acting as the programmer was obtained here:
http://code.google.com/p/mega-isp/
Is this the wrong code?

Is there something I'm missing?

wlewis

Hi all.. I tried this and it works.

Separately,  when I try to burn fuses on an atmega using a usb to serial cable / prolific's latest driver / and avrdude I get out of sync 0x30 on stk500 and 0x01 error messages using stk500v2. Oddly, I was able to burn fuses before on windows vista but now since ive upgraded to windows 7 its no dice.

Strangely, I have no problem loading scripts to the atmega328p using arduino.. which i dont mind telling you is a relief. But still.. Id appreciate any help using avrdude.

phattymatty

Just thought that I would add my name to the list of those with the:

avrdude: stk500_2_ReceiveMessage(): timeout

I'm currently trying to just upload a simple blink.hex program to the arduino.  (I know that this is about arduino as ISP, and I hate to digress the thread too much, but I figure moorecj and I are probably having the same problem.)

I'm currently using:

avrdude -p atmega328p -c stk500 -b 57600 -P com3 -U flash:w:blink.hex

I'm using a duemilanove with 328 chip on Win 7.  I'm fairly certain my board is on the com3 slot because I checked in my system properties.  

I've tried pushing the reset button before, at the same time as and, immediately after running the command, but it hasn't worked.  I know there are other people who have similar problems, but I haven't seen any concrete solutions (or at least any that worked for me.)  Any help would be much appreciated.

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview