Using Serial.begin() in Atmel Studio 7

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi

 

I'm trying to use Serial.begin() in AS7, but i keep getting an error: 'Serial' was not declared in this scope.

I tried including a few Arduino libraries, without luck. Can anyone help me?

My code follows below.

 

/*
 * fc.cpp
 *
 * Created: 21.04.2017 13.37.58
 * Author : jonle
 */ 

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


int main(void)
{
 
 // Set pin 12 to output writing directly to the register for pin 12; data direction register B4 is connected to pin 12
 DDRB |= ((1 << DDB4));
 
 //PCICR |= (1 << PCIE0);
 
 Serial.begin(9600);
 
    while (1) 
    {
  
 }
}

 

Regards

Jon Leithe

This topic has a solution.

/Jon

Last Edited: Fri. Apr 21, 2017 - 01:35 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Serial is a class in Arduino. It does not exist in "standard" C++

 

What you can do is write an INO sketch in the Arduino IDE that includes a call to it then use the "Arduino import" feature that was recently added to As7 and that will pull in enough of the Arduino library code to make Serial available.

 

The alternative if you want to go a more "bare metal" route is simply to write UART_init() and UART_sendchar() functions from scratch then use the FDEV stuff that is demonstrated here:

 

http://www.nongnu.org/avr-libc/u...

 

and then you can just use printf()/puts()/pucthar() and so on like you would in any standard C program.

 

The key thing is the call that connects the UART_sendchar() to the "stdout" stream that printf() etc will be using. That is usually FDEV_SETUP_STREAM().

 

But if you have come from an Arduin obackground maybe it's just easier to use Arduino functions to achieve stuff? In that case write what you want in an INO then import it.

 

To be honest, unless you plan to debug, you might as well just stick with the Arduino IDE anyway - AS7 actually offers very little extra to the actual authoring of the code.