Detect watchdog timer reset

I have a problem with the watchdog timer.
I can activate it, it works, because it resets the microprocessor, but when the arduin restarts I can not understand if it started normally or was a watchdog timer reset.

I read the MCUSR but it's always 0!

#include <avr/wdt.h>
unsigned long i;
uint8_t mcusr_temp;

void setup() {
  // put your setup code here, to run once:
  mcusr_temp = MCUSR;
  MCUSR = 0;

void loop() {
  // put your main code here, to run repeatedly:

void ResetTest(){
if(mcusr_temp & (1<<WDRF)){
   // a watchdog reset occurred
if(mcusr_temp & (1<<BORF)){
  //  a brownout reset occurred
if(mcusr_temp & (1<<EXTRF)){
  //  an external reset occurred
if(mcusr_temp & (1<<PORF)){
  //  a power on reset occurred

What am I doing wrong?

I assume you are using an Arduino board with Optiboot installed.

The watchdog is also used to end an upload. As long as you are using Optiboot you will not be able to tell the difference between watchdog-expired and first-run-after-upload.

This is an example of how to detect a watchdog reset...

This has some of the gory details...

Thank you for the reply.

But the example does not seem to work so well, in response i get

Reset flag test
Have reset flag value 0xFE Watchdog Brownout External Unknown

It takes all the values.
I use an Arduino UNO

I should have included...

I assume you are using an Arduino board with a recent version of Optiboot installed.

You may have to update your bootloader.