Pages: [1]   Go Down
Author Topic: Is reset() hooked up to an event?  (Read 506 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 153
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi all,
I find myself pressing the reset-button on my arduino Mega when I'm heading off on a wrong limb. The proper working of my current sketch depend on values that are written to memory prior to full stop/reset. Does the reset()-button spawn an event that I can hook up to, to have my values written .. or shall I face the fact that I shall learn to end my sketch in a proper manner (pressing my own button) and insert the writing code in this event?
Logged

0
Offline Offline
God Member
*****
Karma: 0
Posts: 594
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When you press the reset button, all RAM is cleared (correction from westf below, it is cleared because the compiler adds startup code before "main()", not because of hardware), all registers are default values, and your code jumps to the bootloader.

You can try placing code in the bootloader, but remember that all memory is reset.

You can get rid of the bootloader, but the memory is still reset.

You can store some stuff into EEPROM, that will not be reset.

The best way is to just add another button yourself.
« Last Edit: July 12, 2012, 02:50:13 pm by frank26080115 » Logged

Freelance engineer, consultant, contractor. Graduated from UW in 2013.

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

Reset does NOT clear RAM.  The sketch startup code will clear ram, however.
Logged

0
Offline Offline
God Member
*****
Karma: 0
Posts: 594
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Reset does NOT clear RAM.  The sketch startup code will clear ram, however.


If this is the case, then it is possible to implement a reset handler, but you're going to have to compile it into the very beginning of the bootloader, or stop using the bootloader.

It will be very difficult and most likely not worth the time in comparison to just implementing another button.
Logged

Freelance engineer, consultant, contractor. Graduated from UW in 2013.

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

The bootloader does not clear RAM, either, it doesn't even use any RAM (beyond a few locations of stack) unless you upload something.  So all you really need to do is modify your sketch, although that's probably a bit tricky to do from within the Arduino environment.  (I think you could have some code execute BEFORE the startup code but putting it in one of the magic ".initN" sections.  But the big difficulty would be in doing something that doesn't get immediately undone by the startup code.)
Logged

Pages: [1]   Go Up
Jump to: