1

I'm working on a project and my dad hit the reset button on my Arduino board, unknowingly. If it wasn't connected to any power source or computer, did it still reset? Do I have to upload my code to the board again? Or does the board need power to be reset?

  • 3
    Was the board turned off? The reset button doesn't do anything if no power is attached to the board. – James Waldby - jwpat7 Apr 6 '17 at 5:19
9

The reset on an Arduino does not erase anything. It merely restarts execution of an already uploaded program. Also the AVR needs to be powered on for it to realize whether it has been reset.

Every time you power on an Arduino it automatically starts code execution from the beginning of the program in the flash memory.

  • Everything in RAM (non persistant memory) will be erased. progmem/flash and EEPROM are persistant and will not be erased. – Paul Apr 6 '17 at 6:37
  • you can't erase RAM any more than you can erase a projector screen; electrons+photons erase themselves. – dandavis Apr 6 '17 at 9:57
  • 4
    Actually, pressing RESET doesn't erase RAM. It resets the CPU and sets all SFRs to power-on defaults, but the RAM remains the same. It's the code that is added to the start of your program (crt0.o) that erases the BSS area and copies any other defaults into place from flash. The rest of RAM continues to hold what was in there before. Of course, with no power applied it's all rubbish anyway, since nothing is happening. – Majenko Apr 6 '17 at 10:08
-2

The reset sets the processor and peripheral registers in initial state. This means that the program counter register (which marks the actual command the processor is working on) will be set to zero so the program starts from the very beginning.

The program is located in the ROM/flash which can only be erased with a flasher tool (in your case when you connect it to your PC) so a reset will not affect the program at all.

  • The reset does not affect the RAM. See Majenko's comment to the previous answer. If you use a bootloader (which is the case in the Nano), the PC is not set to zero: it's set to the start address of the bootloader area. – Edgar Bonet Jul 11 at 13:37
  • Thanks, edited. – bmann Jul 11 at 13:43
  • the program counter register [...] will be set to zero” is still incorrect. – Edgar Bonet Jul 11 at 13:47
  • Then what happens exactly? How is the program going to start from the beginning? – bmann Jul 11 at 13:51
  • 1
    The PC is set by hardware to the start address of the “boot loader flash section”. The bootloader runs, then it handles control to the user's program at address zero. See the section Boot Loader Support on the ATmega328P datasheet. – Edgar Bonet Jul 11 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.