int after warm start (reset)

Hello,

after pressing Reset (Mega2560), I need an old value in an int. But after Reset, the system overwrites the int with value 0 :confused: .

What is to do at definition time to tell the compiler not to write into this int?

Warm start is after pressing reset,
Cold start is after power off (voltage free hardware).
I need to see the difference between both at runntime.

Thank you for help!

Uwe

UPW:
Warm start is after pressing reset,
Cold start is after power off (voltage free hardware).
I need to see the difference between both at runntime.

Maybe there is no visible difference- what makes you think there is?

But the question on everyone's lips is lkely to be "why do you need to press reset in the first place?".

There should be a noinit option, but I've never used it.

Be careful what you wish for.

What is to do at definition time to tell the compiler not to write into this int?

You can't.

You could save the important value in EEPROM, when it changes, and read the last saved value in setup().

Hello AWOL,

thank you very much, noinit is the keyword for my problem, so I was able to find this here:

tried it with :

int16_t WarmStartFlag attribute ((section (".noinit")));

and it WORKS !!!

Thank you !!! :slight_smile:

UPW:
and it WORKS !!!

So now, satisfy our curiosity and tell us WHY :wink:

Hello,

as written earlier, I need to know the difference between POR (power on reset) and reset. The idea: With reset, the values survive, with por the values are destroyed. But Arduino overwrites 0 and the info is gone.

I know, that the new int value after reset has a chance 1:64k to be the same old value. But I need it quick and dirty. Quick was your part, thank you for this (dirty I know to make myself :slight_smile: )

Writing into eeprom survives in any case, so I canΒ΄t see the difference between por and reset. Sure there is a possibility to get it right with eeprom (I have everything but time).

Thanks again,

Uwe

Is that not the purpose of the MCUSR – MCU Status Register?

I do somethign similar - 'knowing' when the system is stable - all stays as-is.
If the system is reset (POR or WDT) - then it was an unexpected reset, so the EEPROM value is not valid after the restart.

This may give you some ideas for MCUSR