Solved: Intro to Atmel Studio - Programming ATmega328p and ATtiny85

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

 

Hello,

 

I have always done my projects using Arduino IDE.

This works fine for prototypes, but for production PCBs, I'd like to be able to work with other MCUs.

 

I am working in Atmel Studio 7 with an Atmel ICE and an ATmega328p.

First, I'd like to establish a simple test like blinking an LED.

I took the basic blink sketch from arduino and imported it into Atmel Studio 7.

 

/*Begining of Auto generated code by Atmel studio */
#include <Arduino.h>

/*End of auto generated code by Atmel studio */

//Beginning of Auto generated function prototypes by Atmel Studio
//End of Auto generated function prototypes by Atmel Studio

/*
  Blink

  Turns an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino
  model, check the Technical Specs of your board at:
  https://www.arduino.cc/en/Main/Products

  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Blink
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(3, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(3, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(3, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

I can get the LED to flash, but its for like 10 seconds on and off.

I checked in the programming tool and the fuses are set to use the 8 mhz internal timer.

What am I doing wrong so far?

 

 

The other concern I have is that my planned design uses both a 328p and a tiny85.

328p is i2c master and sends instructions to tiny85.

No Arduinos use a tiny85 to my knowledge, so I'm wonder how writing code for tiny85 in Arduino IDE would work, or if it is even possible.

I'm not opposed to learning C, and writing sketches from scratch in Atmel Studio for these devices.

From what I understand, code written in C should work on any of the Atmel chips supported by my Atmel ICE.

 

Is learning C my best option to this problem, or should I continue to work with Arduino IDE and Atmel Studio both and let Arduino IDE do the heavy lifting when it comes to programming?

If learning C is my best option, can you point me to resources to help shorten the learning curve? 

 

Thanks,

 

Caddy

 

 

Last Edited: Thu. Sep 19, 2019 - 02:57 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

caddywhompus wrote:
What am I doing wrong so far?
Over complicating things perhaps?

 

Watch my avatar for a few seconds. (actually there's a fault in it - it omits to include <util/delay.h> so you would need that).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note that you are running at 1 MHz since the CKDIV8 fuse is set.

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


I would need to include the delay library even though that is a function that works in Arduino?

I used the "Create a project from an Arduino sketch" option and figured it would include all the necessary include files to run properly.

 

I unchecked CKDIV8 fuse and when it runs at 8 MHz instead of 1 MHz, the time it runs is 2s on and 2s off.

Could this be because Arduino's run at 16MHz using a crystal, so the delay function is configured to work at 16MHz?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

If all you are doing is importing Arduino sketches what exactly is the point of switching to AS7 at all?

 

(and the delay I was suggesting is already in libc, in fact it uses a builtin)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

caddywhompus wrote:
If learning C is my best option, can you point me to resources to help shorten the learning curve?
C is primary for now though C++ will get there; your preferred C book (edit: preferably with exercises) and C toolchain.

Personal experience :

  • the textbook that the instructor selected for a CEU C course
  • Barr's Programming Embedded Systems in C and C++ (had x86 knowledge that I needed to bootstrap an embedded Intel 486; yea, dated though it's excellent)

For a start, consider the non-compiler (an interpreter); you might like it and continue with it for making code snippets and scripts.

 


CEU - Continuing Education Unit

Reviews of over 60 Embedded Systems Books (The Ganssle Group)

...

C For Everyone, Richard Man and CJ Willrich - an excellent intro to embedded C, the language and its use.

...

Programming Embedded Systems in C and C++, Michael Barr - A very good intro book, with a focus on the 186 processor.

...

Understanding and UsingC Pointers, Richard Reese - A surprisingly worthwhile new book on using C pointers

...

Books on Embedded Software (Barr Group)

Ch -- an embeddable C/C++ interpreter, C and C++ scripting language

Cling Documentation | GOREPL

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Wed. Sep 18, 2019 - 07:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Some 'C' learning & reference stuff:

 

http://blog.antronics.co.uk/2011...

 

Arduino is really just C++

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

 This one is a good one to get started on

I dont normally log on but couldnt resist good luck

 

 B

 

https://www.newbiehack.com/MicrocontrollerIntroductionABeginnersGuidetotheAtmelAVRAtmega32.aspx

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All,

 

Thanks for the resources!

Consider my issue solved.

I'm going to do some reading and rewrite my code, eliminating the Arduino IDE step.

 

Caddy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

caddywhompus wrote:
No Arduinos use a tiny85 to my knowledge,

The Arduino Gemma is a tiny85 you can select from the boards menu!

Other Tiny's are available with the Tiny's Universal board package, so not limited to T25/45/85.

 

Unless you need debugwire debug capability, AS7 is not needed if using sketches.

 

Jim

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

caddywhompus wrote:
Consider my issue solved.

 

See Tip #5 for how to mark your question as resolved.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...