I'm trying to learn how to do AVR programming with my Arduino using AVR libraries. I was able to successfully upload this blink program to my Arduino Micro using the Arduino IDE:
#include <avr/io.h>
#include <util/delay.h>
#define MS_DELAY 1000
int main (void) {
// Set 7th bit of DDRC to 1: sets pin 13 to output
DDRC |= _BV(DDC7);
while (1) {
// Set 7th bit of PORTC to 1: sets pin 13 to HIGH
PORTC |= _BV(PORTC7);
// Delay for MS_DELAY amount
_delay_ms(MS_DELAY);
// Turn off LED
// Set 7th bit of PORTC to 0: sets pin 13 to LOW
PORTC &= ~_BV(PORTC7);
// Delay for MS_DELAY amount
_delay_ms(MS_DELAY);
}
}
But now my Arduino does not show up on the list of available Arduino boards to connect to in the Arduino IDE, meaning I am unable to write any new programs. I was having trouble before uploading using the avrdude
commands through the terminal which is why I turned to use the Arduino IDE to help me upload. The Arduino was working fine until the final upload.
I'm on macOS so I checked my /dev/
directory and the device was not there either (my Arduino would show up as /dev/cu.usbmodemXXXX
).
How can I fix this? Did I accidentally brick my Arduino? How can I prevent this in the future?
Thank you!
The Arduino framework provides its own main which performs some initialization, such as calling USBDevice.attach. You are supplying your own main function, so you are responsible for everything, including USB and other Arduino core initialization.
Alternatively, write an Arduino sketch with setup() and loop() procedures so that you can continue using Arduino provided functionality. You can still use the lower level avr-libc functionality and manipulate hardware registers directly.
Or just move away from Arduino, then there is no ambiguity - you have to provide everything. But the Micro is not well suited for this, not if you want to use the USB bootloader. Unless, as you mentioned, you trigger the bootloader via a hard reset sequence.