I am slowly moving from Arduino to AVR C. I purchased an atmega32u4 breakout board from Adafruit (this one here) which comes preloaded with a bootloader that allows programming through the USB interface. I setup Atmel Studio 6 to write and build the code and avrdude to upload the hex file onto the micro controller. These steps work well and I am able to build and upload without issue. The problem I am having is that the hex file built by Atmel Studio does not appear to run on the mega32:
#ifndef F_CPU #define F_CPU 16000000L // 16 MHz clock speed #endif #include <avr/io.h> #include <util/delay.h> int main(void) { DDRC = 0xFF; //Makes all pins on PORTC outputs while(1) //infinite loop { PORTC = 0xFF; _delay_ms(1000); //1 second delay PORTC = 0x00; _delay_ms(1000); //1 second delay } }
There is a simple circuit of a LED and a resistor to verify the operation of the code above.
I have taken the same code above and put it into the Arduino IDE as such:
#include <avr/io.h> #include <util/delay.h> void setup() { DDRC = 0xFF; } void loop() { PORTC = 0xFF; _delay_ms(1000); PORTC = 0x00; _delay_ms(1000); }
This works as expected and the LED lights on and off at about once per second. I am using the Arduino IDE only to build the hex file using the Leonardo profile (runs an atmega32u4). However, in both cases I am using avrdude to upload the hex file to the micro controller as such:
avrdude.exe -F -v -c avr109 -p m32u4 -U flash:w:Blinky.hex:i -P COM5
I have a high degree of confidence I am doing something wrong in Atmel Studio.
Thanks for listening.