element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Is it possible to reset the Arduino with a software command?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 22 replies
  • Answers 5 answers
  • Subscribers 394 subscribers
  • Views 3897 views
  • Users 0 members are here
Related

Is it possible to reset the Arduino with a software command?

billpenner
billpenner over 9 years ago

I am now resetting using  "asm volatile ("  jmp 0"); and it works but I would like to leave the variables as is. I want to leave the LCD backlight off. I can supply the code if necessary.

Thanks, Bill

  • Sign in to reply
  • Cancel

Top Replies

  • Robert Peter Oakes
    Robert Peter Oakes over 9 years ago +2 suggested
    essentially it would be as if you hit the reset button. Remember the Arduino code is at a very high level, abstracting much of the hardware and even code from the developer, the typical developer using…
  • Robert Peter Oakes
    Robert Peter Oakes over 9 years ago in reply to shabaz +2
    Oh so true But a fun road to travel, as with many things, the trip can be more fun that the destination
  • shabaz
    shabaz over 9 years ago +1 suggested
    Hi Bill, That may be tricky, depending on the scope some variables are set to zero automatically, and others will have different content (i.e. non-zero). However, one option is to write your data to EEPROM…
Parents
  • shabaz
    0 shabaz over 9 years ago

    Hi Bill,

     

    That may be tricky, depending on the scope some variables are set to zero automatically, and others will have different content (i.e. non-zero).

    However, one option is to write your data to EEPROM, which of course is persistent even after power loss.

    Is there a reason you wish to reset? Ordinarily you'd never do that (unless a software failure was detected, e.g. using a watchdog timer)

    or some rare scenario like a software upgrade. (normal practice is to never allow have the microcontroller to reset or exit).

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • billpenner
    0 billpenner over 9 years ago in reply to shabaz

    I realize how correct you are re: It's not wise, normal to reset, re power a microprocessor. But I am concerned that an error could occur that would lock up the system. By starting from the beginning would clear any thing like overflowing the stack due to incorrect input or electronic noise or my bad programming. I don't have debugging programs that would allow me to se the state of all the variables , stack etc. I also don't have the time or expertise to check every possible scenario.  I tried setup() ; ..there is where I realized that I can't leave the variables as they are ( what a mess this creates). I appreciate all the helpful advice and I am still working on all the suggestions. At present, I am still using the asm volatile ("  jmp 0") and although it causes blinks in the display, it seems to be safe regarding the above. The training is worthwhile even if I am not able th fully understand all the ramifications of the suggestions.

    Bill

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • billpenner
    0 billpenner over 9 years ago in reply to shabaz

    I realize how correct you are re: It's not wise, normal to reset, re power a microprocessor. But I am concerned that an error could occur that would lock up the system. By starting from the beginning would clear any thing like overflowing the stack due to incorrect input or electronic noise or my bad programming. I don't have debugging programs that would allow me to se the state of all the variables , stack etc. I also don't have the time or expertise to check every possible scenario.  I tried setup() ; ..there is where I realized that I can't leave the variables as they are ( what a mess this creates). I appreciate all the helpful advice and I am still working on all the suggestions. At present, I am still using the asm volatile ("  jmp 0") and although it causes blinks in the display, it seems to be safe regarding the above. The training is worthwhile even if I am not able th fully understand all the ramifications of the suggestions.

    Bill

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • shabaz
    0 shabaz over 9 years ago in reply to billpenner

    Hi Bill,

     

    A software reset can (sometimes) be a good thing to do to handle situations as you describe (program runaway for instance).

    I was just addressing that second point in you original question, i.e, regardless of the way the reset occurs (jmp zero, watchdog programmed reset, or forcing a pin as mcb1 mentions), the variables can not be assumed to remain the same (despite power not having been removed from the chip), because in-between the reset and the Arduino main/loop etc, there is a bit of invisible code (called C startup or similar) which will force some variable storage to zero. Any that are not forced to zero cannot be presumed to be uncorrupted anyway, due to the program runaway which might have caused the reset (so that was the only reason I wanted to confirm why the reset was to occur, because we have to presume loss of all state information upon reset (regardless of the way the reset occurs) unless state can be inferred from elsewhere (e.g. logic levels on pins or non-volatile memory).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • billpenner
    0 billpenner over 9 years ago in reply to shabaz

    Thank you. My comment was not meant in any way to be criticizing. Quite the opposite. I can't thank you and the others on the forum enough for all the help. I take every comment in the way it is intended, that is, to be helpful.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • shabaz
    0 shabaz over 9 years ago in reply to billpenner

    Hi Bill,

     

    You're too kind, it was no problem at all to help. I just wasn't sure if the second part (regarding the state of variables had got lost in the discussion since the thread had grown a bit since I last saw it!).

    I don't know much recent stuff about Arduino, but I learn a lot from following what you and others do with it. From that I gather it

    has underlying C compiler, just the compiling/building of the code is hidden from the user to a degree.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 9 years ago in reply to shabaz

    Not that I am a software programmer, but I tend to force/set variables either during the initial declaration or during void setup().

    Call me stupid but I always imagined it was better to be sure.

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • shabaz
    0 shabaz over 9 years ago in reply to mcb1

    Hi Mark,

     

    I do too, it would be thrown out in a code review if it wasn't, so I agree. I interpreted Bill's query to be whether there was a way to maintain variable content across a reset regardless of whether it was wise or not. The answer being no, not all variables will be persistent (some data spaces are).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 9 years ago in reply to mcb1

    Better than using them with garbage. Otherwise GIGO (garbage in, garbage out).

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 9 years ago in reply to shabaz

    I think more specifically it would be fare to say you "Can Not Guarantee" the preservation of volatile RAM through a reset condition so therefor should NEVER rely on it happening

    If you need variables preserving across resets either software invoked or Power Cycle then you need to use None Volatile RAM, either the EEPROM or an external SD Card

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • shabaz
    0 shabaz over 9 years ago in reply to Robert Peter Oakes

    Hi Peter,

     

    In theory if you're careful, the behaviour is guaranteed. The JMP 0 won't corrupt memory, it is a legal instruction. However, as mentioned several times, the compiler and C-startup code will have defined behaviour, and it depends on the scope of the variables. That part is outside of our control (unless we rewrite it, or use a different language or just write in assembler).

     

    In real life, the answer is obviously no for a couple of reasons, primarily because if you've had program runaway then you cannot assume your important variables have not been corrupted either, and secondly in real life no-one would ever be allowed to have such code in a shipping product since it won't pass any code review.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 9 years ago in reply to shabaz

    But it may not take much to mess that up, for instance a pin state (Input) being different during the power on first time run causing the order of the variable creation to be different, now your really messed up.

    Yes there are ways around it to improve the odds of the ram to be intact but is it worth the headaches, and it still does not help you with a power on reset as here there are no guarantees and the code really does not know the difference.

     

    Though some MPU;s have a flag to indicate if the reset was a POR or Soft but i'm not sure if the AMEGA328 has that

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • shabaz
    0 shabaz over 9 years ago in reply to Robert Peter Oakes

    I agree. A POR isn't the same, and all goes out the window in that case. And as you say, additional trickiness is then to figure out what kind of reset occurred. I think Bill is aware we're not advocating this should be done at all, we wouldn't do it for real. In practice only a few times I can think of for a JMP 0 (other than a watchdog forced reset which can be a different location) such as perhaps after an in-service software upgrade.. and even then we wouldn't be presuming the state of RAM contents in our code (for reasons mentioned before).

    As usual, a simple question is more involved depending how deep the rabbit hole we go.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube