Pages: [1]   Go Down
Author Topic: Using Diecimila as AVR ISP for a ATmega8  (Read 1156 times)
0 Members and 1 Guest are viewing this topic.
Munich, Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear all,

thanks a lot for all your posts concerning the usage of the Diecimila as AVR ISP together with avrdude.

First of all, I did not need to insert the 120 Ohm resistor between +5V and Reset on the Diecimila to get avrdude work fine.

Attempting to get the ATmega8 programmed from within Arduino0022 did not work due to signature problem. Overcome using avrdude with option -F.

But attempting to download a bootloader to a ATmega8 running on a 16MHz Xtal breadboard and connected as indicated in the
ArduinoISP page, I got avrdude apparently successfully doing what it was supposed to, but then using the fresh programmed ATmega8 in the Diecimila board, the system does not see it (stk500 error).

Here the output of the programming sequence:

------------------------
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

H:\>d:

D:\>d:

D:\>cd arduino/avr

D:\Arduino\AVR>avrdude -b 19200 -P com4 -p m8 -c avrisp

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.13s

avrdude: Device signature = 0x1e9307

avrdude: safemode: Fuses OK

avrdude done.  Thank you.


D:\Arduino\AVR>avrdude -b 19200 -P com4 -p m8 -c avrisp -F

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.14s

avrdude: Device signature = 0x1e9307

avrdude: safemode: Fuses OK

avrdude done.  Thank you.


D:\Arduino\AVR>avrdude -b 19200 -P com4 -p m8 -c avrisp -F -U flash:w:ATmegaBOOT.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.13s

avrdude: Device signature = 0x1e9307
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed

         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "ATmegaBOOT.hex"
avrdude: input file ATmegaBOOT.hex auto detected as Intel Hex
avrdude: writing flash (8170 bytes):

Writing | ################################################## | 100% 2.03s

avrdude: 8170 bytes of flash written
avrdude: verifying flash memory against ATmegaBOOT.hex:
avrdude: load data flash data from input file ATmegaBOOT.hex:
avrdude: input file ATmegaBOOT.hex auto detected as Intel Hex
avrdude: input file ATmegaBOOT.hex contains 8170 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 14.50s

avrdude: verifying ...
avrdude: 8170 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.


D:\Arduino\AVR>avrdude -b 19200 -P com4 -p m8 -c avrisp -F

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.11s

avrdude: Device signature = 0x1e9307

avrdude: safemode: Fuses OK

avrdude done.  Thank you.


D:\Arduino\AVR>

---------------------------

I am convinced I missed a step in the command line. Wrong usage of the -U option?

-U flash:w:ATmegaBOOT.hex

The bootloader I took is the one provided within Arduino0022:
    D:\Arduino\hardware\arduino\bootloaders\atmega8\ATmegaBOOT.hex

Does anyone have 5 minutes to help me out?

Thanks
Phil
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8858
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The device signature looks fine for the ATmega8.  I suspect you got the signature error when using Arduino0022 because you had not disabled auto-reset.  You might want to disable the auto-reset on the Diecimila and try to burn the bootloader again using Arduino0022.

Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Munich, Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, thanks for the reply.
In the meanwhile I have found another post describing some start-up very long delay (10s) and recommending to download a new bootloader with a start-up delay of 2s.
I have not yet tried out but will do it tonight.

Did I understand you correctly, that disabling the auto-reset (meaning pulling-up RESET to 5V thru a 120R) may get Arduino0022 work fine
to re-program the flash of the ATmega8 using the Diecimila (ATmega168) as AVR ISP?
Or should I use avrdude as I did before?
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8858
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did I understand you correctly, that disabling the auto-reset (meaning pulling-up RESET to 5V thru a 120R) may get Arduino0022 work fine
to re-program the flash of the ATmega8 using the Diecimila (ATmega168) as AVR ISP?

Yes, you understood correctly.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Munich, Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good morning!

Finally I got some time to try again.

I have used avrdude as described above to download the bootLoader with 2 seconds delay.

D:\Arduino\AVR>avrdude -b 19200 -P com4 -p m8 -c avrisp -F -U flash:w:ATmega8BOOT2s.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.13s

avrdude: Device signature = 0x1e9307
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed

         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "ATmega8BOOT2s.hex"
avrdude: input file ATmega8BOOT2s.hex auto detected as Intel Hex
avrdude: writing flash (8184 bytes):

Writing | ################################################## | 100% 2.05s

avrdude: 8184 bytes of flash written
avrdude: verifying flash memory against ATmega8BOOT2s.hex:
avrdude: load data flash data from input file ATmega8BOOT2s.hex:
avrdude: input file ATmega8BOOT2s.hex auto detected as Intel Hex
avrdude: input file ATmega8BOOT2s.hex contains 8184 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 14.50s

avrdude: verifying ...
avrdude: 8184 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.


The programming went apparently fine but then when trying to download a sketch I got the following error:

Binary sketch size: 5842 bytes (of a 7168 byte maximum)
avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51


I used the same COM channel.
So, now I feel quite confused.... Any hint?


Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8858
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The programming went apparently fine but then when trying to download a sketch I got the following error:

Binary sketch size: 5842 bytes (of a 7168 byte maximum)
avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51


I used the same COM channel.
So, now I feel quite confused.... Any hint?

My first two guesses would be: 
    1) Wrong baud rate for the bootloader. 
    2) Auto-reset is not working.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Munich, Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear 'johnwasser',
again thanks for your reply.

However it did not help ;(
1) I would not know where to change the speed in the bootloader. I used the one in the Arduino0022 distribution for ATmega8
and also the one (only binary file available) which was supposed not to wait so long.
2) I have tried pulling up RESET* to +5V via a 120R as suggested on my Arduino Diecimila. Its I/O Pin 10 is connected to the RESET* of the ATmega8. And the 3 ISP lines 11, 12 & 13 are connected one to one as indicated.

I do now believe the problem is apparently related to some internal settings of the bootloader:

#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <avr/delay.h>

//#define F_CPU         16000000

/* We, Malmoitians, like slow interaction
 * therefore the slow baud rate ;-)
 */
//#define BAUD_RATE      9600

/* 6.000.000 is more or less 8 seconds at the
 * speed configured here
 */
//#define MAX_TIME_COUNT   6000000
#define MAX_TIME_COUNT (F_CPU>>1)
///#define MAX_TIME_COUNT_MORATORY   1600000


The BAUD_RATE is passed to the compiler via the atmega8/Makefile
DEFS       = -DF_CPU=16000000 -DBAUD_RATE=19200


Any hints?
Logged

Munich, Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi again,

In another post 'johnwasser' wrote:
On the Arduino where you are running ArduinoISP you have to disable the auto-reset.  Find a small electrolytic capacitor (roughly 1 or 2 microfarad) and connect it between the Reset pin and Ground (+ side to Reset, - side to Ground).  You can probably harvest one off an old circuit board if you don't have a source handy.

Would it make it? The information is quite confuse, some speak of a 120 Ohm resistor ...
I really believe the Arduino AVR-ISP page should be updated at some point so as to provide a proven procedure.
I shall try to summarize my experience in a page ... that could be my contribution to the forum!

Now going through the forum, I also have seen the possibility to directly burn the application, if no bootloader is required. In my case, that would be the solution. I will try it out as soon I get my code compiled and linked under WinAVR into a .hex file.

Have a nice & sunny day!

Logged

Munich, Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good morning from sunny Germany!

as announced I succeeded to generate the hex file for the ATmega8 and flashed it onto the chip.

BUT, while the setup() starts to be executed, it seems to hang in a delay(5000) call.

I have crossed checked my application running it on my Diecimila with ATmega168 and it works.

Do you know of any restriction for the ATmega8 wrt ATmega168?
The LCD works fine (at least I have my welcome banner properly displayed).
 
For the flash programming, I did not use the capacitor nor the resistor between Reset* and GND.

D:\Arduino\AVR>avrdude -b 19200 -P com4 -p m8 -c avrisp -F -U flash:w:wwcc.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.13s

avrdude: Device signature = 0x1e9307
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed

         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "wwcc.hex"
avrdude: input file wwcc.hex auto detected as Intel Hex
avrdude: writing flash (6274 bytes):

Writing | ################################################## | 100% 12.64s

avrdude: 6274 bytes of flash written
avrdude: verifying flash memory against wwcc.hex:
avrdude: load data flash data from input file wwcc.hex:
avrdude: input file wwcc.hex auto detected as Intel Hex
avrdude: input file wwcc.hex contains 6274 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 11.19s

avrdude: verifying ...
avrdude: 6274 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.


PS: It's been quite a struggle to get the Makefile correct so as to generate a decent hex file what size is
concerned. The linker was reporting the size would not fit onto a ATmega8 while the compilation/linking using the
Arduino IDE was fine. I had to do with some flags:
CFLAGS += -fshort-enums -ffunction-sections -fdata-sections -ffreestanding
CFLAGS += -Wall -Wl,--relax -Wl,--gc-sections
and
CPPFLAGS += -fno-exceptions -ffunction-sections -fdata-sections -ffreestanding
CPPFLAGS += -Wall -Wl,--relax -Wl,--gc-sections


PPS: For the ATmega8 there is a warning concerning the redefinition of the macro PE which is defined first in iom8.h (PE = 2) and later in pins_arduino.h (PE = 5).

Any hint would be most appreciated ...! smiley-wink
Phil
Logged

Pages: [1]   Go Up
Jump to: