Go Down

Topic: Burning bootloader to ATMEGA328 via ATMEGA168 (Read 5669 times) previous topic - next topic

sonicvsb

Jun 18, 2014, 05:05 pm Last Edit: Jun 18, 2014, 05:08 pm by sonicvsb Reason: 1
I have the following components: an ATMEGA328 and an ATMEGA168.
I have used the 168, with its bootloader, along with a FTDI RL232 breakout board to program and use as normal. I have had no problems so far. My circuit there is: +5V and GND on ATMEGA chip where necessary, TXD of FTDI to Digital Pin 0 (Pin 2 on IC) and RXD of FTDI to Digital Pin 1 (Pin 3 on IC). Also, there is a 16MHz crystal on XTAL1 and XTAL2 pins, along with 18pf capacitors tied to ground. DTR of FTDI is brought through a 0.1uF capacitor into RESET line (pin 1 of IC) and CTS is tied to ground.

However, I recently got some new fresh 328's. They do not have a bootloader on them, so I decided to turn my existing Arduino "clone" to an ArduinoISP. I have used the following tutorial: https://learn.adafruit.com/arduino-tips-tricks-and-techniques/arduinoisp
Circuit is as follows: Pin 1 (IC) of 328 to Digital Pin 10 of 168
Pin 7 (IC) of 328 to 5V
Pin 8 (IC) of 328 to GND
Pin 9 (IC, XTAL1) of 328 to Digital Pin 9 of 168
Pin 17 (IC) of 328 to Digital Pin 11 of 168
Pin 18 (IC) of 328 to Digital Pin 12 of 168
Pin 19 (IC) of 328 to Digital Pin 13 of 168
Pin 20 (IC) to 5V
Pin 22 (IC) to GND

Two 5mm LEDs through 1K resistors each, tied to pins A0 and Digital pin 8 of 168. Then to Ground.
I uploaded my ArduinoISP sketch as I had always uploaded sketches - "Arduino Diecimila or Duemilanove w/ ATmega168 on COM3". It went through. I selected "programmer->ArduinoISP" and then tried to burn the bootloader to the 328. I have a question: which "Board" should I use? I trued Uno, Duemilanove w/ Atmega328 as well as Diecimila/Duemilanove 168. I also tried with adding a 10uF cap between DTR (reset) and GND. It does not seem to make a difference. Here is what I get:

Code: [Select]
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 have checked the connections. Everything seems to be OK. Any ideas?

Edit: version of IDE is 1.0.5-r2 and not 1.5.2. which is reported not to work with ArduinoISP.

Riva

Have a look at this as it gives a better visual representation of how to connect up. Remember to connect both VCC & GND pins on the 328. You will also need a crystal/resonator on the 328.
1 Select 168 board
2 Upload the ArduinoISP sketch
3 Power off 168, connect capacitor between reset and GND and connect wires to the 328
4 Power on the 168 & 328
5 Select UNO as board and ArduinoISP as the programmer and do Burn bootloader
Don't PM me for help as I will ignore it.

Budvar10

#2
Jun 18, 2014, 05:26 pm Last Edit: Jun 18, 2014, 05:28 pm by Budvar10 Reason: 1
Chek it again. You omitted 10k resistor on 328 from reset to 5v. I am recommending to look at ArduinISP on this website, here is also schematic of UNO R3 and connect accordingly. ISP uses pins 16-19 from168!
Arduino clone with ATmega1284P   http://forum.arduino.cc/index.php?topic=277260.0

Budvar10

Look at Arduino on breadboard and connect 328 according this. Then connect pins 19 to 19, 18 - 18, 17-17 , 168.16 to 328.1.
For raw 328 you need not crystal but only for the first try, while fuses stay unprogrammed. I hope that I am correct with pins, check it twice.
Arduino clone with ATmega1284P   http://forum.arduino.cc/index.php?topic=277260.0

sonicvsb

#4
Jun 18, 2014, 05:59 pm Last Edit: Jun 18, 2014, 06:08 pm by sonicvsb Reason: 1
Actually, it was wired almost the same with the first try.
I have done it with the tutorial from this site. Connected pins, checked them five times. I also put a 16Mhz crystal and capacitors, connected all +5Vs and GNDs. What I forgot was the 10K resistor. Also, the 10uF capacitor stays in. When I put it, now I get the following error:

Code: [Select]
avrdude: Expected signature for ATMEGA328P is 1E 95 0F
        Double check chip, or use -F to override this check.


Now I am suspecting wrong fuses, but I do not know what and how to change.


I actually checked if the chip wasn't ATmega328-PU instead of ATmega328P-PU, which should have no problems. I saw that the chip was 328P-PU, so no problems here, I guess?

Riva

What device signature are you getting back? Might need to turn on verbose upload in preferences.
The fact it's reporting back a valid signature looks good for your connections.
Have a look here for details of overcoming differences (or use the -F option)
Don't PM me for help as I will ignore it.

sonicvsb

Here is the verbose output.

Code: [Select]
C:\Program Files (x86)\Arduino\hardware/tools/avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega328p -cstk500v1 -P\\.\COM3 -b19200 -e -Ulock:w:0x3F:m -Uefuse:w:0x05:m -Uhfuse:w:0xde:m -Ulfuse:w:0xff:m

avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware/tools/avr/etc/avrdude.conf"

         Using Port                    : \\.\COM3
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
         AVR Part                      : ATMEGA328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
avrdude: Send: A [41] . [80]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [02]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [81]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [01]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [82]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [12]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [98]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
avrdude: Send: A [41] . [84]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [85]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [86]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [87]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [89]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: Send: A [41] . [81]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [01]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [82]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [12]
avrdude: Recv: . [10]
avrdude: Send: B [42] . [86] . [00] . [00] . [01] . [01] . [01] . [01] . [03] . [ff] . [ff] . [ff] . [ff] . [00] . [80] . [04] . [00] . [00] . [00] . [80] . [00]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
avrdude: Send: E [45] . [05] . [04] . [d7] . [c2] . [00]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
avrdude: Send: P [50]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
avrdude: AVR device initialized and ready to accept instructions

Reading | avrdude: Send: V [56] 0 [30] . [00] . [00] . [00]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: V [56] 0 [30] . [00] . [01] . [00]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
################avrdude: Send: V [56] 0 [30] . [00] . [02] . [00]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
################################## | 100% 0.06s

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

avrdude: Send: Q [51]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]

avrdude done.  Thank you.



I have seen the differences between 328 and 328P. I am assured that mine is 328P, so no problem there. Anything else?

Riva

Maybe it's not all connected up correctly then.
Code: [Select]
avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.
Don't PM me for help as I will ignore it.

sonicvsb

As I inspect the breadboard connections, it is correct. Is it possible that the chip is dead?

I'll try to rebuild the breadboard tomorrow and we'll see if I've missed something and if it works.

Budvar10

Code: [Select]
avrdude: Expected signature for ATMEGA328P is 1E 95 0F
         Double check chip, or use -F to override this check.

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

I don't thik the chip is dead. I've seen this messages already, after I tried to burn chip on the breadboard and always I was able to burn it correctly, but I don't know exact solution. I am not sure but second message means that your ArduinoISP sketch is corrupted (don't forget to disconnect 328P before upload!). Disconnect it from PC, check the connections carefully and try again. There are only 4 important wires beside of power and GND.
Arduino clone with ATmega1284P   http://forum.arduino.cc/index.php?topic=277260.0

westfw

Quote
Pin 9 (IC, XTAL1) of 328 to Digital Pin 9 of 168

Are you running Adafruit's version of ArduinoISP?  The standard "example" ArduinoISP does NOT provide a "clock" on pin D9, and I think a bunch of the other pins are different as well...

sonicvsb

I will do everything again today from scratch. I also have another blank ATmega328P-PU, will try that as well.

When pin 9 clock was connected, I was using Adafruit's sketch. When I connected a crystal, I tried using the normal ArduinoISP instead. Yes, when uploading, I disconnect the 328. I have connected the three "Heartbeat", "Error" and "Programming" LEDs according to the sketch to the 168. I see only the Programming LED on for a while and then when I am given the error the LED starts fading and increasing in Brightness slowly, as PWM. Error and Heartbeat are not seen on.

My basic questions before I start rebuilding everything:
- It seems that I need a 0.1uF capacitor between DTR and the Reset pin of 168 in order to upload the sketch correctly. After that, do I need it? Should I have only it, or should I have only 10uF electrolytic between Reset and GND or both caps?
- Which resistor should I use between RESET and +5V? It has been suggested both 10K and 120 Ohms. I have tried both, but I want to know for sure before I begin again.

Riva


My basic questions before I start rebuilding everything:
- It seems that I need a 0.1uF capacitor between DTR and the Reset pin of 168 in order to upload the sketch correctly. After that, do I need it? Should I have only it, or should I have only 10uF electrolytic between Reset and GND or both caps?
- Which resistor should I use between RESET and +5V? It has been suggested both 10K and 120 Ohms. I have tried both, but I want to know for sure before I begin again.

If your uploading a sketch using the bootloader then the MCU needs resetting (using the 0.1uF on DTR/Reset) to invoke the bootloader to upload the sketch.
If your uploading using SPI then the reset is connected as part of this so it can force a reset as needed. The 10uF capacitor is needed on the Arduino doing the programming (not the Arduino being programmed) when using ArduinoISP to stop it from being reset when AVRDude opens the serial port to upload the bootloader/sketch to the programmer.
Don't PM me for help as I will ignore it.

sonicvsb

I ripped everything off the board and then rebuilt it again. Now, another problem. During the ArduinoISP SKETCH upload to the 168, I get the same "non-sync" error. Checked the connections, everything seems to be OK. Maybe it is dead? Or my trusty little FTDI chip...

Riva


I ripped everything off the board and then rebuilt it again. Now, another problem. During the ArduinoISP SKETCH upload to the 168, I get the same "non-sync" error. Checked the connections, everything seems to be OK. Maybe it is dead? Or my trusty little FTDI chip...

You can test the FTDI using loopback (wire between RX/TX) and a serial terminal.
Don't PM me for help as I will ignore it.

Go Up