Atmel Studio with Arduino IDE

Hy!

I’ve downloaded the Arduino IDE for the Atmel Studio 6.2. The reason is to be able to use the Arduino functions, while making my program in the good old C programming language. Here is a simple code I’ve written:

#include <avr/io.h>
#define F_CPU 16000000UL		// clock: 16 MHz
#include <util/delay.h>			// delay
#include <avr/interrupt.h>
#include "Arduino.h"

int main(void)
{
	sei();			// enable interruots
	DDRB |= 1<<7;	// on board led
	DDRE |= 1 << PINE3;		// digital pin 5 to output	(PWM)
	// PWM config:
	TCCR3A |= 1<<WGM11 | 1<<COM1A1 | 1<<COM1A0;
	TCCR3B |= 1<<WGM13 | 1<<WGM12 | 1<<CS30;
	ICR3 = 1999;		// 8kHz signal
	OCR3A = 1000;		// 50 % duty cycle
	
	init();
	
	Serial.begin(9600);		// enable serial comm, 9600 baud
	
	while(1)
	{
			Serial.print("\n Hello");		// print "Hello" on the screen
			PORTB ^= 1<<7;					// blinks the on board led 
			_delay_ms(1000);				// wait 1 s
	}
}

I have a little problem with that. If I use the “init();” function than the serial communication and the led blinking works, but the pwm signal generation is not. If I delete the “init();” function than the pwm generation and the led blinking works, but the serial communication is not. I think I’m really close to use both environment’s advantages in one project. Maybe some changes needed to the Arduino.h file, but I don’t know what. Could you help me guys to solve this?

Sounds to me like init() screws with the timer and sets up the serial port. What is init()? Have you looked at the code to see what it does?

Maybe move that call to before your timer setup stuff.


Rob

What is init()?

It’s a function that the IDE calls to set up the hardware (including timers) in every sketch.

Yes of course, steelgoofy, have a look in wiring.c, you will see that init() does indeed play with that timer.

BTW, I've used the Visual Micro plug in a fair bit and don't remember every having to call init().


Rob

The reason is to be able to use the Arduino functions, while making my program in the good old C programming language.

There is a far easier way to accomplish what you want to do: http://forum.arduino.cc/index.php/topic,40585.0.html

Ray