Author Topic: Programming AVR MCUs without libraries like the Arduino library?  (Read 6869 times)

0 Members and 1 Guest are viewing this topic.

Offline KoldTopic starter

  • Newbie
  • Posts: 7
  • Country: ca
Hi everyone; first post here!  :D

I've been doing a fair bit of embedded design projects using the Arduino, and I would finally like to break free of the hand-holding libraries that Arduino provides. However, this also means the amount of online help resources is now vastly reduced.

I would like to be able to program AVR microcontrollers with regular old C from Atmel Studio (or even just compiling the code and programming the device manually). I've already taken the basic steps to do this: I have implemented an ADC and simple I/O to create a 7-segment display, but my next project is much more complex. I will need to be doing ADC, external interrupts, and using I2C+SPI. I imagine, also, that my project after that will be another order of magnitude more complex.

I suppose, then, that I have three questions:
  • Does anybody know of an online resource to help one learn to maneuver the AVR microcontrollers?
  • When you folks began learning your first microcontroller in all its guts and glory, did you have the aid of helpful resources?
  • If the only answer is to just throw yourself in and start reading the 400-page data sheet, do you have any tips before I throw myself in?

Thanks!

Edit: I realize I should have, perhaps, posted this in the Microcontroller sub-forum... please move it there if you think it more appropriate. :)
« Last Edit: January 26, 2015, 06:56:58 pm by Kold »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #1 on: January 26, 2015, 07:20:24 pm »
Quote
If the only answer is to just throw yourself in and start reading the 400-page data sheet, do you have any tips before I throw myself in?

Sadly, there is no other way around it.
================================
https://dannyelectronics.wordpress.com/
 

Offline nuno

  • Frequent Contributor
  • **
  • Posts: 606
  • Country: pt
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #2 on: January 26, 2015, 07:22:24 pm »
Well, it does go through picking up the datasheet and reading it :). However, it doesn't mean you have to read everything and in detail. You'll need to have a "general overview" about what it has and does so, in a first reading, you can fast-read through the details, and from there on you just need to use it as a reference. When you need to use the ADC, then go back to the ADC chapter and read it carefully, and so on. Some microcontrollers' datasheets are better written to be used like this, having a very good overview in the 1st chapter(s); in AVRs the datasheets spread the general part a bit throughout the chapters on the specific modules, but usable anyways.

Winever's (GCC for AVR) libc documentation will show you what functions are there that you can use. If you have the Arduino IDE, you already have Winever there and this documentation is included.

There's an AVR centric forum, avrfreaks.net (there are very good EE people over there, too). It also has a collection of AVR specific projects that you can use in several ways.
 

Offline Maxlor

  • Frequent Contributor
  • **
  • Posts: 565
  • Country: ch
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #3 on: January 26, 2015, 07:34:10 pm »
However, this also means the amount of online help resources is now vastly reduced.
It's not, actually. You will soon find that the documentation that Atmel provides is much more thorough and reliable than whatever documentation you find on Arduinos. And it's not just the data sheet: if you look at the documentation page for the ATmega32u4 for example, you'll find dozens of application notes that describe all kinds of use cases.

It is true that this documentation is a bit harder to understand than your average Arduino tutorial. I think the initial effort is well worth it though, since pretty much everything you'll ever need to know about the chip is there, and you can be quite sure that the information given is accurate too.
 

Offline KoldTopic starter

  • Newbie
  • Posts: 7
  • Country: ca
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #4 on: January 26, 2015, 09:05:58 pm »
Thanks for the advice, guys! Your words are encouraging...

Time to... *gulp* start reading...
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17816
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #5 on: January 26, 2015, 09:21:01 pm »
You will find it quite a jump but worth it. I did as you and just went through one periphery at a time although I have not done many. Still setting up and reading the ADC is quite a thing when you do it yourself compared to the Arduino. The chips generally are set up ready to go so you only need to enable and work with the registers of the peripheries you want to use. I'm not sure what the Atmel studio has to offer there is the Atmel software framework they keep banging on about I don't know if that has any support for lower end chips. It certainly seems to add a little bit of the Arduino touch to arm processors from the little I have seen in tutorials. Unfortunately at most video tutorials are abysmal and are mostly marketing wank.
 

Offline Puffie40

  • Regular Contributor
  • *
  • Posts: 54
  • Country: ca
  • Irregular Logic
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #6 on: January 26, 2015, 09:30:08 pm »
You will find the data sheet will give you all you need to know, and then some (like the behavior of the pins and power characteristics). With the proper compilers and some practice, you could even code the uP in assembly.

Learning to refer to the data sheet will also allow you to jump to other processors like the  PIC.
 

Offline hneve

  • Regular Contributor
  • *
  • Posts: 61
  • Country: no
    • http://www.neve.nu/
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #7 on: January 26, 2015, 09:35:55 pm »
I also made the jump from arduino ide to atmel studio. I wrote a few entry level guides too, only I wrote them in my native language (Norsk)

You will find things hard and maybe confusing at first but that's how it is when doing something new.

Sent fra min D6503 via Tapatalk

73 de LB4NH
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #8 on: January 26, 2015, 09:40:46 pm »
Not sure if you are mind-set on Atmel Studio - I tried AVR Studio when it first came out and thought that was extremely bloated.

Otherwise, you can do the development in IAR AVR, CB AVR, or even emBlocks - the last two are based on Code::Blocks, a superb IDE in my view.
================================
https://dannyelectronics.wordpress.com/
 

Offline G0HZU

  • Super Contributor
  • ***
  • Posts: 3015
  • Country: gb
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #9 on: January 26, 2015, 10:09:02 pm »
Quote
•If the only answer is to just throw yourself in and start reading the 400-page data sheet, do you have any tips before I throw myself in?

I've only used a few AVR parts but in all of my cases there is a chapter in the datasheet that prints a warning about the code examples given in the datasheet

This is partly to do with an issue with devices that have an extended I/O map. Also, there's some stuff about c headers. It's worth reading this chapter first and try to understand why they include this chapter because otherwise you may find you will get frustrated with the code samples in the datasheet.


« Last Edit: January 26, 2015, 10:11:40 pm by G0HZU »
 

Offline Wilksey

  • Super Contributor
  • ***
  • Posts: 1329
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #10 on: January 26, 2015, 10:24:37 pm »
A quick Google search results but to name a few:
http://www.avrbeginners.net/
https://www.newbiehack.com/MicrocontrollerIntroductionABeginnersGuidetotheAtmelAVRAtmega32.aspx
http://www.instructables.com/id/Help%3A-An-Absolute-Beginner-s-Guide-to-8-Bit-AVR-Pr/
http://www.ladyada.net/learn/avr/

I would check the main hobby guru sites such as Sparkfun, Adafruit, even YouTube, after all, most of us are probably here because of YouTube.

AVRFreaks used to be a good resource, not sure what they have now, people do tend to focus more on Arduino than actual AVR these days.

First decide if you want to focus on AVR C or AVR Assembler, then just do a quick Google search for "AVR for Beginners" for example.
 

Offline KoldTopic starter

  • Newbie
  • Posts: 7
  • Country: ca
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #11 on: January 26, 2015, 10:37:03 pm »
Once again, thanks for the advice, everyone! I just read through the SPI section of the datasheet and it wasn't bad at all! I internalize wireless com (ZigBee) protocols at work that are much worse than that was...

Not sure if you are mind-set on Atmel Studio - I tried AVR Studio when it first came out and thought that was extremely bloated.

Otherwise, you can do the development in IAR AVR, CB AVR, or even emBlocks - the last two are based on Code::Blocks, a superb IDE in my view.

Your Code::Blocks-inspired IDEs intrigue me... because I use Code::Blocks to do all my C++ programming. But I do, already, have AVR Studio all set up and have been using it... food for thought!

A quick Google search results but to name a few:
http://www.avrbeginners.net/
https://www.newbiehack.com/MicrocontrollerIntroductionABeginnersGuidetotheAtmelAVRAtmega32.aspx
http://www.instructables.com/id/Help%3A-An-Absolute-Beginner-s-Guide-to-8-Bit-AVR-Pr/
http://www.ladyada.net/learn/avr/

I would check the main hobby guru sites such as Sparkfun, Adafruit, even YouTube, after all, most of us are probably here because of YouTube.

AVRFreaks used to be a good resource, not sure what they have now, people do tend to focus more on Arduino than actual AVR these days.

First decide if you want to focus on AVR C or AVR Assembler, then just do a quick Google search for "AVR for Beginners" for example.

Thanks! I had already done a preliminary Google search (in fact this is how I was able to get the ADC working in the first place for the most part), but couldn't find anything that really had more than basic fluff. I'll take a look over the places you recommended later when I get off work.
 

Offline nuno

  • Frequent Contributor
  • **
  • Posts: 606
  • Country: pt
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #12 on: January 26, 2015, 10:50:02 pm »
The ADC is actually a pretty simple peripheral, that you can put to work with half a dozen or less register writes. Even when using the interrupts, dead simple.
 

Online amyk

  • Super Contributor
  • ***
  • Posts: 8275
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #13 on: January 26, 2015, 11:41:38 pm »
Datasheets are not usually meant to be read like a novel - read about the CPU first, then find the peripheral(s) you're interested in and read those sections. However, you should at the least read about the GPIO pins since they are shared between peripherals. Don't forget about the errata too!

... and you actually don't need anything other than some wires and pushbuttons to program an AVR: http://youtu.be/UJHeDvr_doM
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9951
  • Country: nz
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #14 on: January 27, 2015, 12:00:23 am »
Most of the avr datasheets contain c code examples for many things

Also make sure you checkout the atmel app notes. They are basically a step by step example of doing lots of more advanced stuff. They don't always give you code but always provide a flowchart of the steps you need.

Oh and avr external interrupts are easy.
Enable the int you want by setting its enable bit
Set if you want rise fall or both
Make sure you have global interrupts enabled
Add the isr signal function with the name of the int
Done, it should now work
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #15 on: January 27, 2015, 12:26:17 am »
Does anybody know of an online resource to help one learn to maneuver the AVR microcontrollers?
throw myself in?

Datasheet is most useful. For AVR you can find also books and youtbue tutorials.

When you folks began learning your first microcontroller in all its guts and glory, did you have the aid of helpful resources?

No much help, I had to build hardware the populate the memory and could figure out if the load operation is to load a register from memory or vice versa. It takes some time and patient.

If the only answer is to just throw yourself in and start reading the 400-page data sheet, do you have any tips before I throw myself in?

You don't need to read the entire datasheet, just focus on the peripheral you are interested in. They are pretty much independent.

BTW, you can do low level register access in the Arduino IDE, you don't have to use the Arduino libraries. It's a choice, not a requirement.  BTW, Atmel Studio is a monster but this is a different story.
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21686
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #16 on: January 27, 2015, 12:38:23 am »
As a masochist (and purist, and only infrequent programmer in software so it doesn't matter, :P ), I do it in assembler, which works just fine.  You can set up an AVR Studio assembly project, or do it in C (GCC accepts assembler files, formatted accordingly; giving you the power of the C preprocessor for macros, which is handy).  If you get fed up, scratching away like that, you can go to plain old C for as much as you like, and use whatever standard libraries you please.  Which is basically what Arduino does (everything is a library function), just formatted a little cleaner.

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #17 on: January 27, 2015, 12:50:26 am »
If you get fed up, scratching away like that, you can go to plain old C for as much as you like, ...

.. or C++ which is what Arduino uses (e.g. serial.println(...)).
 

Offline alank2

  • Super Contributor
  • ***
  • Posts: 2185
Re: Programming AVR MCUs without libraries like the Arduino library?
« Reply #18 on: January 27, 2015, 03:59:03 am »
  • Does anybody know of an online resource to help one learn to maneuver the AVR microcontrollers?

I've learned everything over at avrfreaks.net.  I didn't know how to flash an LED and started there.  Read, Try, Learn, Repeat.  Studying the datasheet is critical.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf