Author Topic: ATmega8 with arduino as ISP programming issues...  (Read 55854 times)

0 Members and 1 Guest are viewing this topic.

Offline GabYoung92

  • Regular Contributor
  • *
  • Posts: 136
  • Country: au
Re: ATmega8 with arduino as ISP programming issues...
« Reply #75 on: July 19, 2012, 02:26:04 am »
Just to test it you could boot that PC on a ubuntu linux live cd.

sudo su

apt-get install avrdude

avrdude -i 50  -p m8 -P /dev/parport0 -E noreset -c bsd -e -U flash:w:mycode.hex


If you're wondering what the "-E no reset" does it just means the mcu will start running once the code has been written.
(Otherwise in linux the default LPT port state is with reset low, so after programming the device stays reset and you have to unplug the header to get it to run.)

I'll give that a go.  Downloading 12.04 now,
Am I able to upload the arduino bootloader to the chip using avrdude so that programming is easy until my programmer arrives?
 

Online Psi

  • Super Contributor
  • ***
  • Posts: 7513
  • Country: nz
Re: ATmega8 with arduino as ISP programming issues...
« Reply #76 on: July 19, 2012, 03:04:24 am »
Yes, if you have a bootloader hex file you should be able to upload that in the same way.

However you will need to change the fuse bits to enable the reset vector and set the required boot blocks size.
It may also need the EEPROM preserve fuse set, if the boot loader uses the eeprom?


To change a fuse bit you can go
 
avrdude  -c bsd -p m8 -E noreset -P /dev/parport0 -U lfuse:w:0x??:m 
avrdude  -c bsd -p m8 -E noreset -P /dev/parport0 -U hfuse:w:0x??:m
where ?? is the hex value to set and where lfuse/hfuse specifies which fuse byte you're setting

This is where people make mistakes and set the hfuse to what the lfuse should be or get the bit order reversed etc..

Best thing to do is first read out the current fuse bits and check to see if they make sense, as this checks if your method of reading/understanding them is correctly.

I don't think you can just display them on the screen with avrdude but you can read them out as files

avrdude  -c bsd -p m8 -E noreset -P /dev/parport0 -U hfuse:r:high.hex:r
avrdude  -c bsd -p m8 -E noreset -P /dev/parport0 -U lfuse:r:low.hex:r

Now you have two files.. high.hex and low.hex
If you run  "hexdump low.hex"  you will get

0000000 00ef                                   
0000001

So EF is the current low fuse value for that example.
Convert to binary and compare to datasheet to see which flags are set.

If you're unsure about fuse bit stuff, ask before doing it.
« Last Edit: July 19, 2012, 03:35:43 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline GabYoung92

  • Regular Contributor
  • *
  • Posts: 136
  • Country: au
Re: ATmega8 with arduino as ISP programming issues...
« Reply #77 on: July 19, 2012, 06:47:28 am »
Oh noes! I think..

First go I connected to the ATmega8..  second go I plugged it into the 328p on the arduino board..

Is there something I'm doing wrong here?

Code: [Select]
ubuntu@ubuntu:~$ sudo avrdude -p m8 -b 19200 -P /dev/parport0 -c bsd -F

avrdude: AVR device not responding
avrdude: initialization failed, rc=-1
avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
avrdude: Expected signature for ATMEGA8 is 1E 93 07

avrdude done.  Thank you.

ubuntu@ubuntu:~$ sudo avrdude -p m328p -b 19200 -P /dev/parport0 -c bsd -F

avrdude: AVR device not responding
avrdude: initialization failed, rc=-1
avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
avrdude: Expected signature for ATMEGA328P is 1E 95 0F

avrdude done.  Thank you.
 

Online Psi

  • Super Contributor
  • ***
  • Posts: 7513
  • Country: nz
Re: ATmega8 with arduino as ISP programming issues...
« Reply #78 on: July 19, 2012, 07:20:05 am »
-b does nothing when using the LPT port, it's for setting the serial port baudrate.
I've never needed to use -F to force communication. If it can't detect the signature then it's not going to work so there's no point forcing it.
Try add -i 20  that will slow down the LPT program rate.

Do you have the mega8 connected to the printer port pins correctly and are you supplying the mega8 with 5V power from somewhere?
Can you post a pic of it?
« Last Edit: July 19, 2012, 07:27:27 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline GabYoung92

  • Regular Contributor
  • *
  • Posts: 136
  • Country: au
Re: ATmega8 with arduino as ISP programming issues...
« Reply #79 on: July 19, 2012, 07:39:34 am »
-b does nothing when using the LPT port, it's for setting the serial port baudrate.
I've never needed to use -F to force communication. If it can't detect the signature then it's not going to work so there's no point forcing it.
Try add -i 20  that will slow down the LPT program rate.

Do you have the mega8 connected to the printer port pins correctly and are you supplying the mega8 with 5V power from somewhere?
Can you post a pic of it?

I've unpluged it since then.  I salvaged a 14.3F1FB crystal and two caps.  Connected them up using the arduino as ISP and tried again... But I can't seem to get it to read the signature. 

Picture of what i've got currently
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 6684
Re: ATmega8 with arduino as ISP programming issues...
« Reply #80 on: July 19, 2012, 08:21:34 am »
I was also thinking of recommending you try the simple parallel port interface, but it seems you can't get any communication happening. This can happen if you've accidentally programmed RSTDISBL, which may have been due to the same thing that caused the corruption earlier.

If I were you I'd just hook it up in parallel programming mode manually (a few switches and debounced pushbuttons is enough, and a 12V source through current-limiting resistor - 250uA is enough) and at least see if the signature bytes can be read out. The advantage of this mode is it doesn't need a clock at all, and while they're latched on the output you can probe the pins with a multimeter to see if they're the expected values. The datasheet explains the procedure in detail.
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1306
  • Country: 00
Re: ATmega8 with arduino as ISP programming issues...
« Reply #81 on: July 19, 2012, 08:25:40 am »
That should probably work if the MCU is set to use an external xtal.  Are those caps ~15pF?

The code for the programmer firmware says:

Quote
// Windows users should consider WinAVR's avrdude instead of the
// avrdude included with Arduino software.

Is this the version of avrdude you're using?
 

Offline GabYoung92

  • Regular Contributor
  • *
  • Posts: 136
  • Country: au
Re: ATmega8 with arduino as ISP programming issues...
« Reply #82 on: July 19, 2012, 08:51:24 am »
That should probably work if the MCU is set to use an external xtal.  Are those caps ~15pF?

The code for the programmer firmware says:

Quote
// Windows users should consider WinAVR's avrdude instead of the
// avrdude included with Arduino software.

Is this the version of avrdude you're using?

I'm not sure of the fuse programming.  I used the boards template on http://arduino.cc/forum/index.php?topic=112452.0 to try and program it to use the internal clock. 

The markings on them are 102 100v, 1000pF from doing a quick search.. I know they are far too large.. but it was the only caps I could salvage to try the XTAL.  I've got an order of 16MHz crystals and 20pF caps on the way.  But for the time I'd thought I would try this setup.

Yes, I was using avrdude which was inside my Arduino IDE package.  I'm installing WinAVR as I'm typing this.
« Last Edit: July 19, 2012, 08:54:09 am by GabYoung92 »
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1306
  • Country: 00
Re: ATmega8 with arduino as ISP programming issues...
« Reply #83 on: July 19, 2012, 09:00:14 am »
You never programmed the 8515, right?  And it doesn't work with the programmer either?  If so then I say something's wrong on that side instead of the MCU. 

Did you make any changes to the firmware?  I saw one of the pages suggest a change that looks like would affect the timing.

Quote
Note for Arduino 1.0: you need to make one small change to the ArduinoISP code. Find the line in the heartbeat() function that says "delay(40);" and change it to "delay(20);".
 

Offline GabYoung92

  • Regular Contributor
  • *
  • Posts: 136
  • Country: au
Re: ATmega8 with arduino as ISP programming issues...
« Reply #84 on: July 19, 2012, 09:05:24 am »
You never programmed the 8515, right?  And it doesn't work with the programmer either?  If so then I say something's wrong on that side instead of the MCU. 

Did you make any changes to the firmware?  I saw one of the pages suggest a change that looks like would affect the timing.

Quote
Note for Arduino 1.0: you need to make one small change to the ArduinoISP code. Find the line in the heartbeat() function that says "delay(40);" and change it to "delay(20);".

No I've never been able to program the 8515. Well my arduinoIDE has always told me it's failed. 

I'm using 1.0.1 which has updated the sketch already so I didn't have to change any of the code.


I think its the chip.  I'm trying to burn the bootloader onto the ATmega8 using the Arduino via arduinoIDE but I'm still getting the signature error. 
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1306
  • Country: 00
Re: ATmega8 with arduino as ISP programming issues...
« Reply #85 on: July 19, 2012, 09:14:35 am »
I'm wondering if your sketch is the same one that I got then.  I grabbed the latest version (.04) and the code still has this...

Code: [Select]
void heartbeat() {
  if (hbval > 192) hbdelta = -hbdelta;
  if (hbval < 32) hbdelta = -hbdelta;
  hbval += hbdelta;
  analogWrite(LED_HB, hbval);
  delay(40);
}

So far as the 8515 goes, if it's never been programmed then avrdude shouldn't have any issues connecting to it since there's no chance that the fuses have been fubarred yet.
 

Offline GabYoung92

  • Regular Contributor
  • *
  • Posts: 136
  • Country: au
Re: ATmega8 with arduino as ISP programming issues...
« Reply #86 on: July 19, 2012, 09:17:26 am »
I'm wondering if your sketch is the same one that I got then.  I grabbed the latest version (.04) and the code still has this...

Code: [Select]
void heartbeat() {
  if (hbval > 192) hbdelta = -hbdelta;
  if (hbval < 32) hbdelta = -hbdelta;
  hbval += hbdelta;
  analogWrite(LED_HB, hbval);
  delay(40);
}

So far as the 8515 goes, if it's never been programmed then avrdude shouldn't have any issues connecting to it since there's no chance that the fuses have been fubarred yet.

Loaded up Arduino 1.0.1, ArduinoISP sketch.  Yep, delay(20);

I'll re-upload the ISP program to my 328, connect the 8515 and give it a go.
 

Offline GabYoung92

  • Regular Contributor
  • *
  • Posts: 136
  • Country: au
Re: ATmega8 with arduino as ISP programming issues...
« Reply #87 on: July 19, 2012, 09:27:50 am »
Code: [Select]
avrdude -p m8515 -c avrisp -b 19200 -P COM7

avrdude: please define PAGEL and BS2 signals in the configuration file for part
ATMEGA8515
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.07s

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


avrdude done.  Thank you.

 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1306
  • Country: 00
Re: ATmega8 with arduino as ISP programming issues...
« Reply #88 on: July 19, 2012, 10:15:59 am »
I'm out of ideas.  I guess the next thing to try is HV parallel programming.  You might be able to find a Arduino sketch to help in that regard.
 

Offline LEECH666

  • Frequent Contributor
  • **
  • Posts: 392
  • Country: de
Re: ATmega8 with arduino as ISP programming issues...
« Reply #89 on: July 19, 2012, 12:49:59 pm »
Just something I noticed: I think you don't have to specify the -P COM7 if you're using an USB programmer like the AVRisp (Arduino). At least I never did when I used the AVRisp to programm my perfboard USBtinyISP (ATtiny2313). Maybe that's why it's reading garbage, because it's trying to access the COM Port 7 somehow and nothing is connected to it?

http://www.ladyada.net/make/usbtinyisp/avrdude.html

Quote
Using it is simple, just indicate usbtiny as the programmer type. The port option is ignored as it always uses USB.
I think the Arduino AVRisp works the same way. (Might not be true for Linux?)

I managed to fix some AVRs with bad fuse settings this way:

- I set up my Arduino to generate a clock (basically the blinky sketch without delays is what I used here). Any other clock source will probably do, like the calibration output of a scope. If you own one.

- Hooked up the clock output of the toggleing Arduino to the XTAL1 input of the broken AVR. GND of Arduino connected to GND of the AVR (obviously).

Used USBtinyISP to flash fuses with following command:

avrdude.exe -p m168 -c usbtiny -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xf9:m -B 2000

Notes:

Not all AVRs have extended fuses (efuse).

The -B option specifies the ISP clock speed. 2000 is a rather slow value. It didn't work for me without that -B option. You can read some more about the -B option on the link to Lady Ada a bit further up my post.

I put in the default fuse settings for the ATmega168 (m168). You can find out the default fuse settings of many AVRs on this handy homepage: http://www.engbedded.com/fusecalc/

I admit I didn't read the full thread, so if this has been said before, I am sorry.

Cheers,
Florian
« Last Edit: July 19, 2012, 12:55:20 pm by LEECH666 »
 

Offline GabYoung92

  • Regular Contributor
  • *
  • Posts: 136
  • Country: au
Re: ATmega8 with arduino as ISP programming issues...
« Reply #90 on: July 19, 2012, 12:58:43 pm »
LEECH666 I'll have to give that a go in the morning.  See if it makes a difference because it sort of makes sence because com7 is the port to the arduino.. this may be an issue, I'm not sure, but worth a go of course!

No DSO as of yet, but I recently ordered a Rigol ds1502e :D and was hoping for it to turn up today! :( no luck so maybe in the morning. Would the 1khz clock be fast enough?  I'm using my only arduino as the ISP so I don't think I've got any way to do the clock, except on the DSO I'm waiting on...

Great website! now to make sure I select the right thing and that I can get these chips working again :P

Don't worry, It's pretty much me trying different ways to get this to work, and failing :P 
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1306
  • Country: 00
Re: ATmega8 with arduino as ISP programming issues...
« Reply #91 on: July 19, 2012, 01:04:45 pm »
There is documentation for the Arduino ISP firmware here.
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1306
  • Country: 00
Re: ATmega8 with arduino as ISP programming issues...
« Reply #92 on: July 19, 2012, 01:57:29 pm »
Wow!  Did you see this bug?

Quote
void start_pmode() {
  spi_init();
  // following delays may not work on all targets...
  pinMode(RESET, OUTPUT);
  digitalWrite(RESET, HIGH);  // Note: Target MCU is brought out of reset.  Per Atmel spec.
  pinMode(SCK, OUTPUT);
  digitalWrite(SCK, LOW);    // Note: But SCK is set as an output and driven low.
  delay(50);
  digitalWrite(RESET, LOW);
  delay(50);
  pinMode(MISO, INPUT);
  pinMode(MOSI, OUTPUT);
  spi_transaction(0xAC, 0x53, 0x00, 0x00);
  pmode = 1;
}



That's a big problem.  Basically the programmer brings the MCU out of reset for 50 ms and during that time has the SCK pin set as an output and drives it low.  If the firmware on the chip being programmed happens to use that pin as an output and drives it high it can damage the chips. 

You might check to see if your Arduino can still make use of that pin.  It might be fried.  I would also put current-limiting resistors on all those pins from now on until you get a real programmer.  I looked through the programmer firmware and it's pretty much a big hack.
 

Offline LEECH666

  • Frequent Contributor
  • **
  • Posts: 392
  • Country: de
Re: ATmega8 with arduino as ISP programming issues...
« Reply #93 on: July 19, 2012, 06:00:56 pm »
I guess you also could use your PC soundcard plus some waveform generation software as a clock source.

I'm tempted to make a video on fixing AVRs with wrong clock fusebit settings using different kinds of clock sources and an Arduino / USBtinyISP.



 

Offline GabYoung92

  • Regular Contributor
  • *
  • Posts: 136
  • Country: au
Re: ATmega8 with arduino as ISP programming issues...
« Reply #94 on: July 20, 2012, 02:55:37 am »
TerminalJack505,

I've just extended to the blink program to switch all of the digital pins on, and all of them go HIGH and LOW, so no problems there.

Yea I was hoping to use it without having to get a programmer, but I've bought a cheap Chinese one so hopefully I get some luck then!


LEECH666,
I was thinking of doing something like that.  I know i would wire up the com of the audio jack to ground, but the pos pin, should I wire that to XTAL1 or XTAL2 on the ATmega8?

Go for it! Be great to watch, and hopefully I can learn from it :)
 

Offline LEECH666

  • Frequent Contributor
  • **
  • Posts: 392
  • Country: de
Re: ATmega8 with arduino as ISP programming issues...
« Reply #95 on: July 20, 2012, 06:40:39 am »
But you would be faced with my horrible German accent. ;)

Might try to shoot a video later.

I think it was XTAL1 which needs to be used.

Cheers,
Florian
 

Offline GabYoung92

  • Regular Contributor
  • *
  • Posts: 136
  • Country: au
Re: ATmega8 with arduino as ISP programming issues...
« Reply #96 on: July 20, 2012, 06:44:06 am »
But you would be faced with my horrible German accent. ;)

Might try to shoot a video later.

I think it was XTAL1 which needs to be used.

Cheers,
Florian

Don't mind German :P  (One of my lecturers has a strong Russian accent which at times is quite funny when he says things).

I'll have to give it a go.  Thanks!
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 6684
Re: ATmega8 with arduino as ISP programming issues...
« Reply #97 on: July 20, 2012, 09:56:36 am »
I guess you also could use your PC soundcard plus some waveform generation software as a clock source.
That might not produce enough voltage. According to the datasheet for the ATmega8 it has to be at least 0.8Vcc which is 4V for a 5V supply and 2.64V for 3.3V. Line level output is usually 2Vpp. (It can go below 0 to -1V, which is definitely not good for the AVR at all, but this could probably be avoided in software.) Careful use of an amplifier might work.

I'd go the HVPP route if I were you. Not as much equipment needed to setup if all you want to do is erase the chip and/or reset the fuses. Then again, some of us on here probably do like playing with all that extra stuff :D
 

Offline GabYoung92

  • Regular Contributor
  • *
  • Posts: 136
  • Country: au
Re: ATmega8 with arduino as ISP programming issues...
« Reply #98 on: July 20, 2012, 10:00:00 am »
I guess you also could use your PC soundcard plus some waveform generation software as a clock source.
That might not produce enough voltage. According to the datasheet for the ATmega8 it has to be at least 0.8Vcc which is 4V for a 5V supply and 2.64V for 3.3V. Line level output is usually 2Vpp. (It can go below 0 to -1V, which is definitely not good for the AVR at all, but this could probably be avoided in software.) Careful use of an amplifier might work.

I'd go the HVPP route if I were you. Not as much equipment needed to setup if all you want to do is erase the chip and/or reset the fuses. Then again, some of us on here probably do like playing with all that extra stuff :D

If I used the sound card, I would interface it with a transistor pair and source through a sensible voltage to the clock pin.

I'm not sure how to do the HVPP, is there a good tutorial I could follow?
 

Offline LEECH666

  • Frequent Contributor
  • **
  • Posts: 392
  • Country: de
Re: ATmega8 with arduino as ISP programming issues...
« Reply #99 on: July 20, 2012, 10:21:07 am »
Since you already have an Arduino you might want to check out this Arduino shield.
http://mightyohm.com/blog/products/hv-rescue-shield-2-x/

 You could probably slap smth together on a breadboard or perfboard that will work. I think you will need to have either access to a 12V source or use a step up converter to create the 12V from the 5V USB supply of your PC (like the shield does).

There is an older version of that shield that uses a transistor based step up converter instead of a single IC in a SOT23-6 package.

Let me try to find it ...

Cheers,
Florian.

//EDIT

Found the old transistor based version here: http://mightyohm.com/blog/2008/09/arduino-based-avr-high-voltage-programmer/

Probably just another hack job really. Might be okay for the occasional hobbyist fix tho. ;)

PS: amyk - Your points are valid. I didn't think about that at all. :P
Thanks for bringing it up.

//EDIT 2

Well DERP! Apparently it's not a step up converter at all. Upon rereading the article I just noticed that you still have to apply 12V externally.
« Last Edit: July 20, 2012, 10:32:08 am by LEECH666 »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf