programming with bootloader vs. direct with avrisp

I had a strange issue today: I have code running perfectly on a duemilanove and 328. It uses the arduino bootloader.

Now when I programmed a new chip using the arduino ide and burned the code directly using an avrispmkii (I went into prefferences.txt and changed the upload.using=avrispmkii) the code does not work properly. It half works...e.g. some functions work and a lot don't.

I need to do further testing but what would cause this? I would have thought the code would be exactly the same. Could it be a problem with avrispmkii firmware settings?

I need to do further testing but what would cause this?

Could be fuse settings on the new chip.

I am pretty dumb when it comes to fuses. Is there a dummies guide?

Also should I just be programming via avr studio since I can't set fuses via arduino afaik?

I am pretty dumb when it comes to fuses.

I hope you're ready to learn something new! (And hopefully I have something useful to offer!)

Is there a dummies guide?

Could be but I'm not aware of one.

Also should I just be programming via avr studio since I can't set fuses via arduino afaik?

I've had no problems using the Pololu AVR Programmer from the Arduino IDE. I suspect you will not need AVR Studio.

Let's start with some basic questions...

Is the "new chip" an ATmega328?

Did you buy the new chip with a bootloader installed? Where did you get the new chip?

Are you trying to program the new chip when it's installed in your Duemilanove?

I am using Atmega328P (dip version) purchased as a blank IC from arrow electronics. No bootloader burned on it.

I am placing it in a dueminlanove, powering via usb and porgramming via the ICSP header with an atmel avrispmkii.

I change the prefferences.txt for upload.using=avrispmkii

I did not make any changes to the boards.txt (which is where I guess I can set some of the fuse/lockbit settings for arduino ide)

I have also taken a look at this fuse calculator for some clues:
http://www.engbedded.com/fusecalc

In my sketch I am using eeprom and I am using pins 0 and 1 for something other than tx/rx (actually I am checking them for pcint).

As aforementioned, when I program the bootloader first onto one of these blank chips and then load the arduino sketch it works fine. If I program directly with the avrispmkii without first burning a bootloader then they don't work properly.

I've had several problems programming. One we thought was fixed by unplugging the USB cable and powering through the DC socket with a 9V power supply (but never circled back to confirm). But your problem looks different.

May I ask, when you program directly, and it doesn't work, are you burning in both the Arduino bootloader, and your program, or only your program?

I am wondering, if
working = bootloader + program, and
broken = program,
then maybe the bootloader sets up something which the program alone doesn't.

I was also wondering if the bootloader was providing functionality that my program uses somehow.

May I ask, when you program directly, and it doesn't work, are you burning in both the Arduino bootloader, and your program, or only your program?

When I use the IDE to upload it should only be uploading the code and not the bootloader.

Ah ha!

So, can you copy the entire flash memory image of an ATmega which has had a bootloader burned in, and has uploaded the program via the bootloader?
Then burn that whole (copied) image into a second 'raw' Atmega? (I could do it with AVR Studio, but I'm not sure if you have access to it).

If that doesn't work, then the bootloader isn't the magic component, but if it does work, the bootloader may be the magic.

I am using Atmega328P (dip version) purchased as a blank IC from arrow electronics

Processors come from the factory with the fuses set so the internal oscillator / 8 (1 MHz clock) is used.

when I program the bootloader first onto one of these blank chips and then load the arduino sketch it works fine

The IDE also sets the fuses. The missing bootloader is not the problem. The fuse settings are the problem.

You have several choices available...

  1. You can burn the bootloader onto the chip using the Arduino IDE. This also sets the fuses to use an external 16 MHz crystal. I've never done this so I won't be able to provide much help. The advantage to this approach is you'll have a second fully compatible processor.

  2. You can change the fuses using AVRDUDE. I've done this several times from the command-line and can probably help. The advantage to this approach is you'll have more code space available and won't have the bootloader delay on startup.

  3. You can create an entry in BOARDS.TXT for a 1 MHz option and build your Sketch with this option. The advantage to this approach is the processor will use less power (good for running from batteries).

I definitely want to run the chip using the 16Mhz external xtal.

Can't I change the fuse settings in the boards.txt? or is this only used by the bootloader?

I definitely want to run the chip using the 16Mhz external xtal.

Excellent. That eliminates option #3.

Can't I change the fuse settings in the boards.txt? or is this only used by the bootloader?

As far as I know, the fuse settings in boards.txt are only used when you use the IDE to burn a bootloader onto a chip.

Unless someone else has any ideas, that leaves options #1 and #2. Which would you like to pursue?