Exit(0) breaks my Micro board and turns it into a brick. After I upload the code to the Micro code using IDE, Window pops a message box "the last USB device you connected to this computer malfunctionaled and window does not recongized it ...". I tried to update the driver, but it does not help.
I would like to use Micro SPI to talk to an antenna. I wrote some code, and put exit(0) at the end of the loop().
Ex:
void loop() {
You can ALWAYS exit from an infinite loop by having the code modify the variable to cause the exit. OR! change to a compound loop that includes a variable or Boolean in the test. When time to exit the loop, change the tested value of the variable or the Boolean and you are exited.
On AVR based boards, exit() ends the program, possibly in an endless loop and interrupts disabled. I do not know for the Due.
The problem is that part of the code that you have uploaded to a board with native USB handles the USB (board detection and reaction on software reset). And by using exit() that is no longer working.
This should not effect a double tap reset; it should still invoke the bootloader; you can check it in Windows device manager.
Note that the below two seem to contradict each other. You get an error after double tap reset but you can upload?
If you still have the problem,
If your windows has a COM1, select that as the port.
If your Windows does not have a COM1, hook up and other board that does not support native ISB (e.g. Nano, Uno, Mega or a dedicated TTL-to USB adapter) and select its port.
Leave the board as Micro !!
Upload blink or an empty sketch
When the IDE reports ther memory usage, double tap the reset button.
@sunsun1437 - Glad to see the community was able to help resolve your problem.
Something that helped me while I was starting out was to get a “Ruggeduino”. It’s the same as an Arduino Uno, only it’s made by a different company.
It costs more, but the difference is you can accidentally fry an Arduino/your computers USB port if you’re not careful. “Ruggeduino” has resettable fuses for everything (even reverse polarity protection) It’s brick-proof - I’ve tried It really helps cutting down the learning curve.
exit() is a function that a program would use, on a desktop, to return to the operating system.
An Arduino does not have an operating system, so exit() doesn't do what you expect.
On an AVR like the Arduino Micro, it essentially completely stops the CPU, including the USB connection. The double-tap reset should work to get back to the bootloader, but you have to upload something else that DOESN'T exit() to restore normal behavior.
You might have wanted the C/C++ break statement, which immediately exits a loop, or perhaps return, which would stop the current function and continue from there.