Code works on boot loader but not when directly programmed

Hi,
I have some custom PCBs that I am trying to program. They work fine if I burn the bootloader first. However if I burn the program straight on they don't work at all. I am using an AVRISP mkii. This makes no sense to me. Someone care to explain what may be causing this? I am using the uplaod using programmer feature.

Part of "burning the bootloader" is setting the fuses to change the system clock from the factory default (8 MHz internal divided by 8 to get 1MHz) to the settings Arduino uses (external 16 mHz crystal). Could that be the problem?

You have of course added code to deal with the restart and then transfer control to your sketch? Haven't you?

Mark

There is a BOOTRST fuse that tells it where to start executing. With no bootloader that needs to be the opposite value to if there is a bootloader.

How would I carry that out?
I thought it was just a case of having something working with the bootloader and then going upload using programmer

No a program written to work with a bootloader needs the bootloader to work. A program written to work without a bootloader will not (most likely) work with it.

When your processor starts up the bootloader at location x is called, the bootloader does its thing and then transfers control to your program at location y. x is defined by BOOTRST.

So you need to change BOOTRST from x to y. You also need to do any initialisation of the processor that the bootloader does for you!

Mark

The C startup code should do all that. Does the "upload using programmer" set fuses? if not, you'll need some other tool to do so, especially if the chip was previously used WITHO a bootloader.

mrjonny2:
I am using an AVRISP mkii.

How are you uploading exactly? What program? You should be able to examine the fuse settings. If so, can you tell us what they are?

I am using the Arduino IDE Version 1.0
I am not entirely sure what the fuse settings are. How would I check them?
I also always get the following error when I upload to it. I am using an ATMega2560V running @8Mhz 3.3v

avrdude: verification error, first mismatch at byte 0x0000
         0xcf != 0x0f
avrdude: verification error; content mismatch

holmes4:
No a program written to work with a bootloader needs the bootloader to work. A program written to work without a bootloader will not (most likely) work with it.

I have to take issue with this. All the boot loader does is load programs. Programs (other than bootloaders themselves) are designed to start executing from address 0. How they get there is not relevant.

To find the fuses you should be able to do something like this from a command line:

avrdude -c avrispv2 -p m2560 -v