Pages: [1]   Go Down
Author Topic: Code works on boot loader but not when directly programmed  (Read 770 times)
0 Members and 1 Guest are viewing this topic.
London, UK
Offline Offline
Full Member
***
Karma: 4
Posts: 190
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8933
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

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

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2363
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Mark
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19026
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


London, UK
Offline Offline
Full Member
***
Karma: 4
Posts: 190
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2363
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 135
Posts: 6782
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19026
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged


London, UK
Offline Offline
Full Member
***
Karma: 4
Posts: 190
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Code:
avrdude: verification error, first mismatch at byte 0x0000
         0xcf != 0x0f
avrdude: verification error; content mismatch
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19026
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:
avrdude -c avrispv2 -p m2560 -v
Logged


Pages: [1]   Go Up
Jump to: