I'm trying to make a signal generator [5usec on, 50usec off] with the Pro Micro, using the code below. It works, but had ~10 usec of jitter, so I added the noInterrupts() line in setup. This eliminated the jitter wonderfully, except now the USB port no longer works! Guessing that interrupts are needed for the USB port.
The IDE of course can no longer see the device, so I can't fix/erase the program from there. Is there a way to clear the program in the Pro Micro without using the port? I can't seem to find any solution in any of the forums. Surely a single line of code shouldn't be able to brick a device? Thanks!
void loop() {
digitalWrite(27, HIGH); // turn the output on
delayMicroseconds(5); // wait for x usecs
digitalWrite(27, LOW); // turn the output off
delayMicroseconds(50); // wait for x usecs
}
When I had a bad program that was preventing a USB link being established, the trick was to press RESET while the IDE was searching for somewhere to upload the good sketch.
digitalWrite probably takes a number of usec so that loop is not going to have a period very close to 55us if that was the aim.
You should probably monitor a continuous timer and fire off the commands when it passes appropriate values. Or use timer interrupts or something else ??? But make the timing independent of how long the write instructions take.
Resetting has an effect, but it just changes the error message. Here's the error msg without a reset:
PORTS {} / {} => {}
PORTS {} / {} => {}
Couldn't find a Board on the selected port. Check that you have the correct port selected. If it is correct, try pressing the board's reset button after initiating the upload.
And heres the msg if I reset during the upload:
PORTS {} / {} => {}
PORTS {} / {} => {}
PORTS {} / {COM4, } => {COM4, }
Found upload port: COM4
System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"
Using Port : COM4
Using Programmer : avr109
Overriding Baud Rate : 57600
avrdude: ser_open(): can't open device "\.\COM4": The system cannot find the file specified.
avrdude done. Thank you.
Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
Any clues there? (The troubleshooting link had no suggestions for dealing with a plagued USB port)
Played around some more, and discovered that the reset button was bouncing a bit. Finally got the button to produce exactly one reset pulse during the upload, then it worked!
It uploaded a fixed version of the code, and appears to be un-bricked, thanks!