Atmega32u4 breakout with Atmel Studio 6 not blinking

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ocram
 
Posts: 28
Joined: Mon Nov 19, 2012 10:06 am

Atmega32u4 breakout with Atmel Studio 6 not blinking

Post by ocram »

I am moving away from the Arduino IDE to learn programming in AVR C. I ordered the ATmega32u4 breakout and setup Atmel Studio 6 with a quick blink program. The breakout still has the avr109 bootloader on it and I am using avrdude to upload the hex file from Atmel Studio onto the micro controller.

I connected a LED with a resistor to breakout pin C6, then in Atmel Studio I wrote the following code for an Atmega32 device:

Code: Select all

#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 PORT Output
   while(1) //infinite loop
   {
      PORTC = 0xFF;
      _delay_ms(1000); //1 second delay
      PORTC = 0x00;
      _delay_ms(1000); //1 second delay
   }
}
Nothing happens with the above code. The LED remains dark.

Then I wrote the following on the Arduino IDE and used the Leonardo profile to compile a hex file:

Code: Select all

void setup()
{
   pinMode(5, OUTPUT);
}
void loop()
{
   digitalWrite(5, HIGH);
   delay(1000);
   digitalWrite(5, LOW);
   delay(1000);
}
This code works as expected. The LED blinks on and off at ~1 second intervals.

In both cases I am using the same avrdude command to upload each hex file:
avrdude.exe -F -v -c avr109 -p m32u4 -U flash:w:Blinky.hex:i -P COM5
The hex files built with the Arduino IDE and Atmel Studio are of significantly different sizes (158 bytes with Atmel Studio vs 4,818 bytes with Arduino). I guess that has to do with the Arduino wrappers getting tacked on to the hex file. It does make me wonder if the problem has more to do with Atmel Studio not building a complete/proper hex file because I don't yet know how to use it or if there is an issue instead with the board...

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Atmega32u4 breakout with Atmel Studio 6 not blinking

Post by adafruit_support_mike »

Try copying your code over directly.

The Arduino IDE is built on the same libraries, so all the low-level identifiers like PORTC and _delay_ms() will work.

User avatar
ocram
 
Posts: 28
Joined: Mon Nov 19, 2012 10:06 am

Re: Atmega32u4 breakout with Atmel Studio 6 not blinking

Post by ocram »

Hi Mike, thanks for the reply. I took the following C code from Atmel Studio and put it into the Arduino IDE:

Code: Select all

#include <avr/io.h>
#include <util/delay.h>

void setup()
{
  DDRC = 0xFF; //Makes PORT Output
}

void loop()
{
   PORTC = 0xFF;
   _delay_ms(1000); //1 second delay
   PORTC = 0x00;
   _delay_ms(1000); //1 second delay
}
Sure enough this works.... Maybe there is an issue with Atmel Studio then.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Atmega32u4 breakout with Atmel Studio 6 not blinking

Post by adafruit_support_mike »

Sounds like it.

I'll check with some of the programmers who work with AS more regularly to see if they have any hints.

User avatar
ocram
 
Posts: 28
Joined: Mon Nov 19, 2012 10:06 am

Re: Atmega32u4 breakout with Atmel Studio 6 not blinking

Post by ocram »

Mike thanks for looking into it, I found the problem. I was using the atmega32 device in AS instead of the atmega32u4.... I was following a tutorial that had a typo in it and I didn't catch it so I apologize for taking your time.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Atmega32u4 breakout with Atmel Studio 6 not blinking

Post by adafruit_support_mike »

Ah, that would do it.

Glad to hear you got it working. Happy hacking!

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”