Need access to MCUSR on atmega2560

I have an arduino mega2560 running with a watchdog. Bootloader is "stk500boot_v2_mega2560.hex" Everything is fine.

But I get no access to the MCUSR flag.

Looking at the source of the bootloader: ... (starting line 567 ..) uint8_t mcuStatusReg; mcuStatusReg = MCUSR;

asm volatile ("cli"); asm volatile ("wdr"); MCUSR = 0; ...

You see why I get everytime 0 from the MCUSR.

The idea is to make the mcuStatusReg public (global) so that I can make it by an

external uint8_t mcuStatusReg


So my question is: How can I compile the bootloader on Windows 7 x64 (I tried a day to do it. Without success).

Or is there any other idea how to get the value of MCUSR after a watchdog or brownout reboot?

Best JL

But I get no access to the MCUSR flag.

I don't understand. It is a register, not a flag, and nothing prevents you from reading or modifying it..

Post your code and any error messages.

Hi jremington! "It is a register, not a flag"

Either way: you see that MCUSR is set to Zero in the bootloader.

So "Flag" or "Register" does not make a substential difference.

I Need the value before it is set to Zero.

Best JL

Why mess with the bootloader?

Define your own watchdog and/or brownout interrupt, read MCUSR and save it somewhere.

With AVR Studio and an ISP programmer, you don't even need a bootloader.

Using arduino IDE is a lot more easy for each turnaround while developing?

Just to get access to the MCUSR changing the development system seems to me too much. And may rise unforeseen other problems.

Can you tell me how I could compile the bootloader? (What Environment in Windows 7 x64)

I have here: AVR Studio 6.2 and the latest arduino IDE.

Best JL

@jremington : "With AVR Studio and an ISP programmer, you don't even need a bootloader."

This is at the end what I did. And it works.

But it was two days of recoding/adapting the source to get it to work on Atmel Studio 7.

This is what I would like have to be avoided. I had/have a complex program with many libraries not off the shelf.

Either way, I solved my Problem by migrating from Arduino IDE to Atmel Studio 7.

And Atmel Studio 7 looks great!! All new programs will be written with this IDE.

But there are still some programs written inside thhe Arduino IDE. Probably I will have to stick with both environments

Thank you.

Best JL

Studio 7 is supposed to support Arduino code as is, but I haven't tried.

The folks on the AVRFreaks forum are very knowledgeable and helpful, if you run into difficulties.

How Optiboot passes the MCUCSR register value to the application...

How to make use of the passed value...