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?
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.
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...
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.
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.
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).