Trying to not mess up an Arduino Micro

I am tinkering with an Arduino Micro and I wanted to be careful not to brick the only micro I have in hand. What I wanted to do is to explore the USB capability. I am thinking about calling USBDevice.detach() just to see what happens, and maybe mess with the HID descriptor a bit, maybe having a 10 second delay before calling detach().

My worry is that once I detach(), as warned by the comment in USBAPI.h, the serial port detaches too. If that happens, I will lose auto reset for upload, correct? I don't see any mechanism on the micro schematic to reset it other than the push button, unlike an UNO with a dedicated USB/UART chip that pulls ATMEGA's reset pin through a cap.

Should I be worried? Will the reset button be good enough to save me? I have other arduinos that can act as programmer through ICSP header though.

Thanks.

The reset button should always be sufficient to recover upload capability. The reason is the bootloader is completely separate program from your sketch so the code in your sketch should not be able to interfere with the working of the bootloader in any way.

The ISP programmer is always a nice "get out of jail free card" to have in reserve for when things get royally messed up.

+1 to the ICSP "No Fear" option!

IIRC a locked AVR can be opened by a 12V programmer though that resets flash... but never tried with Arduino.

I did goof around with AT90S2313 (on Dontronics Little RAVR board) that had to be programmed through parallel port and the code was in BASCOM.

BTW I have a lot of respect for the OP since I saw his USB business card run on ATtiny.

Ah yes, Dontronics.

Disappeared back in 2006. :slightly_frowning_face:

Great! Just used Nick Gammon's Hex uploader. The bootloader is gone (cleared hidden devices from win 10 device manager and no more hidden ones under 0x2341 VID).

I struggled with the Arduino as ISP sketch, trying to use an arduino UNO then a MEGA2560 to program anything using that sketch, even holding shift key. It seems that the sketch simultaneously programs the programmer arduino and its target. Both are blinking after the programming. Very strange.

The only down side to Nick's uploader is swapping SD card between the programmer and PC.

liuzengqiang:
I struggled with the Arduino as ISP sketch, trying to use an arduino UNO then a MEGA2560 to program anything using that sketch, even holding shift key. It seems that the sketch simultaneously programs the programmer arduino and its target. Both are blinking after the programming. Very strange.

Did you put a 10 uF capacitor between the reset and ground pin on the Arduino as ISP board?

pert:
Did you put a 10 uF capacitor between the reset and ground pin on the Arduino as ISP board?

I didn't have any caps. I followed the instructions embedded in ArduinoISP.ino. Just looked again, no caps mentioned. So host board needs 10uF micro between its own reset and ground?

For some people, it is needed to prevent the DTR signal from resetting the microcontroller on the Arduino as ISP board and activating the bootloader. You can see this on the fritzing for the Mega as Arduino as ISP on the official tutorial, though for some strange reason they left the capacitor off the Uno version.

This has always been the case, but it has recently become much more likely that you will need the capacitor because Arduino changed the protocol used by the Arduino as ISP programmer from stk500v1 to arduino. The reason they did this is to provide support for using native serial boards as Arduino as ISP. However, the unfortunate side effect is that a lot of people who previously could get by without the capacitor or who are following tutorials that don't recommend the capacitor now find that their Arduino as ISP doesn't work any more.

To resolve that issue, I reverted the change to the protocol in the Arduino as ISP programmer definition and added a new "Arduino as ISP (ATmega32U4)" programmer, which uses the arduino protocol. However, there has not been a new release of Arduino AVR Boards since that time.

liuzengqiang:
I didn't have any caps. I followed the instructions embedded in ArduinoISP.ino. Just looked again, no caps mentioned. So host board needs 10uF micro between its own reset and ground?

Nick has Arduino as ISP in his Minimal Breadboard Arduino blog. He covers the cap and I like his software better.

pert:
For some people, it is needed to prevent the DTR signal from resetting the microcontroller on the Arduino as ISP board and activating the bootloader. You can see this on the fritzing for the Mega as Arduino as ISP on the official tutorial, though for some strange reason they left the capacitor off the Uno version.

This has always been the case, but it has recently become much more likely that you will need the capacitor because Arduino changed the protocol used by the Arduino as ISP programmer from stk500v1 to arduino. The reason they did this is to provide support for using native serial boards as Arduino as ISP. However, the unfortunate side effect is that a lot of people who previously could get by without the capacitor or who are following tutorials that don't recommend the capacitor now find that their Arduino as ISP doesn't work any more.

To resolve that issue, I reverted the change to the protocol in the Arduino as ISP programmer definition and added a new "Arduino as ISP (ATmega32U4)" programmer, which uses the arduino protocol. However, there has not been a new release of Arduino AVR Boards since that time.

I was so confused that I just gave up. But now it all makes sense. The Arduino ISP is a user program. When Arduino IDE opens serial port, the board resets and runs bootloader. To prevent that, we just give RESET a big cap. I still don't know how both programmer and target were programmed simultaneously but I'm happy I don't have to keep swapping sd card between PC and sd shield to use Nick's hex uploader. It's so much easier now.
Thank you!

GoForSmoke:
Nick has Arduino as ISP in his Minimal Breadboard Arduino blog. He covers the cap and I like his software better.

Yeah, Nick's software is great! I once was able to understand the hex uploader, and made some changes to suit my needs. Not anymore. I couldn't retain enough details of his program. Maybe next time I'll read it again and write down some notes.

liuzengqiang:
I still don't know how both programmer and target were programmed simultaneously

Me neither. I have seen a variety of problems reported by people trying to use Arduino as ISP without the reset disable capacitor, but never that one before!

liuzengqiang:
It's so much easier now.
Thank you!

You're very welcome.